-
Notifications
You must be signed in to change notification settings - Fork 24
Lift service discovery client out of CyberArkClient #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -49,24 +49,23 @@ func LoadClientConfigFromEnvironment() (ClientConfig, error) { | |||||
| // NewDatauploadClient initializes and returns a new CyberArk Data Upload client. | ||||||
| // It performs service discovery to find the necessary API endpoints and authenticates | ||||||
| // using the provided client configuration. | ||||||
| func NewDatauploadClient(ctx context.Context, httpClient *http.Client, cfg ClientConfig) (*dataupload.CyberArkClient, error) { | ||||||
| discoveryClient := servicediscovery.New(httpClient) | ||||||
| serviceMap, err := discoveryClient.DiscoverServices(ctx, cfg.Subdomain) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| func NewDatauploadClient(ctx context.Context, httpClient *http.Client, serviceMap *servicediscovery.Services, cfg ClientConfig) (*dataupload.CyberArkClient, error) { | ||||||
| identityAPI := serviceMap.Identity.API | ||||||
| if identityAPI == "" { | ||||||
| return nil, errors.New("service discovery returned an empty identity API") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: This error still talks about "service discovery returned..."
Suggested change
|
||||||
| } | ||||||
| identityClient := identity.New(httpClient, identityAPI, cfg.Subdomain) | ||||||
| err = identityClient.LoginUsernamePassword(ctx, cfg.Username, []byte(cfg.Secret)) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| discoveryAPI := serviceMap.DiscoveryContext.API | ||||||
| if discoveryAPI == "" { | ||||||
| return nil, errors.New("service discovery returned an empty discovery API") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: This error still talks about "service discovery returned..."
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| identityClient := identity.New(httpClient, identityAPI, cfg.Subdomain) | ||||||
|
|
||||||
| err := identityClient.LoginUsernamePassword(ctx, cfg.Username, []byte(cfg.Secret)) | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
Comment on lines
+63
to
+68
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Moving the login down isn't strictly required in this PR, but I did it so that we check both the identity and discovery API availability first, before we try the login. This means if we didn't get a disco API endpoint from service discovery, we won't do a pointless login attempt. |
||||||
|
|
||||||
| return dataupload.New(httpClient, discoveryAPI, identityClient.AuthenticateRequest), nil | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe check for
nilserviceMap here, and return an error, to avoid a panic, or make the argument a value rather than a pointer.