Skip to content

Commit

Permalink
CDPCP-10283 Go SDK against the private cloud needs to set the API bas…
Browse files Browse the repository at this point in the history
…e path (#52)

We already have the API base path configurable, I just added builder-style methods.

Testing done:
  - new unit test
  • Loading branch information
enis authored and gregito committed Sep 12, 2023
1 parent c6bf09a commit 42fb7b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cdp-sdk-go/cdp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ func (config *Config) WithClientApplicationName(clientApplicationName string) *C
return config
}

func (config *Config) WithBaseApiPath(baseApiPath string) *Config {
config.BaseApiPath = baseApiPath
return config
}

func (config *Config) WithVersion(version string) *Config {
// TODO: this function should not be exposed to SDK end-users. When the golang SDK is taken out of
// the terraform provider to be its own project, set this from the goreleaser config and do not let users override it.
Expand Down Expand Up @@ -314,6 +319,10 @@ func (config *Config) GetUserAgentOrDefault() string {
return config.UserAgent
}

func (config *Config) GetBaseApiPath() string {
return config.BaseApiPath
}

// getDefaultUserAgent returns a string to be set for the User-Agent header in HTTP requests. We follow the same format
// with the python based CDP CLI and Java based CDP SDK. However, there is no easy way to detect the OS version without
// running uname, so we don't do that. Can be added later if needed.
Expand Down
6 changes: 6 additions & 0 deletions cdp-sdk-go/cdp/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,9 @@ func TestGetEndpointsWithRegionUsg1(t *testing.T) {
common.AssertEquals(t, "https://api.usg-1.cdp.clouderagovt.com/", altusEndpoint)
common.AssertEquals(t, "https://api.usg-1.cdp.clouderagovt.com/", iamEndpoint)
}

func TestConfig_WithBaseApiPath(t *testing.T) {
var config Config
config.WithBaseApiPath("/foo")
common.AssertEquals(t, "/foo", config.GetBaseApiPath())
}

0 comments on commit 42fb7b4

Please sign in to comment.