(requester Requester)
| 359 | } |
| 360 | |
| 361 | func (c *Client) GetSystemClient(requester Requester) (*octopusApiClient.Client, error) { |
| 362 | // Internal quirks of the go-octopusdeploy API SDK: |
| 363 | // A space-scoped client can do System level things perfectly well, but the inverse is not true. |
| 364 | // Essentially: |
| 365 | // - we can always create a "system" client which has a Space ID of empty string |
| 366 | // - we can only create a "space scoped" client if we have a valid space ID, which requires using the |
| 367 | // system client to look up a space ID and test it first. |
| 368 | // - once we have a "space scoped" client we can use it for all the system things and avoid storing |
| 369 | // two client copies in memory, so we can throw out the system client. |
| 370 | if c.SpaceScopedClient != nil { |
| 371 | return c.SpaceScopedClient, nil |
| 372 | } |
| 373 | |
| 374 | if c.SystemClient != nil { |
| 375 | return c.SystemClient, nil |
| 376 | } |
| 377 | |
| 378 | systemClient, err := octopusApiClient.NewClientWithCredentials(c.HttpClient, c.ApiUrl, c.Credentials, "", requester.GetRequester()) // deliberate empty string for space here |
| 379 | if err != nil { |
| 380 | return nil, err |
| 381 | } |
| 382 | // stash for future use |
| 383 | c.SystemClient = systemClient |
| 384 | return systemClient, nil |
| 385 | } |
| 386 | |
| 387 | // NewStubClientFactory returns a stub instance, so you can satisfy external code that needs a ClientFactory |
| 388 | func NewStubClientFactory() ClientFactory { |
no test coverage detected