From 2e82005d62e392aa30e5d3c706b5e8da270ab4dc Mon Sep 17 00:00:00 2001 From: Sonali Wale <86949270+sonali523@users.noreply.github.com> Date: Wed, 29 Dec 2021 16:42:04 +0530 Subject: [PATCH] Changes to use web ui key in all the Infra Proxy APIs for Cookbooks, Policy Files, Policy Groups, Clients (#6457) * Changes added to use the web ui key Signed-off-by: sonali wale * added minor UI change Signed-off-by: Chaitali Mane Co-authored-by: Chaitali Mane --- .../create-chef-server-slider.component.html | 4 +-- .../infra-proxy-service/server/proxy.go | 28 ++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/components/automate-ui/src/app/modules/infra-proxy/create-chef-server-slider/create-chef-server-slider.component.html b/components/automate-ui/src/app/modules/infra-proxy/create-chef-server-slider/create-chef-server-slider.component.html index a91559b5bbd..85853a9f507 100644 --- a/components/automate-ui/src/app/modules/infra-proxy/create-chef-server-slider/create-chef-server-slider.component.html +++ b/components/automate-ui/src/app/modules/infra-proxy/create-chef-server-slider/create-chef-server-slider.component.html @@ -151,12 +151,12 @@

Add Chef Infra Server

(keyup)="handleInput($event)" autofocus> - WEB UI KEY is required. - Note: A web UI Key is located Here(Need Better Help Text). + Note: A web UI Key is located Here(Need Better Help Text).
Cancel diff --git a/components/infra-proxy-service/server/proxy.go b/components/infra-proxy-service/server/proxy.go index b52008b4453..1b504ad9ec5 100644 --- a/components/infra-proxy-service/server/proxy.go +++ b/components/infra-proxy-service/server/proxy.go @@ -101,6 +101,8 @@ func (s *Server) createClient(ctx context.Context, orgID string, serverID string defer cancel() // TODO: combine get server & org query in one statement. + var credentialID, adminUser string + var isWebuiKey bool server, err := s.service.Storage.GetServer(ctx, serverID) if err != nil { return nil, service.ParseStorageError(err, serverID, "server") @@ -110,8 +112,14 @@ func (s *Server) createClient(ctx context.Context, orgID string, serverID string if err != nil { return nil, service.ParseStorageError(err, orgID, "org") } - - secret, err := s.service.Secrets.Read(ctx, &secrets.Id{Id: org.CredentialID}) + // If web ui key is available with server then use it otherwise use org admin key + if server.CredentialID != "" { + credentialID = server.CredentialID + isWebuiKey = true + } else { + credentialID = org.CredentialID + } + secret, err := s.service.Secrets.Read(ctx, &secrets.Id{Id: credentialID}) if err != nil { return nil, err } @@ -120,12 +128,18 @@ func (s *Server) createClient(ctx context.Context, orgID string, serverID string if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid server url: %s", baseURL) } - + // If using web ui key then set admin user as pivotal otherwise use org admin user + if isWebuiKey { + adminUser = "pivotal" + } else { + adminUser = org.AdminUser + } client, err := NewChefClient(&ChefConfig{ - Name: org.AdminUser, - Key: GetAdminKeyFrom(secret), - SkipSSL: true, - BaseURL: baseURL, + Name: adminUser, + Key: GetAdminKeyFrom(secret), + SkipSSL: true, + BaseURL: baseURL, + IsWebuiKey: isWebuiKey, }) return client, err