diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ea259a71..baf9d7d1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,9 @@ - `lbapplication` [v0.1.0](services/lbapplication/CHANGELOG.md#v010-2025-01-13) - **New**: STACKIT Load Balancer Application module can be used to manage the STACKIT Load Balancer Application - `certificates`: [v0.1.0](services/certificates/CHANGELOG.md#v010-2025-01-13) - - **New**: STACKIT Certificates module can be used to manage the STACKIT Load Balancer Certificates + - **New**: STACKIT Certificates module can be used to manage the STACKIT Load Balancer Certificates## v0.5.0 (2025-01-14) +- `serverbackup`: [v0.5.0](services/serverbackup/CHANGELOG.md#v050-2025-01-14) + - **Feature:** Add new method: `GetServiceResource` ## Release (2025-01-07) diff --git a/services/serverbackup/CHANGELOG.md b/services/serverbackup/CHANGELOG.md index 71559b3d3..cb8abc011 100644 --- a/services/serverbackup/CHANGELOG.md +++ b/services/serverbackup/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.5.0 (2025-01-14) + +- **Feature:** Add new method: `GetServiceResource` + ## v0.4.0 (2024-12-17) - **Feature:** Add support for managing `BackupPolicy` resources diff --git a/services/serverbackup/api_default.go b/services/serverbackup/api_default.go index 20a82327a..c554875c9 100644 --- a/services/serverbackup/api_default.go +++ b/services/serverbackup/api_default.go @@ -1336,6 +1336,126 @@ func (a *APIClient) GetBackupScheduleExecute(ctx context.Context, projectId stri return r.Execute() } +type ApiGetServiceResourceRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + serverId string +} + +func (r ApiGetServiceResourceRequest) Execute() (*GetBackupServiceResponse, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *GetBackupServiceResponse + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.GetServiceResource") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v1/projects/{projectId}/servers/{serverId}/service" + localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"serverId"+"}", url.PathEscape(ParameterValueToString(r.serverId, "serverId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, err + } + + contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) + if ok { + *contextHTTPRequest = req + } + + localVarHTTPResponse, err := a.client.callAPI(req) + contextHTTPResponse, ok := r.ctx.Value(config.ContextHTTPResponse).(**http.Response) + if ok { + *contextHTTPResponse = localVarHTTPResponse + } + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &oapierror.GenericOpenAPIError{ + StatusCode: localVarHTTPResponse.StatusCode, + Body: localVarBody, + ErrorMessage: localVarHTTPResponse.Status, + } + return localVarReturnValue, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &oapierror.GenericOpenAPIError{ + StatusCode: localVarHTTPResponse.StatusCode, + Body: localVarBody, + ErrorMessage: err.Error(), + } + return localVarReturnValue, newErr + } + + return localVarReturnValue, nil +} + +/* +GetServiceResource: get backup service details + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectId project id + @param serverId server id + @return ApiGetServiceResourceRequest +*/ +func (a *APIClient) GetServiceResource(ctx context.Context, projectId string, serverId string) ApiGetServiceResourceRequest { + return ApiGetServiceResourceRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + serverId: serverId, + } +} + +func (a *APIClient) GetServiceResourceExecute(ctx context.Context, projectId string, serverId string) (*GetBackupServiceResponse, error) { + r := ApiGetServiceResourceRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + serverId: serverId, + } + return r.Execute() +} + type ApiListBackupPoliciesRequest struct { ctx context.Context apiService *DefaultApiService diff --git a/services/serverbackup/api_default_test.go b/services/serverbackup/api_default_test.go index 563dc8905..6dbe998a6 100644 --- a/services/serverbackup/api_default_test.go +++ b/services/serverbackup/api_default_test.go @@ -604,6 +604,61 @@ func Test_serverbackup_DefaultApiService(t *testing.T) { } }) + t.Run("Test DefaultApiService GetServiceResource", func(t *testing.T) { + path := "/v1/projects/{projectId}/servers/{serverId}/service" + projectIdValue := "projectId" + path = strings.Replace(path, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) + serverIdValue := "serverId" + path = strings.Replace(path, "{"+"serverId"+"}", url.PathEscape(ParameterValueToString(serverIdValue, "serverId")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(path, func(w http.ResponseWriter, req *http.Request) { + data := GetBackupServiceResponse{} + w.Header().Add("Content-Type", "application/json") + json.NewEncoder(w).Encode(data) + }) + testServer := httptest.NewServer(testDefaultApiServeMux) + defer testServer.Close() + + configuration := &config.Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Region: "test_region", + Servers: config.ServerConfigurations{ + { + URL: testServer.URL, + Description: "Localhost for serverbackup_DefaultApi", + Variables: map[string]config.ServerVariable{ + "region": { + DefaultValue: "test_region.", + EnumValues: []string{ + "test_region.", + }, + }, + }, + }, + }, + OperationServers: map[string]config.ServerConfigurations{}, + } + apiClient, err := NewAPIClient(config.WithCustomConfiguration(configuration), config.WithoutAuthentication()) + if err != nil { + t.Fatalf("creating API client: %v", err) + } + + projectId := "projectId" + serverId := "serverId" + + resp, reqErr := apiClient.GetServiceResource(context.Background(), projectId, serverId).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", reqErr) + } + if resp == nil { + t.Fatalf("response not present") + } + }) + t.Run("Test DefaultApiService ListBackupPolicies", func(t *testing.T) { path := "/v1/projects/{projectId}/backup-policies" projectIdValue := "projectId" diff --git a/services/serverbackup/model_get_backup_service_response.go b/services/serverbackup/model_get_backup_service_response.go new file mode 100644 index 000000000..0981fbc25 --- /dev/null +++ b/services/serverbackup/model_get_backup_service_response.go @@ -0,0 +1,116 @@ +/* +STACKIT Server Backup Management API + +API endpoints for Server Backup Operations on STACKIT Servers. + +API version: 1.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package serverbackup + +import ( + "encoding/json" +) + +// checks if the GetBackupServiceResponse type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &GetBackupServiceResponse{} + +// GetBackupServiceResponse struct for GetBackupServiceResponse +type GetBackupServiceResponse struct { + Enabled *bool `json:"enabled,omitempty"` +} + +// NewGetBackupServiceResponse instantiates a new GetBackupServiceResponse object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewGetBackupServiceResponse() *GetBackupServiceResponse { + this := GetBackupServiceResponse{} + return &this +} + +// NewGetBackupServiceResponseWithDefaults instantiates a new GetBackupServiceResponse object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewGetBackupServiceResponseWithDefaults() *GetBackupServiceResponse { + this := GetBackupServiceResponse{} + return &this +} + +// GetEnabled returns the Enabled field value if set, zero value otherwise. +func (o *GetBackupServiceResponse) GetEnabled() *bool { + if o == nil || IsNil(o.Enabled) { + var ret *bool + return ret + } + return o.Enabled +} + +// GetEnabledOk returns a tuple with the Enabled field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *GetBackupServiceResponse) GetEnabledOk() (*bool, bool) { + if o == nil || IsNil(o.Enabled) { + return nil, false + } + return o.Enabled, true +} + +// HasEnabled returns a boolean if a field has been set. +func (o *GetBackupServiceResponse) HasEnabled() bool { + if o != nil && !IsNil(o.Enabled) { + return true + } + + return false +} + +// SetEnabled gets a reference to the given bool and assigns it to the Enabled field. +func (o *GetBackupServiceResponse) SetEnabled(v *bool) { + o.Enabled = v +} + +func (o GetBackupServiceResponse) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !IsNil(o.Enabled) { + toSerialize["enabled"] = o.Enabled + } + return toSerialize, nil +} + +type NullableGetBackupServiceResponse struct { + value *GetBackupServiceResponse + isSet bool +} + +func (v NullableGetBackupServiceResponse) Get() *GetBackupServiceResponse { + return v.value +} + +func (v *NullableGetBackupServiceResponse) Set(val *GetBackupServiceResponse) { + v.value = val + v.isSet = true +} + +func (v NullableGetBackupServiceResponse) IsSet() bool { + return v.isSet +} + +func (v *NullableGetBackupServiceResponse) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGetBackupServiceResponse(val *GetBackupServiceResponse) *NullableGetBackupServiceResponse { + return &NullableGetBackupServiceResponse{value: val, isSet: true} +} + +func (v NullableGetBackupServiceResponse) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGetBackupServiceResponse) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +}