Skip to content

Commit

Permalink
[infra-proxy-service] minor update regarding server delete message
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Singh <[email protected]>
  • Loading branch information
Vivek Singh committed Dec 19, 2019
1 parent e8f52a8 commit 6dfe59d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions components/infra-proxy-service/server/v1/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ func (s *Server) createClient(ctx context.Context, orgID string) (*chef.Client,
return nil, status.Errorf(codes.InvalidArgument, "invalid org id: %s", err.Error())
}

// TODO: Call GetOrgByName in order to avoid seperate query to fetch infra server detail
// TODO: Call GetOrgByName in order to avoid separate query to fetch infra server detail
// Prefer LEFT OUTER join to in order to append server detail in response

org, err := s.service.Storage.GetOrg(ctx, UUID)
if err != nil {
return nil, service.ParseStorageError(err, orgID, "org")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS orgs (
name TEXT NOT NULL DEFAULT '',
admin_user TEXT NOT NULL DEFAULT '', /* Added for now but can be thing of managing mutitple keys & users */
admin_key TEXT NOT NULL DEFAULT '',
server_id uuid NOT NULL references servers(id) ON DELETE CASCADE,
server_id uuid NOT NULL references servers(id) ON DELETE RESTRICT,
created_at TIMESTAMPTZ NOT NULL,
updated_at TIMESTAMPTZ NOT NULL,
UNIQUE(name, server_id)
Expand Down
5 changes: 2 additions & 3 deletions components/infra-proxy-service/storage/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ func parsePQError(e *pq.Error) error {
case "unique_violation":
return storage.ErrConflict
case "foreign_key_violation":
// in this piece of code, a foreign key violation means the team the user
// should be added to doesn't exist; a "not found" seems like an OK
// in this piece of code, a foreign key violation means the server the org
// approximation for now
return storage.ErrNotFound
return storage.ErrCannotDelete
}

return e
Expand Down
4 changes: 4 additions & 0 deletions components/infra-proxy-service/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ var (
// ErrNotFound is returned when a requested server wasn't found
ErrNotFound = errors.New("not found")

// ErrCannotDelete is returned when a request attempts to delete a server that
// is not allowed to be deleted if orgs present
ErrCannotDelete = errors.New("cannot delete")

// ErrConflict is returned when a server there is a clash of server IDs
ErrConflict = errors.New("conflict")
)

0 comments on commit 6dfe59d

Please sign in to comment.