From c78285e46b4a124f4cbf87f0a8f43fe1f1268f7f Mon Sep 17 00:00:00 2001 From: SaladTechnologies <415806+seniorquico@users.noreply.github.com> Date: Wed, 11 Sep 2024 23:34:55 +0000 Subject: [PATCH] liblab SDK update for version v0.9.0-alpha.2 --- .manifest.json | 19 ++++---- README.md | 44 ++++++++++++++++++- documentation/models/container_status.md | 8 ++-- documentation/models/container_token.md | 6 +-- documentation/models/reallocate_container.md | 6 +-- documentation/services/metadata_service.md | 20 ++++----- internal/clients/rest/client.go | 2 - .../rest/handlers/default_headers_handler.go | 43 ------------------ internal/validation/validate_array_length.go | 12 +++++ internal/validation/validate_array_unique.go | 2 +- internal/validation/validate_max.go | 2 +- internal/validation/validate_min.go | 6 +-- internal/validation/validate_multiple_of.go | 2 +- pkg/metadata/metadata_service.go | 1 + 14 files changed, 88 insertions(+), 85 deletions(-) delete mode 100644 internal/clients/rest/handlers/default_headers_handler.go diff --git a/.manifest.json b/.manifest.json index fd7eab3..801d0e8 100644 --- a/.manifest.json +++ b/.manifest.json @@ -1,11 +1,11 @@ { - "liblabVersion": "2.1.31", - "date": "2024-09-06T14:42:21.566Z", + "liblabVersion": "2.3.1", + "date": "2024-09-11T23:34:37.047Z", "config": { "language": "go", "apiId": 1126, "sdkName": "salad-cloud-imds-sdk", - "sdkVersion": "0.9.0-alpha.1", + "sdkVersion": "0.9.0-alpha.2", "liblabVersion": "2", "deliveryMethods": ["zip"], "languages": ["go"], @@ -26,7 +26,7 @@ "homepage": "https://github.com/saladtechnologies/salad-cloud-imds-sdk-dotnet", "ignoreFiles": [".gitignore", "./LICENSE"], "liblabVersion": "2", - "sdkVersion": "0.9.0-alpha.1", + "sdkVersion": "0.9.0-alpha.2", "targetBranch": "main" }, "go": { @@ -34,7 +34,7 @@ "githubRepoName": "salad-cloud-imds-sdk-go", "ignoreFiles": [".gitignore", "./LICENSE"], "liblabVersion": "2", - "sdkVersion": "0.9.0-alpha.1", + "sdkVersion": "0.9.0-alpha.2", "targetBranch": "main" }, "java": { @@ -58,7 +58,7 @@ "homepage": "https://github.com/saladtechnologies/salad-cloud-imds-sdk-java", "ignoreFiles": [".gitignore", "./LICENSE"], "liblabVersion": "2", - "sdkVersion": "0.9.0-alpha.1", + "sdkVersion": "0.9.0-alpha.2", "targetBranch": "main" }, "python": { @@ -101,7 +101,7 @@ "githubRepoName": "salad-cloud-imds-sdk-python", "ignoreFiles": [".gitignore", "./LICENSE"], "liblabVersion": "2", - "sdkVersion": "0.9.0-alpha.1", + "sdkVersion": "0.9.0-alpha.2", "targetBranch": "main" }, "typescript": { @@ -124,7 +124,7 @@ "homepage": "https://github.com/saladtechnologies/salad-cloud-imds-sdk-javascript", "ignoreFiles": [".gitignore", "./LICENSE"], "liblabVersion": "2", - "sdkVersion": "0.9.0-alpha.1", + "sdkVersion": "0.9.0-alpha.2", "targetBranch": "main" } }, @@ -156,7 +156,7 @@ }, "multiTenant": true, "hooksLocation": { - "bucketKey": "7034/hooks.zip", + "bucketKey": "7096/hooks.zip", "bucketName": "prod-liblab-api-stack-hooks" }, "includeWatermark": false, @@ -208,7 +208,6 @@ "internal/clients/rest/handlers/hook_handler.go", "internal/clients/rest/hooks/hook.go", "internal/clients/rest/hooks/custom_hook.go", - "internal/clients/rest/handlers/default_headers_handler.go", "internal/clients/rest/handlers/retry_handler.go", "internal/clients/rest/handlers/request_validation_handler.go", "internal/validation/validation.go", diff --git a/README.md b/README.md index f54f155..c9eda44 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# SaladCloudImdsSdk Go SDK 0.9.0-alpha.1 +# SaladCloudImdsSdk Go SDK 0.9.0-alpha.2 Welcome to the SaladCloudImdsSdk SDK documentation. This guide will help you get started with integrating and using the SaladCloudImdsSdk SDK in your project. ## Versions - API version: `0.9.0-alpha.1` -- SDK version: `0.9.0-alpha.1` +- SDK version: `0.9.0-alpha.2` ## About the API @@ -17,6 +17,7 @@ The SaladCloud Instance Metadata Service (IMDS). Please refer to the [SaladCloud - [Supported Language Versions](#supported-language-versions) - [Installation](#installation) - [Services](#services) + - [Response Wrappers](#response-wrappers) - [Models](#models) - [License](#license) @@ -39,6 +40,45 @@ The SDK provides various services to interact with the API. +### Response Wrappers + +All services use response wrappers to provide a consistent interface to return the responses from the API. + +The response wrapper itself is a generic struct that contains the response data and metadata. + +
+Below are the response wrappers used in the SDK: + +#### `SaladCloudImdsSdkResponse[T]` + +This response wrapper is used to return the response data from the API. It contains the following fields: + +| Name | Type | Description | +| :------- | :---------------------------------- | :------------------------------------------ | +| Data | `T` | The body of the API response | +| Metadata | `SaladCloudImdsSdkResponseMetadata` | Status code and headers returned by the API | + +#### `SaladCloudImdsSdkError` + +This response wrapper is used to return an error. It contains the following fields: + +| Name | Type | Description | +| :------- | :---------------------------------- | :------------------------------------------ | +| Err | `error` | The error that occurred | +| Body | `T` | The body of the API response | +| Metadata | `SaladCloudImdsSdkResponseMetadata` | Status code and headers returned by the API | + +#### `SaladCloudImdsSdkResponseMetadata` + +This struct is shared by both response wrappers and contains the following fields: + +| Name | Type | Description | +| :--------- | :------------------ | :----------------------------------------------- | +| Headers | `map[string]string` | A map containing the headers returned by the API | +| StatusCode | `int` | The status code returned by the API | + +
+ ## Models The SDK includes several models that represent the data structures used in API requests and responses. These models help in organizing and managing the data efficiently. diff --git a/documentation/models/container_status.md b/documentation/models/container_status.md index bf9ffa7..09fba87 100644 --- a/documentation/models/container_status.md +++ b/documentation/models/container_status.md @@ -4,7 +4,7 @@ Represents the health statuses of the running container. **Properties** -| Name | Type | Required | Description | -| :------ | :--- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Ready | bool | ✅ | `true` if the running container is ready. If a readiness probe is defined, this returns the latest result of the probe. If a readiness probe is not defined but a startup probe is defined, this returns the same value as the `started` property. If neither a readiness probe nor a startup probe are defined, returns `true`. | -| Started | bool | ✅ | `true` if the running container is started. If a startup probe is defined, this returns the latest result of the probe. If a startup probe is not defined, returns `true`. | +| Name | Type | Required | Description | +| :------ | :----- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Ready | `bool` | ✅ | `true` if the running container is ready. If a readiness probe is defined, this returns the latest result of the probe. If a readiness probe is not defined but a startup probe is defined, this returns the same value as the `started` property. If neither a readiness probe nor a startup probe are defined, returns `true`. | +| Started | `bool` | ✅ | `true` if the running container is started. If a startup probe is defined, this returns the latest result of the probe. If a startup probe is not defined, returns `true`. | diff --git a/documentation/models/container_token.md b/documentation/models/container_token.md index 7c78a3f..7eee9e7 100644 --- a/documentation/models/container_token.md +++ b/documentation/models/container_token.md @@ -4,6 +4,6 @@ Represents the identity token of the running container. **Properties** -| Name | Type | Required | Description | -| :--- | :----- | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Jwt | string | ✅ | The JSON Web Token (JWT) that may be used to identify the running container. The JWT may be verified using the JSON Web Key Set (JWKS) available at https://matrix-rest-api.salad.com/.well-known/stash-jwks.json. | +| Name | Type | Required | Description | +| :--- | :------- | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Jwt | `string` | ✅ | The JSON Web Token (JWT) that may be used to identify the running container. The JWT may be verified using the JSON Web Key Set (JWKS) available at https://matrix-rest-api.salad.com/.well-known/stash-jwks.json. | diff --git a/documentation/models/reallocate_container.md b/documentation/models/reallocate_container.md index b55427c..eb3a3cf 100644 --- a/documentation/models/reallocate_container.md +++ b/documentation/models/reallocate_container.md @@ -4,6 +4,6 @@ Represents a request to reallocate a container. **Properties** -| Name | Type | Required | Description | -| :----- | :----- | :------- | :---------------------------------------------------------------------------------------------------------------------------- | -| Reason | string | ✅ | The reason for reallocating the container. This value is reported to SaladCloud support for quality assurance of Salad Nodes. | +| Name | Type | Required | Description | +| :----- | :------- | :------- | :---------------------------------------------------------------------------------------------------------------------------- | +| Reason | `string` | ✅ | The reason for reallocating the container. This value is reported to SaladCloud support for quality assurance of Salad Nodes. | diff --git a/documentation/services/metadata_service.md b/documentation/services/metadata_service.md index 878929f..01005ca 100644 --- a/documentation/services/metadata_service.md +++ b/documentation/services/metadata_service.md @@ -17,10 +17,10 @@ Reallocates the running container to another Salad Node **Parameters** -| Name | Type | Required | Description | -| :------------------ | :------------------ | :------- | :-------------------------- | -| ctx | Context | ✅ | Default go language context | -| reallocateContainer | ReallocateContainer | ✅ | | +| Name | Type | Required | Description | +| :------------------ | :-------------------- | :------- | :-------------------------- | +| ctx | `Context` | ✅ | Default go language context | +| reallocateContainer | `ReallocateContainer` | ✅ | | **Return Type** @@ -61,9 +61,9 @@ Gets the health statuses of the running container **Parameters** -| Name | Type | Required | Description | -| :--- | :------ | :------- | :-------------------------- | -| ctx | Context | ✅ | Default go language context | +| Name | Type | Required | Description | +| :--- | :-------- | :------- | :-------------------------- | +| ctx | `Context` | ✅ | Default go language context | **Return Type** @@ -99,9 +99,9 @@ Gets the identity token of the running container **Parameters** -| Name | Type | Required | Description | -| :--- | :------ | :------- | :-------------------------- | -| ctx | Context | ✅ | Default go language context | +| Name | Type | Required | Description | +| :--- | :-------- | :------- | :-------------------------- | +| ctx | `Context` | ✅ | Default go language context | **Return Type** diff --git a/internal/clients/rest/client.go b/internal/clients/rest/client.go index 31b6bc9..34391f9 100644 --- a/internal/clients/rest/client.go +++ b/internal/clients/rest/client.go @@ -12,7 +12,6 @@ type RestClient[T any] struct { } func NewRestClient[T any](config saladcloudimdssdkconfig.Config) *RestClient[T] { - defaultHeadersHandler := handlers.NewDefaultHeadersHandler[T]() retryHandler := handlers.NewRetryHandler[T]() responseValidationHandler := handlers.NewResponseValidationHandler[T]() unmarshalHandler := handlers.NewUnmarshalHandler[T]() @@ -21,7 +20,6 @@ func NewRestClient[T any](config saladcloudimdssdkconfig.Config) *RestClient[T] terminatingHandler := handlers.NewTerminatingHandler[T]() handlers := handlers.BuildHandlerChain[T](). - AddHandler(defaultHeadersHandler). AddHandler(retryHandler). AddHandler(responseValidationHandler). AddHandler(unmarshalHandler). diff --git a/internal/clients/rest/handlers/default_headers_handler.go b/internal/clients/rest/handlers/default_headers_handler.go deleted file mode 100644 index a4130ff..0000000 --- a/internal/clients/rest/handlers/default_headers_handler.go +++ /dev/null @@ -1,43 +0,0 @@ -package handlers - -import ( - "errors" - - "github.com/saladtechnologies/salad-cloud-imds-sdk-go/internal/clients/rest/httptransport" -) - -type DefaultHeadersHandler[T any] struct { - defaultHeaders map[string]string - nextHandler Handler[T] -} - -func NewDefaultHeadersHandler[T any]() *DefaultHeadersHandler[T] { - defaultHeaders := map[string]string{ - "User-Agent": "go/1.18", - "Content-type": "application/json", - } - - return &DefaultHeadersHandler[T]{ - defaultHeaders: defaultHeaders, - nextHandler: nil, - } -} - -func (h *DefaultHeadersHandler[T]) Handle(request httptransport.Request) (*httptransport.Response[T], *httptransport.ErrorResponse[T]) { - if h.nextHandler == nil { - err := errors.New("Handler chain terminated without terminating handler") - return nil, httptransport.NewErrorResponse[T](err, nil) - } - - nextRequest := request.Clone() - - for key, value := range h.defaultHeaders { - nextRequest.SetHeader(key, value) - } - - return h.nextHandler.Handle(nextRequest) -} - -func (h *DefaultHeadersHandler[T]) SetNext(handler Handler[T]) { - h.nextHandler = handler -} diff --git a/internal/validation/validate_array_length.go b/internal/validation/validate_array_length.go index 17f8dd1..413eb98 100644 --- a/internal/validation/validate_array_length.go +++ b/internal/validation/validate_array_length.go @@ -9,6 +9,10 @@ import ( ) func validateArrayLength(field reflect.StructField, value reflect.Value) error { + if value.IsNil() { + return nil + } + kind := utils.GetReflectKind(value.Type()) if kind != reflect.Array && kind != reflect.Slice { return nil @@ -28,6 +32,10 @@ func validateArrayLength(field reflect.StructField, value reflect.Value) error { } func validateMinLength(field reflect.StructField, value reflect.Value) error { + if value.IsNil() { + return nil + } + minLength, found := field.Tag.Lookup("minLength") if !found { return nil @@ -47,6 +55,10 @@ func validateMinLength(field reflect.StructField, value reflect.Value) error { } func validateMaxLength(field reflect.StructField, value reflect.Value) error { + if value.IsNil() { + return nil + } + maxLength, found := field.Tag.Lookup("maxLength") if !found { return nil diff --git a/internal/validation/validate_array_unique.go b/internal/validation/validate_array_unique.go index f9c3814..45ef727 100644 --- a/internal/validation/validate_array_unique.go +++ b/internal/validation/validate_array_unique.go @@ -7,7 +7,7 @@ import ( func validateArrayIsUnique(field reflect.StructField, value reflect.Value) error { unique, found := field.Tag.Lookup("uniqueItems") - if !found || unique != "true" { + if !found || unique != "true" || value.IsNil() { return nil } diff --git a/internal/validation/validate_max.go b/internal/validation/validate_max.go index c99a9c8..5312491 100644 --- a/internal/validation/validate_max.go +++ b/internal/validation/validate_max.go @@ -10,7 +10,7 @@ import ( func validateMax(field reflect.StructField, value reflect.Value) error { maxValue, found := field.Tag.Lookup("max") - if !found || maxValue == "" { + if !found || maxValue == "" || value.IsNil() { return nil } diff --git a/internal/validation/validate_min.go b/internal/validation/validate_min.go index 053de41..70c71a4 100644 --- a/internal/validation/validate_min.go +++ b/internal/validation/validate_min.go @@ -10,7 +10,7 @@ import ( func validateMin(field reflect.StructField, value reflect.Value) error { minValue, found := field.Tag.Lookup("min") - if !found || minValue == "" { + if !found || minValue == "" || value.IsNil() { return nil } @@ -19,10 +19,6 @@ func validateMin(field reflect.StructField, value reflect.Value) error { return err } - if value.IsNil() { - return fmt.Errorf("field %s is required", field.Name) - } - val := utils.GetReflectValue(value) if val.CanInt() { diff --git a/internal/validation/validate_multiple_of.go b/internal/validation/validate_multiple_of.go index fbe90bc..2c3aa88 100644 --- a/internal/validation/validate_multiple_of.go +++ b/internal/validation/validate_multiple_of.go @@ -11,7 +11,7 @@ import ( func validateMultipleOf(field reflect.StructField, value reflect.Value) error { multipleOfValue, found := field.Tag.Lookup("multipleOf") - if !found || multipleOfValue == "" { + if !found || multipleOfValue == "" || value.IsNil() { return nil } diff --git a/pkg/metadata/metadata_service.go b/pkg/metadata/metadata_service.go index a44b36f..e67148a 100644 --- a/pkg/metadata/metadata_service.go +++ b/pkg/metadata/metadata_service.go @@ -35,6 +35,7 @@ func (api *MetadataService) ReallocateContainer(ctx context.Context, reallocateC client := restClient.NewRestClient[any](config) request := httptransport.NewRequest(ctx, "POST", "/v1/reallocate", config) + request.Headers["Content-Type"] = "application/json" request.Body = reallocateContainer