From 42fb7b4325e589e58976147d99cc7f950519b944 Mon Sep 17 00:00:00 2001 From: Enis Soztutar Date: Mon, 21 Aug 2023 12:13:37 -0700 Subject: [PATCH] CDPCP-10283 Go SDK against the private cloud needs to set the API base path (#52) We already have the API base path configurable, I just added builder-style methods. Testing done: - new unit test --- cdp-sdk-go/cdp/config.go | 9 +++++++++ cdp-sdk-go/cdp/config_test.go | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/cdp-sdk-go/cdp/config.go b/cdp-sdk-go/cdp/config.go index 5d8e0352..956a9924 100644 --- a/cdp-sdk-go/cdp/config.go +++ b/cdp-sdk-go/cdp/config.go @@ -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. @@ -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. diff --git a/cdp-sdk-go/cdp/config_test.go b/cdp-sdk-go/cdp/config_test.go index aeab6cf1..24ef672f 100644 --- a/cdp-sdk-go/cdp/config_test.go +++ b/cdp-sdk-go/cdp/config_test.go @@ -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()) +}