Skip to content

Commit

Permalink
Changes to use web ui key in all the Infra Proxy APIs for Cookbooks, …
Browse files Browse the repository at this point in the history
…Policy Files, Policy Groups, Clients (#6457)

* Changes added to use the web ui key

Signed-off-by: sonali wale <swale@msystechnologies.com>

* added minor UI change

Signed-off-by: Chaitali Mane <cmane@progress.com>

Co-authored-by: Chaitali Mane <cmane@progress.com>
  • Loading branch information
2 people authored and vinay033 committed Apr 22, 2022
1 parent 632e1ac commit e807380
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ <h2 slot="title">Add Chef Infra Server </h2>
(keyup)="handleInput($event)"
autofocus></textarea>
</label>
<chef-error
<chef-error class="textarea-error"
*ngIf="(webUIKeyForm.get('webui_key').hasError('required') || webUIKeyForm.get('webui_key').hasError('pattern')) && webUIKeyForm.get('webui_key').dirty">
WEB UI KEY is required.
</chef-error>
<span class="note_text">Note: A web UI Key is located <a href=''>Here</a>(Need Better Help Text).</span>
</chef-form-field>
<span class="note_text">Note: A web UI Key is located <a href=''>Here</a>(Need Better Help Text).</span>
</div>
<div id="button-bar">
<chef-button id="cancel-server-popup" tertiary [disabled]="creating" (click)="closeSeverSlider()">Cancel</chef-button>
Expand Down
28 changes: 21 additions & 7 deletions components/infra-proxy-service/server/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
Expand All @@ -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
Expand Down

0 comments on commit e807380

Please sign in to comment.