From 6dfe59d904e05449585eda0cda08ccc7e6fe05a9 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Thu, 19 Dec 2019 14:29:32 +0530 Subject: [PATCH] [infra-proxy-service] minor update regarding server delete message Signed-off-by: Vivek Singh --- components/infra-proxy-service/server/v1/proxy.go | 3 +-- .../storage/postgres/migration/sql/00_add_infra_proxy.up.sql | 2 +- components/infra-proxy-service/storage/postgres/postgres.go | 5 ++--- components/infra-proxy-service/storage/storage.go | 4 ++++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/infra-proxy-service/server/v1/proxy.go b/components/infra-proxy-service/server/v1/proxy.go index 1055730a00ad..9e7f0c676514 100644 --- a/components/infra-proxy-service/server/v1/proxy.go +++ b/components/infra-proxy-service/server/v1/proxy.go @@ -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") diff --git a/components/infra-proxy-service/storage/postgres/migration/sql/00_add_infra_proxy.up.sql b/components/infra-proxy-service/storage/postgres/migration/sql/00_add_infra_proxy.up.sql index 9cf77cd5cad9..04809dfd46da 100644 --- a/components/infra-proxy-service/storage/postgres/migration/sql/00_add_infra_proxy.up.sql +++ b/components/infra-proxy-service/storage/postgres/migration/sql/00_add_infra_proxy.up.sql @@ -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) diff --git a/components/infra-proxy-service/storage/postgres/postgres.go b/components/infra-proxy-service/storage/postgres/postgres.go index 2ed9ce2ad95a..827ef8689676 100644 --- a/components/infra-proxy-service/storage/postgres/postgres.go +++ b/components/infra-proxy-service/storage/postgres/postgres.go @@ -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 diff --git a/components/infra-proxy-service/storage/storage.go b/components/infra-proxy-service/storage/storage.go index 76c8eaf3de34..011e1448b483 100644 --- a/components/infra-proxy-service/storage/storage.go +++ b/components/infra-proxy-service/storage/storage.go @@ -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") )