Skip to content

Commit

Permalink
fix robot account issue
Browse files Browse the repository at this point in the history
Signed-off-by: bupd <[email protected]>
  • Loading branch information
bupd committed Nov 5, 2024
1 parent 13781f4 commit db8fcf1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ground-control/internal/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ func (s *Server) registerSatelliteHandler(w http.ResponseWriter, r *http.Request
return
}

roboPresent,err := harbor.IsRobotPresent(r.Context(), req.Name)
if err != nil {
log.Println(err)
err := &AppError{
Message: fmt.Sprintf("Error querying for robot account: %v", err.Error()),
Code: http.StatusBadRequest,
}
HandleAppError(w, err)
return
}

if roboPresent {
err := &AppError{
Message: fmt.Sprintf("Error: Robot Account name already present. Try with different name"),
Code: http.StatusBadRequest,
}
HandleAppError(w, err)
return
}

// Start a new transaction
tx, err := s.db.BeginTx(r.Context(), nil)
if err != nil {
Expand Down
21 changes: 21 additions & 0 deletions ground-control/reg/harbor/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ func GetRobotDetails(r *robot.CreateRobotCreated) (int64, string, string) {
return id, name, secret
}

func IsRobotPresent(ctx context.Context, name string) (bool, error) {
client := GetClient()

name = fmt.Sprintf("name=%s", name)
response, err := client.Robot.ListRobot(
ctx,
&robot.ListRobotParams{
Q: &name,
},
)
if err != nil {
return false, fmt.Errorf("error: listing robot account: %v", err)
}

if len(response.Payload) > 0 {
return true, nil
}

return false, nil
}

func ListRobots(ctx context.Context, opts ListParams) (*robot.ListRobotOK, error) {
client := GetClient()
response, err := client.Robot.ListRobot(
Expand Down

0 comments on commit db8fcf1

Please sign in to comment.