diff --git a/go.mod b/go.mod index 6c9cfc543..7ff0df8f8 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,7 @@ require ( require ( github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4 github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.1 - github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2 v2.0.1 + github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2 v2.0.2 github.com/ionos-cloud/sdk-go-bundle/shared v0.1.1 github.com/ionos-cloud/sdk-go-dbaas-mariadb v1.1.1 github.com/ionos-cloud/sdk-go-kafka v1.1.0 diff --git a/go.sum b/go.sum index f496c1fbf..ccb220775 100644 --- a/go.sum +++ b/go.sum @@ -248,8 +248,8 @@ github.com/ionos-cloud/sdk-go-auth v1.0.6 h1:N7XQ8JLKM9OS1DDlDCIN3Nk4RV4MuNvHFd5 github.com/ionos-cloud/sdk-go-auth v1.0.6/go.mod h1:4MuUIZbnQjgNalEB9LUzIuBTI1keqgA7EpJsjEvMAls= github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.1 h1:8O0c5GLVD6aM//iC3L3+0PaQgKux3tV/MqzOpLV4wEM= github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.1/go.mod h1:BF6R+j1GdJEMImxkeh32qjIVWqsBfgi6VgyfsY5ezIA= -github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2 v2.0.1 h1:0WyMttptHNo2X/2hCtNORZXGnrxEWFcWMUtBQy+xEF0= -github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2 v2.0.1/go.mod h1:+xkTjDjjpNXneY8ZfFtpexTEXKbxoz4Y2tIBqFSvll0= +github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2 v2.0.2 h1:42llVAj7pKbmGVT3Aj6v+77CVEqESK1WL1vI+wOH7Co= +github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2 v2.0.2/go.mod h1:mUnvrQawA+ydTK1vzguZKlSVtKLPcWeDjYGdU96KKG4= github.com/ionos-cloud/sdk-go-bundle/shared v0.1.1 h1:NWobgIhmUJKG6ohFXefMj+KmpEEvLYEDUgGzpns6HQE= github.com/ionos-cloud/sdk-go-bundle/shared v0.1.1/go.mod h1:cLIl4zmB1yMdPSNgTzaRmXeuusEAY1O3Lp/iXSc/R6E= github.com/ionos-cloud/sdk-go-cert-manager v1.0.1 h1:QGnenRREavvU0ZrXvY4hmCMXRyvmKj5jaXsFX9Apfd0= diff --git a/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/README.md b/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/README.md index 1afb7aac5..4f9c38f0b 100644 --- a/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/README.md +++ b/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/README.md @@ -42,7 +42,7 @@ go get github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo@latest | `IONOS_LOG_LEVEL` | Specify the Log Level used to log messages. Possible values: Off, Debug, Trace | | `IONOS_PINNED_CERT` | Specify the SHA-256 public fingerprint here, enables certificate pinning | -⚠️ **_Note: To overwrite the api endpoint - `api.ionos.com`, the environment variable `$IONOS_API_URL` can be set, and used with `NewConfigurationFromEnv()` function._** +⚠️ **_Note: To overwrite the api endpoint - `api.ionos.com`, the environment variable `IONOS_API_URL` can be set, and used with `NewConfigurationFromEnv()` function._** ## Examples @@ -50,6 +50,14 @@ Examples for creating resources using the Go SDK can be found [here](examples/) ## Authentication +All available server URLs are: + +- *https://api.ionos.com/databases/mongodb* - Production + +By default, *https://api.ionos.com/databases/mongodb* is used, however this can be overriden at authentication, either +by setting the `IONOS_API_URL` environment variable or by specifying the `hostUrl` parameter when +initializing the sdk client. + ### Basic Authentication - **Type**: HTTP basic authentication @@ -66,7 +74,7 @@ import ( ) func basicAuthExample() error { - cfg := shared.NewConfiguration("username_here", "pwd_here", "", "") + cfg := shared.NewConfiguration("username_here", "pwd_here", "", "hostUrl_here") cfg.LogLevel = Trace apiClient := mongo.NewAPIClient(cfg) return nil @@ -96,7 +104,7 @@ There are 2 ways to generate your token: if !jwt.HasToken() { return fmt.Errorf("could not generate token") } - cfg := shared.NewConfiguration("", "", *jwt.GetToken(), "") + cfg := shared.NewConfiguration("", "", *jwt.GetToken(), "hostUrl_here") cfg.LogLevel = Trace apiClient := mongo.NewAPIClient(cfg) return nil @@ -273,4 +281,4 @@ All URIs are relative to *https://api.ionos.com/databases/mongodb* [[Back to API list]](#documentation-for-api-endpoints) [[Back to Model list]](#documentation-for-models) - \ No newline at end of file + diff --git a/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/client.go b/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/client.go index 316b49d62..47864ee44 100644 --- a/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/client.go +++ b/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/client.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "io" + "log" "mime/multipart" "net" "net/http" @@ -52,7 +53,7 @@ const ( RequestStatusFailed = "FAILED" RequestStatusDone = "DONE" - Version = "products/dbaas/mongo/v2.0.1" + Version = "products/dbaas/mongo/v2.0.2" ) // APIClient manages communication with the IONOS DBaaS MongoDB REST API API v1.0.0 @@ -82,31 +83,63 @@ type service struct { client *APIClient } +func DeepCopy(cfg *shared.Configuration) (*shared.Configuration, error) { + if cfg == nil { + return nil, nil + } + + data, err := json.Marshal(cfg) + if err != nil { + return nil, fmt.Errorf("failed to serialize configuration: %w", err) + } + + clone := &shared.Configuration{} + err = json.Unmarshal(data, clone) + if err != nil { + return nil, fmt.Errorf("failed to deserialize configuration: %w", err) + } + + return clone, nil +} + // NewAPIClient creates a new API client. Requires a userAgent string describing your application. // optionally a custom http.Client to allow for advanced features such as caching. func NewAPIClient(cfg *shared.Configuration) *APIClient { - if cfg.HTTPClient == nil { - cfg.HTTPClient = http.DefaultClient + // Attempt to deep copy the input configuration + cfgCopy, err := DeepCopy(cfg) + if err != nil { + log.Printf("Error creating deep copy of configuration: %v", err) + + // shallow copy instead as a fallback + cfgCopy := &shared.Configuration{} + *cfgCopy = *cfg } - if len(cfg.Servers) == 0 { - cfg.Servers = shared.ServerConfigurations{ + // Initialize default values in the copied configuration + if cfgCopy.HTTPClient == nil { + cfgCopy.HTTPClient = http.DefaultClient + } + + if len(cfgCopy.Servers) == 0 { + cfgCopy.Servers = shared.ServerConfigurations{ { URL: "https://api.ionos.com/databases/mongodb", Description: "Production", }, } } - //enable certificate pinning if the env variable is set + + // Enable certificate pinning if the environment variable is set pkFingerprint := os.Getenv(shared.IonosPinnedCertEnvVar) if pkFingerprint != "" { httpTransport := &http.Transport{} AddPinnedCert(httpTransport, pkFingerprint) - cfg.HTTPClient.Transport = httpTransport + cfgCopy.HTTPClient.Transport = httpTransport } + // Create and initialize the API client c := &APIClient{} - c.cfg = cfg + c.cfg = cfgCopy c.common.client = c // API Services diff --git a/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/utils.go b/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/utils.go index 8e66e3407..3fd415f93 100644 --- a/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/utils.go +++ b/vendor/github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2/utils.go @@ -22,6 +22,10 @@ type IonosTime struct { time.Time } +type NullableIonosTime struct { + NullableTime +} + func (t *IonosTime) UnmarshalJSON(data []byte) error { str := string(data) if shared.Strlen(str) == 0 { diff --git a/vendor/modules.txt b/vendor/modules.txt index 970f8f535..d7d0af1e6 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -66,8 +66,8 @@ github.com/ionos-cloud/sdk-go-auth # github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.1 ## explicit; go 1.22 github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 -# github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2 v2.0.1 -## explicit; go 1.21 +# github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2 v2.0.2 +## explicit; go 1.22 github.com/ionos-cloud/sdk-go-bundle/products/dbaas/mongo/v2 # github.com/ionos-cloud/sdk-go-bundle/shared v0.1.1 ## explicit; go 1.20