diff --git a/CHANGELOG.md b/CHANGELOG.md index 1baec815f..ad5ce1124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ - **Features**: Add waiters to manage the STACKIT Git - `observability`: [v0.5.0](services/observability/CHANGELOG.md#v050-2025-04-16) - **Feature:** Add new methods `ListLogsAlertgroups`, `CreateLogsAlertgroups`, `GetLogsAlertgroup`, `UpdateLogsAlertgroup`, `DeleteLogsAlertgroup` +- `kms`: [v0.0.1](services/kms/CHANGELOG.md#v001-2025-04-28) + - **New module:** Initial publication of Key Management Service API + ## Release (2025-04-09) - `cdn`: [v0.3.0](services/cdn/CHANGELOG.md#v030-2025-04-04) diff --git a/examples/kms/go.mod b/examples/kms/go.mod new file mode 100644 index 000000000..b0bc2280c --- /dev/null +++ b/examples/kms/go.mod @@ -0,0 +1,13 @@ +module github.com/stackitcloud/stackit-sdk-go/examples/kms + +go 1.21 + +require ( + github.com/stackitcloud/stackit-sdk-go/core v0.17.1 + github.com/stackitcloud/stackit-sdk-go/services/kms v0.0.0-20250428090914-306285b22343 +) + +require ( + github.com/golang-jwt/jwt/v5 v5.2.2 // indirect + github.com/google/uuid v1.6.0 // indirect +) diff --git a/examples/kms/go.sum b/examples/kms/go.sum new file mode 100644 index 000000000..1d1eb85ac --- /dev/null +++ b/examples/kms/go.sum @@ -0,0 +1,10 @@ +github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8= +github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/stackitcloud/stackit-sdk-go/core v0.17.1 h1:TTrVoB1lERd/qfWzpe6HpwCJSjtaGnUI7UE7ITb5IT0= +github.com/stackitcloud/stackit-sdk-go/core v0.17.1/go.mod h1:8KIw3czdNJ9sdil9QQimxjR6vHjeINFrRv0iZ67wfn0= +github.com/stackitcloud/stackit-sdk-go/services/kms v0.0.0-20250428090914-306285b22343 h1:AA0EkaVGUvlVSTFWimKVlFXAoSwb+5p6BoP4LLt9V0U= +github.com/stackitcloud/stackit-sdk-go/services/kms v0.0.0-20250428090914-306285b22343/go.mod h1:eDyjUgidB+JYtE78aYLd1d/v/ijzm+FrWAzaaZxenso= diff --git a/examples/kms/kms.go b/examples/kms/kms.go new file mode 100644 index 000000000..6d2a34c85 --- /dev/null +++ b/examples/kms/kms.go @@ -0,0 +1,82 @@ +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/stackitcloud/stackit-sdk-go/core/utils" + "github.com/stackitcloud/stackit-sdk-go/services/kms" + "github.com/stackitcloud/stackit-sdk-go/services/kms/wait" +) + +func main() { + // Specify the project ID + projectId := "PROJECT_ID" + region := "eu01" + + // Create a new API client, that uses default authentication and configuration + kmsClient, err := kms.NewAPIClient() + if err != nil { + fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err) + os.Exit(1) + } + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + keyRing, err := kmsClient.CreateKeyRing(ctx, projectId, region).CreateKeyRingPayload(kms.CreateKeyRingPayload{ + Description: utils.Ptr("a test keyring"), + DisplayName: utils.Ptr("test-keyring"), + }).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "cannot create keyring: %v\n", err) + return + } + + key, err := kmsClient.CreateKey(ctx, projectId, region, *keyRing.Id).CreateKeyPayload(kms.CreateKeyPayload{ + Algorithm: kms.ALGORITHM_AES_256_GCM.Ptr(), + Backend: kms.BACKEND_SOFTWARE.Ptr(), + Description: utils.Ptr("A test key"), + DisplayName: utils.Ptr("test-key"), + Purpose: kms.PURPOSE_SYMMETRIC_ENCRYPT_DECRYPT.Ptr(), + }).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "cannot create key: %v\n", err) + return + } + if err := wait.CreateOrUpdateKeyWaitHandler(ctx, kmsClient, projectId, region, *key.KeyRingId, *key.Id); err != nil { + fmt.Fprintf(os.Stderr, "failed to create key: %v", err) + return + } + fmt.Printf("created key %s\n", *key.Id) + + keyRings, err := kmsClient.ListKeyRingsExecute(ctx, projectId, region) + if err != nil { + fmt.Fprintf(os.Stderr, "cannot list keyrings: %v\n", err) + return + } + if keyrings := keyRings.KeyRings; keyrings != nil { + if len(*keyrings) == 0 { + fmt.Printf("no keyrings defined\n") + } else { + for _, keyring := range *keyrings { + fmt.Printf("id=%s displayname=%s status=%s\n", *keyring.Id, *keyring.DisplayName, *keyring.State) + keylist, err := kmsClient.ListKeysExecute(ctx, projectId, region, *key.KeyRingId) + if err != nil { + fmt.Fprintf(os.Stderr, "cannot list keys: %v", err) + return + } + if keys := keylist.Keys; keys != nil { + if len(*keys) == 0 { + fmt.Printf("no keys\n") + } else { + for _, key := range *keys { + fmt.Printf("key id=%s key name=%s key status=%s\n", *key.Id, *key.DisplayName, *key.State) + } + } + } + } + } + } +} diff --git a/go.work b/go.work index 09ae92285..94bb9b900 100644 --- a/go.work +++ b/go.work @@ -10,6 +10,7 @@ use ( ./examples/errorhandling ./examples/iaas ./examples/iaasalpha + ./examples/kms ./examples/loadbalancer ./examples/logme ./examples/mariadb diff --git a/services/kms/CHANGELOG.md b/services/kms/CHANGELOG.md new file mode 100644 index 000000000..581797ca8 --- /dev/null +++ b/services/kms/CHANGELOG.md @@ -0,0 +1,2 @@ +## v0.0.1 (2025-04-28) +- **New module:** Initial publication of Key Management Service API diff --git a/services/kms/LICENSE.md b/services/kms/LICENSE.md new file mode 100644 index 000000000..7e2f06484 --- /dev/null +++ b/services/kms/LICENSE.md @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright 2025 Schwarz IT KG + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/services/kms/NOTICE.txt b/services/kms/NOTICE.txt new file mode 100644 index 000000000..7b2db53fe --- /dev/null +++ b/services/kms/NOTICE.txt @@ -0,0 +1,2 @@ +STACKIT Key Management Service API SDK for Go +Copyright 2025 Schwarz IT KG diff --git a/services/kms/api_default.go b/services/kms/api_default.go index 91eeb5857..76d9b64a9 100644 --- a/services/kms/api_default.go +++ b/services/kms/api_default.go @@ -755,34 +755,32 @@ func (a *APIClient) DecryptExecute(ctx context.Context, projectId string, region return r.Execute() } -type ApiDisableVersionRequest struct { - ctx context.Context - apiService *DefaultApiService - projectId string - regionId string - keyRingId string - keyId string - versionNumber int64 +type ApiDeleteKeyRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string + keyId string } -func (r ApiDisableVersionRequest) Execute() error { +func (r ApiDeleteKeyRequest) Execute() error { var ( - localVarHTTPMethod = http.MethodPost + localVarHTTPMethod = http.MethodDelete localVarPostBody interface{} formFiles []formFile ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.DisableVersion") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.DeleteKey") if err != nil { return &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/disable" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(r.keyId, "keyId")), -1) - localVarPath = strings.Replace(localVarPath, "{"+"versionNumber"+"}", url.PathEscape(ParameterValueToString(r.versionNumber, "versionNumber")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -887,71 +885,64 @@ func (r ApiDisableVersionRequest) Execute() error { } /* -DisableVersion: Disable version +DeleteKey: Delete key -Disables the given version. +Schedules the deletion of the given key @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @param regionId The STACKIT region name the key ring is located in. @param keyRingId The key ring UUID. @param keyId The key UUID. - @param versionNumber The version number. - @return ApiDisableVersionRequest + @return ApiDeleteKeyRequest */ -func (a *APIClient) DisableVersion(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) ApiDisableVersionRequest { - return ApiDisableVersionRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, - keyRingId: keyRingId, - keyId: keyId, - versionNumber: versionNumber, +func (a *APIClient) DeleteKey(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) ApiDeleteKeyRequest { + return ApiDeleteKeyRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, } } -func (a *APIClient) DisableVersionExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) error { - r := ApiDisableVersionRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, - keyRingId: keyRingId, - keyId: keyId, - versionNumber: versionNumber, +func (a *APIClient) DeleteKeyExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) error { + r := ApiDeleteKeyRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, } return r.Execute() } -type ApiEnableVersionRequest struct { - ctx context.Context - apiService *DefaultApiService - projectId string - regionId string - keyRingId string - keyId string - versionNumber int64 +type ApiDeleteKeyRingRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string } -func (r ApiEnableVersionRequest) Execute() error { +func (r ApiDeleteKeyRingRequest) Execute() error { var ( - localVarHTTPMethod = http.MethodPost + localVarHTTPMethod = http.MethodDelete localVarPostBody interface{} formFiles []formFile ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.EnableVersion") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.DeleteKeyRing") if err != nil { return &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/enable" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) - localVarPath = strings.Replace(localVarPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(r.keyId, "keyId")), -1) - localVarPath = strings.Replace(localVarPath, "{"+"versionNumber"+"}", url.PathEscape(ParameterValueToString(r.versionNumber, "versionNumber")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -1056,73 +1047,60 @@ func (r ApiEnableVersionRequest) Execute() error { } /* -EnableVersion: Enable version +DeleteKeyRing: Delete keyring -Enables the given version. +Deletes the given key ring if it is empty @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @param regionId The STACKIT region name the key ring is located in. @param keyRingId The key ring UUID. - @param keyId The key UUID. - @param versionNumber The version number. - @return ApiEnableVersionRequest + @return ApiDeleteKeyRingRequest */ -func (a *APIClient) EnableVersion(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) ApiEnableVersionRequest { - return ApiEnableVersionRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, - keyRingId: keyRingId, - keyId: keyId, - versionNumber: versionNumber, +func (a *APIClient) DeleteKeyRing(ctx context.Context, projectId string, regionId string, keyRingId string) ApiDeleteKeyRingRequest { + return ApiDeleteKeyRingRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, } } -func (a *APIClient) EnableVersionExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) error { - r := ApiEnableVersionRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, - keyRingId: keyRingId, - keyId: keyId, - versionNumber: versionNumber, +func (a *APIClient) DeleteKeyRingExecute(ctx context.Context, projectId string, regionId string, keyRingId string) error { + r := ApiDeleteKeyRingRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, } return r.Execute() } -type ApiEncryptRequest struct { - ctx context.Context - apiService *DefaultApiService - projectId string - regionId string - keyRingId string - keyId string - versionNumber int64 - encryptPayload *EncryptPayload -} - -func (r ApiEncryptRequest) EncryptPayload(encryptPayload EncryptPayload) ApiEncryptRequest { - r.encryptPayload = &encryptPayload - return r +type ApiDestroyVersionRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string + keyId string + versionNumber int64 } -func (r ApiEncryptRequest) Execute() (*EncryptedData, error) { +func (r ApiDestroyVersionRequest) Execute() error { var ( - localVarHTTPMethod = http.MethodPost - localVarPostBody interface{} - formFiles []formFile - localVarReturnValue *EncryptedData + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.Encrypt") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.DestroyVersion") if err != nil { - return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + return &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/encrypt" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/destroy" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) @@ -1132,12 +1110,9 @@ func (r ApiEncryptRequest) Execute() (*EncryptedData, error) { localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} localVarFormParams := url.Values{} - if r.encryptPayload == nil { - return localVarReturnValue, fmt.Errorf("encryptPayload is required and must be specified") - } // to determine the Content-Type header - localVarHTTPContentTypes := []string{"application/json"} + localVarHTTPContentTypes := []string{} // set Content-Type header localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) @@ -1153,11 +1128,9 @@ func (r ApiEncryptRequest) Execute() (*EncryptedData, error) { if localVarHTTPHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } - // body params - localVarPostBody = r.encryptPayload req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { - return localVarReturnValue, err + return err } contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) @@ -1171,14 +1144,14 @@ func (r ApiEncryptRequest) Execute() (*EncryptedData, error) { *contextHTTPResponse = localVarHTTPResponse } if err != nil || localVarHTTPResponse == nil { - return localVarReturnValue, err + return err } localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) localVarHTTPResponse.Body.Close() localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) if err != nil { - return localVarReturnValue, err + return err } if localVarHTTPResponse.StatusCode >= 300 { @@ -1192,75 +1165,54 @@ func (r ApiEncryptRequest) Execute() (*EncryptedData, error) { err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 401 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 404 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr - } - newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) - newErr.Model = v - return localVarReturnValue, newErr - } - if localVarHTTPResponse.StatusCode == 409 { - var v HttpError - err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) - if err != nil { - newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 500 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v } - 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 newErr } - return localVarReturnValue, nil + return nil } /* -Encrypt: Encrypt +DestroyVersion: Destroy version -Encrypts data using the given key version. +Removes the key material of a version permanently. @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @@ -1268,10 +1220,10 @@ Encrypts data using the given key version. @param keyRingId The key ring UUID. @param keyId The key UUID. @param versionNumber The version number. - @return ApiEncryptRequest + @return ApiDestroyVersionRequest */ -func (a *APIClient) Encrypt(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) ApiEncryptRequest { - return ApiEncryptRequest{ +func (a *APIClient) DestroyVersion(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) ApiDestroyVersionRequest { + return ApiDestroyVersionRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, @@ -1282,8 +1234,8 @@ func (a *APIClient) Encrypt(ctx context.Context, projectId string, regionId stri } } -func (a *APIClient) EncryptExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) (*EncryptedData, error) { - r := ApiEncryptRequest{ +func (a *APIClient) DestroyVersionExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) error { + r := ApiDestroyVersionRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, @@ -1295,33 +1247,34 @@ func (a *APIClient) EncryptExecute(ctx context.Context, projectId string, region return r.Execute() } -type ApiGetKeyRequest struct { - ctx context.Context - apiService *DefaultApiService - projectId string - regionId string - keyRingId string - keyId string +type ApiDisableVersionRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string + keyId string + versionNumber int64 } -func (r ApiGetKeyRequest) Execute() (*Key, error) { +func (r ApiDisableVersionRequest) Execute() error { var ( - localVarHTTPMethod = http.MethodGet - localVarPostBody interface{} - formFiles []formFile - localVarReturnValue *Key + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.GetKey") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.DisableVersion") if err != nil { - return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + return &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/disable" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(r.keyId, "keyId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"versionNumber"+"}", url.PathEscape(ParameterValueToString(r.versionNumber, "versionNumber")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -1346,7 +1299,7 @@ func (r ApiGetKeyRequest) Execute() (*Key, error) { } req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { - return localVarReturnValue, err + return err } contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) @@ -1360,14 +1313,14 @@ func (r ApiGetKeyRequest) Execute() (*Key, error) { *contextHTTPResponse = localVarHTTPResponse } if err != nil || localVarHTTPResponse == nil { - return localVarReturnValue, err + return err } localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) localVarHTTPResponse.Body.Close() localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) if err != nil { - return localVarReturnValue, err + return err } if localVarHTTPResponse.StatusCode >= 300 { @@ -1381,120 +1334,116 @@ func (r ApiGetKeyRequest) Execute() (*Key, error) { err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 401 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 404 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 500 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v } - return localVarReturnValue, newErr + return 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 + return nil } /* -GetKey: Get key +DisableVersion: Disable version -Returns the details for the given key. +Disables the given version. @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @param regionId The STACKIT region name the key ring is located in. @param keyRingId The key ring UUID. @param keyId The key UUID. - @return ApiGetKeyRequest + @param versionNumber The version number. + @return ApiDisableVersionRequest */ -func (a *APIClient) GetKey(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) ApiGetKeyRequest { - return ApiGetKeyRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, - keyRingId: keyRingId, - keyId: keyId, +func (a *APIClient) DisableVersion(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) ApiDisableVersionRequest { + return ApiDisableVersionRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, + versionNumber: versionNumber, } } -func (a *APIClient) GetKeyExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) (*Key, error) { - r := ApiGetKeyRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, - keyRingId: keyRingId, - keyId: keyId, +func (a *APIClient) DisableVersionExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) error { + r := ApiDisableVersionRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, + versionNumber: versionNumber, } return r.Execute() } -type ApiGetKeyRingRequest struct { - ctx context.Context - apiService *DefaultApiService - projectId string - regionId string - keyRingId string +type ApiEnableVersionRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string + keyId string + versionNumber int64 } -func (r ApiGetKeyRingRequest) Execute() (*KeyRing, error) { +func (r ApiEnableVersionRequest) Execute() error { var ( - localVarHTTPMethod = http.MethodGet - localVarPostBody interface{} - formFiles []formFile - localVarReturnValue *KeyRing + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.GetKeyRing") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.EnableVersion") if err != nil { - return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + return &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/enable" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(r.keyId, "keyId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"versionNumber"+"}", url.PathEscape(ParameterValueToString(r.versionNumber, "versionNumber")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -1519,7 +1468,7 @@ func (r ApiGetKeyRingRequest) Execute() (*KeyRing, error) { } req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { - return localVarReturnValue, err + return err } contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) @@ -1533,14 +1482,14 @@ func (r ApiGetKeyRingRequest) Execute() (*KeyRing, error) { *contextHTTPResponse = localVarHTTPResponse } if err != nil || localVarHTTPResponse == nil { - return localVarReturnValue, err + return err } localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) localVarHTTPResponse.Body.Close() localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) if err != nil { - return localVarReturnValue, err + return err } if localVarHTTPResponse.StatusCode >= 300 { @@ -1554,116 +1503,118 @@ func (r ApiGetKeyRingRequest) Execute() (*KeyRing, error) { err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 401 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 404 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 500 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v } - 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 newErr } - return localVarReturnValue, nil + return nil } /* -GetKeyRing: Get key ring +EnableVersion: Enable version -Returns the details for the given key ring. +Enables the given version. @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @param regionId The STACKIT region name the key ring is located in. @param keyRingId The key ring UUID. - @return ApiGetKeyRingRequest + @param keyId The key UUID. + @param versionNumber The version number. + @return ApiEnableVersionRequest */ -func (a *APIClient) GetKeyRing(ctx context.Context, projectId string, regionId string, keyRingId string) ApiGetKeyRingRequest { - return ApiGetKeyRingRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, - keyRingId: keyRingId, +func (a *APIClient) EnableVersion(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) ApiEnableVersionRequest { + return ApiEnableVersionRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, + versionNumber: versionNumber, } } -func (a *APIClient) GetKeyRingExecute(ctx context.Context, projectId string, regionId string, keyRingId string) (*KeyRing, error) { - r := ApiGetKeyRingRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, - keyRingId: keyRingId, +func (a *APIClient) EnableVersionExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) error { + r := ApiEnableVersionRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, + versionNumber: versionNumber, } return r.Execute() } -type ApiGetVersionRequest struct { - ctx context.Context - apiService *DefaultApiService - projectId string - regionId string - keyRingId string - keyId string - versionNumber int64 +type ApiEncryptRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string + keyId string + versionNumber int64 + encryptPayload *EncryptPayload } -func (r ApiGetVersionRequest) Execute() (*Version, error) { +func (r ApiEncryptRequest) EncryptPayload(encryptPayload EncryptPayload) ApiEncryptRequest { + r.encryptPayload = &encryptPayload + return r +} + +func (r ApiEncryptRequest) Execute() (*EncryptedData, error) { var ( - localVarHTTPMethod = http.MethodGet + localVarHTTPMethod = http.MethodPost localVarPostBody interface{} formFiles []formFile - localVarReturnValue *Version + localVarReturnValue *EncryptedData ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.GetVersion") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.Encrypt") if err != nil { return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/encrypt" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) @@ -1673,9 +1624,12 @@ func (r ApiGetVersionRequest) Execute() (*Version, error) { localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} localVarFormParams := url.Values{} + if r.encryptPayload == nil { + return localVarReturnValue, fmt.Errorf("encryptPayload is required and must be specified") + } // to determine the Content-Type header - localVarHTTPContentTypes := []string{} + localVarHTTPContentTypes := []string{"application/json"} // set Content-Type header localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) @@ -1691,6 +1645,8 @@ func (r ApiGetVersionRequest) Execute() (*Version, error) { if localVarHTTPHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } + // body params + localVarPostBody = r.encryptPayload req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { return localVarReturnValue, err @@ -1756,6 +1712,17 @@ func (r ApiGetVersionRequest) Execute() (*Version, error) { newErr.Model = v return localVarReturnValue, newErr } + if localVarHTTPResponse.StatusCode == 409 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } if localVarHTTPResponse.StatusCode == 500 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) @@ -1783,9 +1750,9 @@ func (r ApiGetVersionRequest) Execute() (*Version, error) { } /* -GetVersion: Get version +Encrypt: Encrypt -Returns the details for the given version. +Encrypts data using the given key version. @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @@ -1793,10 +1760,10 @@ Returns the details for the given version. @param keyRingId The key ring UUID. @param keyId The key UUID. @param versionNumber The version number. - @return ApiGetVersionRequest + @return ApiEncryptRequest */ -func (a *APIClient) GetVersion(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) ApiGetVersionRequest { - return ApiGetVersionRequest{ +func (a *APIClient) Encrypt(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) ApiEncryptRequest { + return ApiEncryptRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, @@ -1807,8 +1774,8 @@ func (a *APIClient) GetVersion(ctx context.Context, projectId string, regionId s } } -func (a *APIClient) GetVersionExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) (*Version, error) { - r := ApiGetVersionRequest{ +func (a *APIClient) EncryptExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) (*EncryptedData, error) { + r := ApiEncryptRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, @@ -1820,33 +1787,33 @@ func (a *APIClient) GetVersionExecute(ctx context.Context, projectId string, reg return r.Execute() } -type ApiGetWrappingKeyRequest struct { - ctx context.Context - apiService *DefaultApiService - projectId string - regionId string - keyRingId string - wrappingKeyId string +type ApiGetKeyRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string + keyId string } -func (r ApiGetWrappingKeyRequest) Execute() (*WrappingKey, error) { +func (r ApiGetKeyRequest) Execute() (*Key, error) { var ( localVarHTTPMethod = http.MethodGet localVarPostBody interface{} formFiles []formFile - localVarReturnValue *WrappingKey + localVarReturnValue *Key ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.GetWrappingKey") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.GetKey") if err != nil { return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/wrappingkeys/{wrappingKeyId}" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) - localVarPath = strings.Replace(localVarPath, "{"+"wrappingKeyId"+"}", url.PathEscape(ParameterValueToString(r.wrappingKeyId, "wrappingKeyId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(r.keyId, "keyId")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -1961,83 +1928,948 @@ func (r ApiGetWrappingKeyRequest) Execute() (*WrappingKey, error) { } /* -GetWrappingKey: Get wrapping key +GetKey: Get key -Returns the details for the given wrapping key. +Returns the details for the given key. @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @param regionId The STACKIT region name the key ring is located in. @param keyRingId The key ring UUID. - @param wrappingKeyId The wrapping key UUID. - @return ApiGetWrappingKeyRequest + @param keyId The key UUID. + @return ApiGetKeyRequest */ -func (a *APIClient) GetWrappingKey(ctx context.Context, projectId string, regionId string, keyRingId string, wrappingKeyId string) ApiGetWrappingKeyRequest { - return ApiGetWrappingKeyRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, +func (a *APIClient) GetKey(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) ApiGetKeyRequest { + return ApiGetKeyRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, + } +} + +func (a *APIClient) GetKeyExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) (*Key, error) { + r := ApiGetKeyRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, + } + return r.Execute() +} + +type ApiGetKeyRingRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string +} + +func (r ApiGetKeyRingRequest) Execute() (*KeyRing, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *KeyRing + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.GetKeyRing") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}" + localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -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, + } + if localVarHTTPResponse.StatusCode == 400 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + } + 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 +} + +/* +GetKeyRing: Get key ring + +Returns the details for the given key ring. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectId The STACKIT portal project UUID the key ring is part of. + @param regionId The STACKIT region name the key ring is located in. + @param keyRingId The key ring UUID. + @return ApiGetKeyRingRequest +*/ +func (a *APIClient) GetKeyRing(ctx context.Context, projectId string, regionId string, keyRingId string) ApiGetKeyRingRequest { + return ApiGetKeyRingRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + } +} + +func (a *APIClient) GetKeyRingExecute(ctx context.Context, projectId string, regionId string, keyRingId string) (*KeyRing, error) { + r := ApiGetKeyRingRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + } + return r.Execute() +} + +type ApiGetVersionRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string + keyId string + versionNumber int64 +} + +func (r ApiGetVersionRequest) Execute() (*Version, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Version + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.GetVersion") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}" + localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(r.keyId, "keyId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"versionNumber"+"}", url.PathEscape(ParameterValueToString(r.versionNumber, "versionNumber")), -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, + } + if localVarHTTPResponse.StatusCode == 400 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + } + 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 +} + +/* +GetVersion: Get version + +Returns the details for the given version. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectId The STACKIT portal project UUID the key ring is part of. + @param regionId The STACKIT region name the key ring is located in. + @param keyRingId The key ring UUID. + @param keyId The key UUID. + @param versionNumber The version number. + @return ApiGetVersionRequest +*/ +func (a *APIClient) GetVersion(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) ApiGetVersionRequest { + return ApiGetVersionRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, + versionNumber: versionNumber, + } +} + +func (a *APIClient) GetVersionExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) (*Version, error) { + r := ApiGetVersionRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, + versionNumber: versionNumber, + } + return r.Execute() +} + +type ApiGetWrappingKeyRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string + wrappingKeyId string +} + +func (r ApiGetWrappingKeyRequest) Execute() (*WrappingKey, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *WrappingKey + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.GetWrappingKey") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/wrappingkeys/{wrappingKeyId}" + localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"wrappingKeyId"+"}", url.PathEscape(ParameterValueToString(r.wrappingKeyId, "wrappingKeyId")), -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, + } + if localVarHTTPResponse.StatusCode == 400 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + } + 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 +} + +/* +GetWrappingKey: Get wrapping key + +Returns the details for the given wrapping key. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectId The STACKIT portal project UUID the key ring is part of. + @param regionId The STACKIT region name the key ring is located in. + @param keyRingId The key ring UUID. + @param wrappingKeyId The wrapping key UUID. + @return ApiGetWrappingKeyRequest +*/ +func (a *APIClient) GetWrappingKey(ctx context.Context, projectId string, regionId string, keyRingId string, wrappingKeyId string) ApiGetWrappingKeyRequest { + return ApiGetWrappingKeyRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + wrappingKeyId: wrappingKeyId, + } +} + +func (a *APIClient) GetWrappingKeyExecute(ctx context.Context, projectId string, regionId string, keyRingId string, wrappingKeyId string) (*WrappingKey, error) { + r := ApiGetWrappingKeyRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, keyRingId: keyRingId, wrappingKeyId: wrappingKeyId, } + return r.Execute() +} + +type ApiImportKeyRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string + keyId string + importKeyPayload *ImportKeyPayload +} + +func (r ApiImportKeyRequest) ImportKeyPayload(importKeyPayload ImportKeyPayload) ApiImportKeyRequest { + r.importKeyPayload = &importKeyPayload + return r +} + +func (r ApiImportKeyRequest) Execute() (*Key, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *Key + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ImportKey") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/import" + localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(r.keyId, "keyId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.importKeyPayload == nil { + return localVarReturnValue, fmt.Errorf("importKeyPayload is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // 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 + } + // body params + localVarPostBody = r.importKeyPayload + 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, + } + if localVarHTTPResponse.StatusCode == 400 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 404 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 409 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + } + 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 } -func (a *APIClient) GetWrappingKeyExecute(ctx context.Context, projectId string, regionId string, keyRingId string, wrappingKeyId string) (*WrappingKey, error) { - r := ApiGetWrappingKeyRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, - keyRingId: keyRingId, - wrappingKeyId: wrappingKeyId, +/* +ImportKey: Import key + +Imports a new version to the given key. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectId The STACKIT portal project UUID the key ring is part of. + @param regionId The STACKIT region name the key ring is located in. + @param keyRingId The key ring UUID. + @param keyId The key UUID. + @return ApiImportKeyRequest +*/ +func (a *APIClient) ImportKey(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) ApiImportKeyRequest { + return ApiImportKeyRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, + } +} + +func (a *APIClient) ImportKeyExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) (*Key, error) { + r := ApiImportKeyRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, } return r.Execute() } -type ApiImportKeyRequest struct { - ctx context.Context - apiService *DefaultApiService - projectId string - regionId string - keyRingId string - keyId string - importKeyPayload *ImportKeyPayload +type ApiListKeyRingsRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string } -func (r ApiImportKeyRequest) ImportKeyPayload(importKeyPayload ImportKeyPayload) ApiImportKeyRequest { - r.importKeyPayload = &importKeyPayload - return r +func (r ApiListKeyRingsRequest) Execute() (*KeyRingList, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *KeyRingList + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListKeyRings") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings" + localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -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, + } + if localVarHTTPResponse.StatusCode == 400 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 401 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } + if localVarHTTPResponse.StatusCode == 500 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + } + 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 } -func (r ApiImportKeyRequest) Execute() (*Key, error) { +/* +ListKeyRings: List key rings + +Returns a list of all key rings within the project. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param projectId The STACKIT portal project UUID the key ring is part of. + @param regionId The STACKIT region name the key ring is located in. + @return ApiListKeyRingsRequest +*/ +func (a *APIClient) ListKeyRings(ctx context.Context, projectId string, regionId string) ApiListKeyRingsRequest { + return ApiListKeyRingsRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + } +} + +func (a *APIClient) ListKeyRingsExecute(ctx context.Context, projectId string, regionId string) (*KeyRingList, error) { + r := ApiListKeyRingsRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + } + return r.Execute() +} + +type ApiListKeysRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string +} + +func (r ApiListKeysRequest) Execute() (*KeyList, error) { var ( - localVarHTTPMethod = http.MethodPost + localVarHTTPMethod = http.MethodGet localVarPostBody interface{} formFiles []formFile - localVarReturnValue *Key + localVarReturnValue *KeyList ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ImportKey") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListKeys") if err != nil { return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/import" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) - localVarPath = strings.Replace(localVarPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(r.keyId, "keyId")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} localVarFormParams := url.Values{} - if r.importKeyPayload == nil { - return localVarReturnValue, fmt.Errorf("importKeyPayload is required and must be specified") - } // to determine the Content-Type header - localVarHTTPContentTypes := []string{"application/json"} + localVarHTTPContentTypes := []string{} // set Content-Type header localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) @@ -2053,8 +2885,6 @@ func (r ApiImportKeyRequest) Execute() (*Key, error) { if localVarHTTPHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } - // body params - localVarPostBody = r.importKeyPayload req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { return localVarReturnValue, err @@ -2120,17 +2950,6 @@ func (r ApiImportKeyRequest) Execute() (*Key, error) { newErr.Model = v return localVarReturnValue, newErr } - if localVarHTTPResponse.StatusCode == 409 { - var v HttpError - err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) - if err != nil { - newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr - } - newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) - newErr.Model = v - return localVarReturnValue, newErr - } if localVarHTTPResponse.StatusCode == 500 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) @@ -2158,63 +2977,64 @@ func (r ApiImportKeyRequest) Execute() (*Key, error) { } /* -ImportKey: Import key +ListKeys: List keys -Imports a new version to the given key. +Returns the keys for the given key ring. @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @param regionId The STACKIT region name the key ring is located in. @param keyRingId The key ring UUID. - @param keyId The key UUID. - @return ApiImportKeyRequest + @return ApiListKeysRequest */ -func (a *APIClient) ImportKey(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) ApiImportKeyRequest { - return ApiImportKeyRequest{ +func (a *APIClient) ListKeys(ctx context.Context, projectId string, regionId string, keyRingId string) ApiListKeysRequest { + return ApiListKeysRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, regionId: regionId, keyRingId: keyRingId, - keyId: keyId, } } -func (a *APIClient) ImportKeyExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) (*Key, error) { - r := ApiImportKeyRequest{ +func (a *APIClient) ListKeysExecute(ctx context.Context, projectId string, regionId string, keyRingId string) (*KeyList, error) { + r := ApiListKeysRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, regionId: regionId, keyRingId: keyRingId, - keyId: keyId, } return r.Execute() } -type ApiListKeyRingsRequest struct { +type ApiListVersionsRequest struct { ctx context.Context apiService *DefaultApiService projectId string regionId string + keyRingId string + keyId string } -func (r ApiListKeyRingsRequest) Execute() (*KeyRingList, error) { +func (r ApiListVersionsRequest) Execute() (*VersionList, error) { var ( localVarHTTPMethod = http.MethodGet localVarPostBody interface{} formFiles []formFile - localVarReturnValue *KeyRingList + localVarReturnValue *VersionList ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListKeyRings") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListVersions") if err != nil { return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(r.keyId, "keyId")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -2291,6 +3111,17 @@ func (r ApiListKeyRingsRequest) Execute() (*KeyRingList, error) { newErr.Model = v return localVarReturnValue, newErr } + if localVarHTTPResponse.StatusCode == 404 { + var v HttpError + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.ErrorMessage = err.Error() + return localVarReturnValue, newErr + } + newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) + newErr.Model = v + return localVarReturnValue, newErr + } if localVarHTTPResponse.StatusCode == 500 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) @@ -2318,35 +3149,41 @@ func (r ApiListKeyRingsRequest) Execute() (*KeyRingList, error) { } /* -ListKeyRings: List key rings +ListVersions: List versions -Returns a list of all key rings within the project. +Returns a list of all versions of a given key. @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @param regionId The STACKIT region name the key ring is located in. - @return ApiListKeyRingsRequest + @param keyRingId The key ring UUID. + @param keyId The key UUID. + @return ApiListVersionsRequest */ -func (a *APIClient) ListKeyRings(ctx context.Context, projectId string, regionId string) ApiListKeyRingsRequest { - return ApiListKeyRingsRequest{ +func (a *APIClient) ListVersions(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) ApiListVersionsRequest { + return ApiListVersionsRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, } } -func (a *APIClient) ListKeyRingsExecute(ctx context.Context, projectId string, regionId string) (*KeyRingList, error) { - r := ApiListKeyRingsRequest{ +func (a *APIClient) ListVersionsExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) (*VersionList, error) { + r := ApiListVersionsRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, } return r.Execute() } -type ApiListKeysRequest struct { +type ApiListWrappingKeysRequest struct { ctx context.Context apiService *DefaultApiService projectId string @@ -2354,20 +3191,20 @@ type ApiListKeysRequest struct { keyRingId string } -func (r ApiListKeysRequest) Execute() (*KeyList, error) { +func (r ApiListWrappingKeysRequest) Execute() (*WrappingKeyList, error) { var ( localVarHTTPMethod = http.MethodGet localVarPostBody interface{} formFiles []formFile - localVarReturnValue *KeyList + localVarReturnValue *WrappingKeyList ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListKeys") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListWrappingKeys") if err != nil { return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/wrappingkeys" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) @@ -2485,18 +3322,18 @@ func (r ApiListKeysRequest) Execute() (*KeyList, error) { } /* -ListKeys: List keys +ListWrappingKeys: List wrapping keys -Returns the keys for the given key ring. +Returns the wrapping keys for the given key ring. @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @param regionId The STACKIT region name the key ring is located in. @param keyRingId The key ring UUID. - @return ApiListKeysRequest + @return ApiListWrappingKeysRequest */ -func (a *APIClient) ListKeys(ctx context.Context, projectId string, regionId string, keyRingId string) ApiListKeysRequest { - return ApiListKeysRequest{ +func (a *APIClient) ListWrappingKeys(ctx context.Context, projectId string, regionId string, keyRingId string) ApiListWrappingKeysRequest { + return ApiListWrappingKeysRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, @@ -2505,8 +3342,8 @@ func (a *APIClient) ListKeys(ctx context.Context, projectId string, regionId str } } -func (a *APIClient) ListKeysExecute(ctx context.Context, projectId string, regionId string, keyRingId string) (*KeyList, error) { - r := ApiListKeysRequest{ +func (a *APIClient) ListWrappingKeysExecute(ctx context.Context, projectId string, regionId string, keyRingId string) (*WrappingKeyList, error) { + r := ApiListWrappingKeysRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, @@ -2516,7 +3353,7 @@ func (a *APIClient) ListKeysExecute(ctx context.Context, projectId string, regio return r.Execute() } -type ApiListVersionsRequest struct { +type ApiRestoreKeyRequest struct { ctx context.Context apiService *DefaultApiService projectId string @@ -2525,20 +3362,19 @@ type ApiListVersionsRequest struct { keyId string } -func (r ApiListVersionsRequest) Execute() (*VersionList, error) { +func (r ApiRestoreKeyRequest) Execute() error { var ( - localVarHTTPMethod = http.MethodGet - localVarPostBody interface{} - formFiles []formFile - localVarReturnValue *VersionList + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListVersions") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.RestoreKey") if err != nil { - return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + return &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/restore" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) @@ -2567,7 +3403,7 @@ func (r ApiListVersionsRequest) Execute() (*VersionList, error) { } req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { - return localVarReturnValue, err + return err } contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) @@ -2581,14 +3417,14 @@ func (r ApiListVersionsRequest) Execute() (*VersionList, error) { *contextHTTPResponse = localVarHTTPResponse } if err != nil || localVarHTTPResponse == nil { - return localVarReturnValue, err + return err } localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) localVarHTTPResponse.Body.Close() localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) if err != nil { - return localVarReturnValue, err + return err } if localVarHTTPResponse.StatusCode >= 300 { @@ -2602,74 +3438,64 @@ func (r ApiListVersionsRequest) Execute() (*VersionList, error) { err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 401 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 404 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 500 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v } - 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 newErr } - return localVarReturnValue, nil + return nil } /* -ListVersions: List versions +RestoreKey: Restore deleted key -Returns a list of all versions of a given key. +Restores the given key from being deleted. @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @param regionId The STACKIT region name the key ring is located in. @param keyRingId The key ring UUID. @param keyId The key UUID. - @return ApiListVersionsRequest + @return ApiRestoreKeyRequest */ -func (a *APIClient) ListVersions(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) ApiListVersionsRequest { - return ApiListVersionsRequest{ +func (a *APIClient) RestoreKey(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) ApiRestoreKeyRequest { + return ApiRestoreKeyRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, @@ -2679,8 +3505,8 @@ func (a *APIClient) ListVersions(ctx context.Context, projectId string, regionId } } -func (a *APIClient) ListVersionsExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) (*VersionList, error) { - r := ApiListVersionsRequest{ +func (a *APIClient) RestoreKeyExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) error { + r := ApiRestoreKeyRequest{ apiService: a.defaultApi, ctx: ctx, projectId: projectId, @@ -2691,31 +3517,34 @@ func (a *APIClient) ListVersionsExecute(ctx context.Context, projectId string, r return r.Execute() } -type ApiListWrappingKeysRequest struct { - ctx context.Context - apiService *DefaultApiService - projectId string - regionId string - keyRingId string +type ApiRestoreVersionRequest struct { + ctx context.Context + apiService *DefaultApiService + projectId string + regionId string + keyRingId string + keyId string + versionNumber int64 } -func (r ApiListWrappingKeysRequest) Execute() (*WrappingKeyList, error) { +func (r ApiRestoreVersionRequest) Execute() error { var ( - localVarHTTPMethod = http.MethodGet - localVarPostBody interface{} - formFiles []formFile - localVarReturnValue *WrappingKeyList + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile ) a := r.apiService - localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListWrappingKeys") + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.RestoreVersion") if err != nil { - return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + return &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} } - localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/wrappingkeys" + localVarPath := localBasePath + "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/restore" localVarPath = strings.Replace(localVarPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(r.projectId, "projectId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(r.regionId, "regionId")), -1) localVarPath = strings.Replace(localVarPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(r.keyRingId, "keyRingId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(r.keyId, "keyId")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"versionNumber"+"}", url.PathEscape(ParameterValueToString(r.versionNumber, "versionNumber")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -2740,7 +3569,7 @@ func (r ApiListWrappingKeysRequest) Execute() (*WrappingKeyList, error) { } req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { - return localVarReturnValue, err + return err } contextHTTPRequest, ok := r.ctx.Value(config.ContextHTTPRequest).(**http.Request) @@ -2754,14 +3583,14 @@ func (r ApiListWrappingKeysRequest) Execute() (*WrappingKeyList, error) { *contextHTTPResponse = localVarHTTPResponse } if err != nil || localVarHTTPResponse == nil { - return localVarReturnValue, err + return err } localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) localVarHTTPResponse.Body.Close() localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) if err != nil { - return localVarReturnValue, err + return err } if localVarHTTPResponse.StatusCode >= 300 { @@ -2775,88 +3604,84 @@ func (r ApiListWrappingKeysRequest) Execute() (*WrappingKeyList, error) { err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 401 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 404 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v - return localVarReturnValue, newErr + return newErr } if localVarHTTPResponse.StatusCode == 500 { var v HttpError err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) if err != nil { newErr.ErrorMessage = err.Error() - return localVarReturnValue, newErr + return newErr } newErr.ErrorMessage = oapierror.FormatErrorMessage(localVarHTTPResponse.Status, &v) newErr.Model = v } - 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 newErr } - return localVarReturnValue, nil + return nil } /* -ListWrappingKeys: List wrapping keys +RestoreVersion: Restore version -Returns the wrapping keys for the given key ring. +Restores the given version from being destroyed @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). @param projectId The STACKIT portal project UUID the key ring is part of. @param regionId The STACKIT region name the key ring is located in. @param keyRingId The key ring UUID. - @return ApiListWrappingKeysRequest + @param keyId The key UUID. + @param versionNumber The version number. + @return ApiRestoreVersionRequest */ -func (a *APIClient) ListWrappingKeys(ctx context.Context, projectId string, regionId string, keyRingId string) ApiListWrappingKeysRequest { - return ApiListWrappingKeysRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, - keyRingId: keyRingId, +func (a *APIClient) RestoreVersion(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) ApiRestoreVersionRequest { + return ApiRestoreVersionRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, + versionNumber: versionNumber, } } -func (a *APIClient) ListWrappingKeysExecute(ctx context.Context, projectId string, regionId string, keyRingId string) (*WrappingKeyList, error) { - r := ApiListWrappingKeysRequest{ - apiService: a.defaultApi, - ctx: ctx, - projectId: projectId, - regionId: regionId, - keyRingId: keyRingId, +func (a *APIClient) RestoreVersionExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) error { + r := ApiRestoreVersionRequest{ + apiService: a.defaultApi, + ctx: ctx, + projectId: projectId, + regionId: regionId, + keyRingId: keyRingId, + keyId: keyId, + versionNumber: versionNumber, } return r.Execute() } diff --git a/services/kms/api_default_test.go b/services/kms/api_default_test.go index 48be45645..ba3427d68 100644 --- a/services/kms/api_default_test.go +++ b/services/kms/api_default_test.go @@ -28,7 +28,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -87,7 +87,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) testDefaultApiServeMux := http.NewServeMux() @@ -143,7 +143,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/wrappingkeys" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -202,7 +202,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/decrypt" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -263,11 +263,176 @@ func Test_kms_DefaultApiService(t *testing.T) { } }) + t.Run("Test DefaultApiService DeleteKey", func(t *testing.T) { + _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}" + projectIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) + regionIdValue := "regionId-value" + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) + keyRingIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) + keyIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(keyIdValue, "keyId")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { + }) + 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 kms_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 := projectIdValue + regionId := regionIdValue + keyRingId := keyRingIdValue + keyId := keyIdValue + + reqErr := apiClient.DeleteKey(context.Background(), projectId, regionId, keyRingId, keyId).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", reqErr) + } + }) + + t.Run("Test DefaultApiService DeleteKeyRing", func(t *testing.T) { + _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}" + projectIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) + regionIdValue := "regionId-value" + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) + keyRingIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { + }) + 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 kms_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 := projectIdValue + regionId := regionIdValue + keyRingId := keyRingIdValue + + reqErr := apiClient.DeleteKeyRing(context.Background(), projectId, regionId, keyRingId).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", reqErr) + } + }) + + t.Run("Test DefaultApiService DestroyVersion", func(t *testing.T) { + _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/destroy" + projectIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) + regionIdValue := "regionId-value" + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) + keyRingIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) + keyIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(keyIdValue, "keyId")), -1) + versionNumberValue := int64(123) + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"versionNumber"+"}", url.PathEscape(ParameterValueToString(versionNumberValue, "versionNumber")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { + }) + 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 kms_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 := projectIdValue + regionId := regionIdValue + keyRingId := keyRingIdValue + keyId := keyIdValue + versionNumber := versionNumberValue + + reqErr := apiClient.DestroyVersion(context.Background(), projectId, regionId, keyRingId, keyId, versionNumber).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", reqErr) + } + }) + t.Run("Test DefaultApiService DisableVersion", func(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/disable" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -325,7 +490,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/enable" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -383,7 +548,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/encrypt" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -448,7 +613,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -509,7 +674,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -567,7 +732,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -631,7 +796,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/wrappingkeys/{wrappingKeyId}" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -692,7 +857,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/import" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -754,7 +919,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) testDefaultApiServeMux := http.NewServeMux() @@ -809,7 +974,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -867,7 +1032,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -928,7 +1093,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/wrappingkeys" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -982,11 +1147,124 @@ func Test_kms_DefaultApiService(t *testing.T) { } }) + t.Run("Test DefaultApiService RestoreKey", func(t *testing.T) { + _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/restore" + projectIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) + regionIdValue := "regionId-value" + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) + keyRingIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) + keyIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(keyIdValue, "keyId")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { + }) + 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 kms_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 := projectIdValue + regionId := regionIdValue + keyRingId := keyRingIdValue + keyId := keyIdValue + + reqErr := apiClient.RestoreKey(context.Background(), projectId, regionId, keyRingId, keyId).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", reqErr) + } + }) + + t.Run("Test DefaultApiService RestoreVersion", func(t *testing.T) { + _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/restore" + projectIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) + regionIdValue := "regionId-value" + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) + keyRingIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) + keyIdValue := uuid.NewString() + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyId"+"}", url.PathEscape(ParameterValueToString(keyIdValue, "keyId")), -1) + versionNumberValue := int64(123) + _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"versionNumber"+"}", url.PathEscape(ParameterValueToString(versionNumberValue, "versionNumber")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(_apiUrlPath, func(w http.ResponseWriter, req *http.Request) { + }) + 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 kms_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 := projectIdValue + regionId := regionIdValue + keyRingId := keyRingIdValue + keyId := keyIdValue + versionNumber := versionNumberValue + + reqErr := apiClient.RestoreVersion(context.Background(), projectId, regionId, keyRingId, keyId, versionNumber).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", reqErr) + } + }) + t.Run("Test DefaultApiService RotateKey", func(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/rotate" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -1047,7 +1325,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/sign" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) @@ -1112,7 +1390,7 @@ func Test_kms_DefaultApiService(t *testing.T) { _apiUrlPath := "/v1beta/projects/{projectId}/regions/{regionId}/keyrings/{keyRingId}/keys/{keyId}/versions/{versionNumber}/verify" projectIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"projectId"+"}", url.PathEscape(ParameterValueToString(projectIdValue, "projectId")), -1) - regionIdValue := "regionId" + regionIdValue := "regionId-value" _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"regionId"+"}", url.PathEscape(ParameterValueToString(regionIdValue, "regionId")), -1) keyRingIdValue := uuid.NewString() _apiUrlPath = strings.Replace(_apiUrlPath, "{"+"keyRingId"+"}", url.PathEscape(ParameterValueToString(keyRingIdValue, "keyRingId")), -1) diff --git a/services/kms/client.go b/services/kms/client.go index ba026a0cb..796a60ca8 100644 --- a/services/kms/client.go +++ b/services/kms/client.go @@ -66,10 +66,7 @@ func NewAPIClient(opts ...config.ConfigurationOption) (*APIClient, error) { } } - err := config.ConfigureRegion(cfg) - if err != nil { - return nil, fmt.Errorf("configuring region: %w", err) - } + // using new regional api, so no region is set here if cfg.HTTPClient == nil { cfg.HTTPClient = &http.Client{} @@ -308,7 +305,7 @@ func (c *APIClient) prepareRequest( var body *bytes.Buffer // Detect postBody type and post. - if postBody != nil { + if !IsNil(postBody) { contentType := headerParams["Content-Type"] if contentType == "" { contentType = detectContentType(postBody) diff --git a/services/kms/go.mod b/services/kms/go.mod index 843c3fa6d..56703ea84 100644 --- a/services/kms/go.mod +++ b/services/kms/go.mod @@ -3,6 +3,7 @@ module github.com/stackitcloud/stackit-sdk-go/services/kms go 1.21 require ( + github.com/google/go-cmp v0.7.0 github.com/google/uuid v1.6.0 github.com/stackitcloud/stackit-sdk-go/core v0.17.1 ) diff --git a/services/kms/model_key.go b/services/kms/model_key.go index b067ae42b..bfc09e481 100644 --- a/services/kms/model_key.go +++ b/services/kms/model_key.go @@ -78,6 +78,26 @@ func setKeyGetCreatedAtAttributeType(arg *KeyGetCreatedAtAttributeType, val KeyG *arg = &val } +/* + types and functions for deletionDate +*/ + +// isDateTime +type KeyGetDeletionDateAttributeType = *time.Time +type KeyGetDeletionDateArgType = time.Time +type KeyGetDeletionDateRetType = time.Time + +func getKeyGetDeletionDateAttributeTypeOk(arg KeyGetDeletionDateAttributeType) (ret KeyGetDeletionDateRetType, ok bool) { + if arg == nil { + return ret, false + } + return *arg, true +} + +func setKeyGetDeletionDateAttributeType(arg *KeyGetDeletionDateAttributeType, val KeyGetDeletionDateRetType) { + *arg = &val +} + /* types and functions for description */ @@ -231,6 +251,8 @@ type Key struct { // The date and time the creation of the key was triggered. // REQUIRED CreatedAt KeyGetCreatedAtAttributeType `json:"createdAt"` + // This date is set when a key is pending deletion and refers to the scheduled date of deletion + DeletionDate KeyGetDeletionDateAttributeType `json:"deletionDate,omitempty"` // A user chosen description to distinguish multiple keys. Description KeyGetDescriptionAttributeType `json:"description,omitempty"` // The display name to distinguish multiple keys. @@ -331,6 +353,29 @@ func (o *Key) SetCreatedAt(v KeyGetCreatedAtRetType) { setKeyGetCreatedAtAttributeType(&o.CreatedAt, v) } +// GetDeletionDate returns the DeletionDate field value if set, zero value otherwise. +func (o *Key) GetDeletionDate() (res KeyGetDeletionDateRetType) { + res, _ = o.GetDeletionDateOk() + return +} + +// GetDeletionDateOk returns a tuple with the DeletionDate field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Key) GetDeletionDateOk() (ret KeyGetDeletionDateRetType, ok bool) { + return getKeyGetDeletionDateAttributeTypeOk(o.DeletionDate) +} + +// HasDeletionDate returns a boolean if a field has been set. +func (o *Key) HasDeletionDate() bool { + _, ok := o.GetDeletionDateOk() + return ok +} + +// SetDeletionDate gets a reference to the given time.Time and assigns it to the DeletionDate field. +func (o *Key) SetDeletionDate(v KeyGetDeletionDateRetType) { + setKeyGetDeletionDateAttributeType(&o.DeletionDate, v) +} + // GetDescription returns the Description field value if set, zero value otherwise. func (o *Key) GetDescription() (res KeyGetDescriptionRetType) { res, _ = o.GetDescriptionOk() @@ -473,6 +518,9 @@ func (o Key) ToMap() (map[string]interface{}, error) { if val, ok := getKeyGetCreatedAtAttributeTypeOk(o.CreatedAt); ok { toSerialize["CreatedAt"] = val } + if val, ok := getKeyGetDeletionDateAttributeTypeOk(o.DeletionDate); ok { + toSerialize["DeletionDate"] = val + } if val, ok := getKeyGetDescriptionAttributeTypeOk(o.Description); ok { toSerialize["Description"] = val } diff --git a/services/kms/model_version.go b/services/kms/model_version.go index 87e0aea05..64dd596f1 100644 --- a/services/kms/model_version.go +++ b/services/kms/model_version.go @@ -38,6 +38,26 @@ func setVersionGetCreatedAtAttributeType(arg *VersionGetCreatedAtAttributeType, *arg = &val } +/* + types and functions for destroyDate +*/ + +// isDateTime +type VersionGetDestroyDateAttributeType = *time.Time +type VersionGetDestroyDateArgType = time.Time +type VersionGetDestroyDateRetType = time.Time + +func getVersionGetDestroyDateAttributeTypeOk(arg VersionGetDestroyDateAttributeType) (ret VersionGetDestroyDateRetType, ok bool) { + if arg == nil { + return ret, false + } + return *arg, true +} + +func setVersionGetDestroyDateAttributeType(arg *VersionGetDestroyDateAttributeType, val VersionGetDestroyDateRetType) { + *arg = &val +} + /* types and functions for disabled */ @@ -166,6 +186,8 @@ type Version struct { // The date and time the creation of the key was triggered. // REQUIRED CreatedAt VersionGetCreatedAtAttributeType `json:"createdAt"` + // The scheduled date when a version's key material will be erased completely from the backend + DestroyDate VersionGetDestroyDateAttributeType `json:"destroyDate,omitempty"` // States whether versions is enabled or disabled. Disabled VersiongetDisabledAttributeType `json:"disabled,omitempty"` // The unique id of the key this version is assigned to. @@ -227,6 +249,29 @@ func (o *Version) SetCreatedAt(v VersionGetCreatedAtRetType) { setVersionGetCreatedAtAttributeType(&o.CreatedAt, v) } +// GetDestroyDate returns the DestroyDate field value if set, zero value otherwise. +func (o *Version) GetDestroyDate() (res VersionGetDestroyDateRetType) { + res, _ = o.GetDestroyDateOk() + return +} + +// GetDestroyDateOk returns a tuple with the DestroyDate field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *Version) GetDestroyDateOk() (ret VersionGetDestroyDateRetType, ok bool) { + return getVersionGetDestroyDateAttributeTypeOk(o.DestroyDate) +} + +// HasDestroyDate returns a boolean if a field has been set. +func (o *Version) HasDestroyDate() bool { + _, ok := o.GetDestroyDateOk() + return ok +} + +// SetDestroyDate gets a reference to the given time.Time and assigns it to the DestroyDate field. +func (o *Version) SetDestroyDate(v VersionGetDestroyDateRetType) { + setVersionGetDestroyDateAttributeType(&o.DestroyDate, v) +} + // GetDisabled returns the Disabled field value if set, zero value otherwise. func (o *Version) GetDisabled() (res VersiongetDisabledRetType) { res, _ = o.GetDisabledOk() @@ -346,6 +391,9 @@ func (o Version) ToMap() (map[string]interface{}, error) { if val, ok := getVersionGetCreatedAtAttributeTypeOk(o.CreatedAt); ok { toSerialize["CreatedAt"] = val } + if val, ok := getVersionGetDestroyDateAttributeTypeOk(o.DestroyDate); ok { + toSerialize["DestroyDate"] = val + } if val, ok := getVersiongetDisabledAttributeTypeOk(o.Disabled); ok { toSerialize["Disabled"] = val } diff --git a/services/kms/wait/wait.go b/services/kms/wait/wait.go new file mode 100644 index 000000000..c8cf02e08 --- /dev/null +++ b/services/kms/wait/wait.go @@ -0,0 +1,147 @@ +package wait + +import ( + "context" + "errors" + "net/http" + "time" + + "github.com/stackitcloud/stackit-sdk-go/core/oapierror" + "github.com/stackitcloud/stackit-sdk-go/core/wait" + "github.com/stackitcloud/stackit-sdk-go/services/kms" +) + +const ( + StatusKeyActive = "active" + StatusKeyNotReady = "version_not_ready" + StatusKeyDeleted = "deleted" +) + +const ( + StatusKeyVersionActive = "active" + StatusKeyVersionKeyMaterialNotReady = "key_material_not_ready" + StatusKeyVersionKeyMaterialInvalid = "key_material_invalid" + StatusKeyVersionDisabled = "disabled" + StatusKeyVersionDestroyed = "destroyed" +) + +const ( + StatusWrappingKeyActive = "active" + StatusWrappingKeyKeyMaterialNotReady = "key_material_not_ready" + StatusWrappingKeyExpired = "expired" + StatusWrappingKeyDeleting = "deleting" +) + +type ApiKmsClient interface { + GetKeyExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string) (*kms.Key, error) + GetVersionExecute(ctx context.Context, projectId string, regionId string, keyRingId string, keyId string, versionNumber int64) (*kms.Version, error) + GetWrappingKeyExecute(ctx context.Context, projectId string, regionId string, keyRingId string, wrappingKeyId string) (*kms.WrappingKey, error) +} + +func CreateOrUpdateKeyWaitHandler(ctx context.Context, client ApiKmsClient, projectId, region, keyRingId, keyId string) *wait.AsyncActionHandler[kms.Key] { + handler := wait.New(func() (bool, *kms.Key, error) { + response, err := client.GetKeyExecute(ctx, projectId, region, keyRingId, keyId) + if err != nil { + return false, nil, err + } + + if response.State != nil { + switch *response.State { + case StatusKeyNotReady: + return false, nil, nil + default: + return true, response, nil + } + } + + return false, nil, nil + }) + handler.SetTimeout(10 * time.Minute) + return handler +} + +func DeleteKeyWaitHandler(ctx context.Context, client ApiKmsClient, projectId, region, keyRingId, keyId string) *wait.AsyncActionHandler[kms.Key] { + handler := wait.New(func() (bool, *kms.Key, error) { + _, err := client.GetKeyExecute(ctx, projectId, region, keyRingId, keyId) + if err != nil { + var apiErr *oapierror.GenericOpenAPIError + if errors.As(err, &apiErr) { + if statusCode := apiErr.StatusCode; statusCode == http.StatusNotFound || statusCode == http.StatusGone { + return true, nil, nil + } + } + return true, nil, err + } + return false, nil, nil + }) + handler.SetTimeout(10 * time.Minute) + return handler +} + +func EnableKeyVersionWaitHandler(ctx context.Context, client ApiKmsClient, projectId, region, keyRingId, keyId string, version int64) *wait.AsyncActionHandler[kms.Version] { + handler := wait.New(func() (bool, *kms.Version, error) { + response, err := client.GetVersionExecute(ctx, projectId, region, keyRingId, keyId, version) + if err != nil { + return false, nil, err + } + + if response.State != nil { + switch *response.State { + case StatusKeyVersionDestroyed: + return true, response, nil + case StatusKeyVersionKeyMaterialInvalid: + return true, response, nil + case StatusKeyVersionDisabled: + return true, response, nil + case StatusKeyVersionKeyMaterialNotReady: + return false, nil, nil + default: + return true, response, nil + } + } + + return false, nil, nil + }) + handler.SetTimeout(10 * time.Minute) + return handler +} + +func DisableKeyVersionWaitHandler(ctx context.Context, client ApiKmsClient, projectId, region, keyRingId, keyId string, version int64) *wait.AsyncActionHandler[kms.Version] { + handler := wait.New(func() (bool, *kms.Version, error) { + _, err := client.GetVersionExecute(ctx, projectId, region, keyRingId, keyId, version) + if err != nil { + var apiErr *oapierror.GenericOpenAPIError + if errors.As(err, &apiErr) { + if statusCode := apiErr.StatusCode; statusCode == http.StatusNotFound || statusCode == http.StatusGone { + return true, nil, nil + } + } + return true, nil, err + } + return false, nil, nil + }) + handler.SetTimeout(10 * time.Minute) + return handler +} + +func CreateWrappingKeyWaitHandler(ctx context.Context, client ApiKmsClient, projectId, region, keyRingId, wrappingKeyId string) *wait.AsyncActionHandler[kms.WrappingKey] { + handler := wait.New(func() (bool, *kms.WrappingKey, error) { + response, err := client.GetWrappingKeyExecute(ctx, projectId, region, keyRingId, wrappingKeyId) + if err != nil { + return false, nil, err + } + + if state := response.State; state != nil { + switch *state { + case StatusWrappingKeyKeyMaterialNotReady: + return false, nil, nil + default: + return true, response, nil + } + } + + return false, nil, nil + }) + handler.SetTimeout(10 * time.Minute) + return handler +} diff --git a/services/kms/wait/wait_test.go b/services/kms/wait/wait_test.go new file mode 100644 index 000000000..d4bf5feca --- /dev/null +++ b/services/kms/wait/wait_test.go @@ -0,0 +1,525 @@ +package wait + +import ( + "context" + "errors" + "net/http" + "testing" + "time" + + "github.com/google/go-cmp/cmp" + "github.com/google/uuid" + "github.com/stackitcloud/stackit-sdk-go/core/oapierror" + "github.com/stackitcloud/stackit-sdk-go/core/utils" + "github.com/stackitcloud/stackit-sdk-go/services/kms" +) + +var ( + testProject = uuid.NewString() + testRegion = "eu01" + testDate = time.Now() + testKeyRingId = uuid.NewString() + testKeyId = uuid.NewString() + testPublicKey = "i am an invalid public key" +) + +var _ ApiKmsClient = (*apiKmsMocked)(nil) + +type keyResponse struct { + key *kms.Key + err error +} + +type versionResponse struct { + version *kms.Version + err error +} + +type wrappingKeyResponse struct { + wrappingKey *kms.WrappingKey + err error +} + +type apiKmsMocked struct { + idxKeyResponse int + idxVersionResponse int + idxWrappingKeyResponse int + keyResponses []keyResponse + versionResponses []versionResponse + wrappingKeyResponses []wrappingKeyResponse +} + +// GetWrappingKeyExecute implements ApiKmsClient. +func (a *apiKmsMocked) GetWrappingKeyExecute(_ context.Context, _, _, _, _ string) (*kms.WrappingKey, error) { + resp := a.wrappingKeyResponses[a.idxWrappingKeyResponse] + a.idxWrappingKeyResponse++ + a.idxWrappingKeyResponse %= len(a.wrappingKeyResponses) + return resp.wrappingKey, resp.err +} + +// GetVersionExecute implements ApiKmsClient. +func (a *apiKmsMocked) GetVersionExecute(_ context.Context, _, _, _, _ string, _ int64) (*kms.Version, error) { + resp := a.versionResponses[a.idxVersionResponse] + a.idxVersionResponse++ + a.idxVersionResponse %= len(a.versionResponses) + return resp.version, resp.err +} + +// GetKeyExecute implements ApiKmsClient. +func (a *apiKmsMocked) GetKeyExecute(_ context.Context, _, _, _, _ string) (*kms.Key, error) { + resp := a.keyResponses[a.idxKeyResponse] + a.idxKeyResponse++ + a.idxKeyResponse %= len(a.keyResponses) + return resp.key, resp.err +} + +func fixtureKey(state string) *kms.Key { + return &kms.Key{ + Algorithm: kms.ALGORITHM_AES_256_GCM.Ptr(), + Backend: kms.BACKEND_SOFTWARE.Ptr(), + CreatedAt: &testDate, + DeletionDate: &testDate, + Description: utils.Ptr("test-description"), + DisplayName: utils.Ptr("test-displayname"), + Id: &testKeyId, + ImportOnly: utils.Ptr(false), + KeyRingId: &testKeyRingId, + Purpose: kms.PURPOSE_SYMMETRIC_ENCRYPT_DECRYPT.Ptr(), + State: &state, + } +} + +func fixtureWrappingKey(state string) *kms.WrappingKey { + return &kms.WrappingKey{ + Algorithm: kms.WRAPPINGALGORITHM__2048_OAEP_SHA256.Ptr(), + Backend: kms.BACKEND_SOFTWARE.Ptr(), + CreatedAt: &testDate, + Description: utils.Ptr("test-description"), + DisplayName: utils.Ptr("test-displayname"), + Id: &testKeyId, + KeyRingId: &testKeyRingId, + Purpose: kms.WRAPPINGPURPOSE_SYMMETRIC_KEY.Ptr(), + State: &state, + ExpiresAt: &testDate, + PublicKey: &testPublicKey, + } +} + +func fixtureVersion(version int, disabled bool, state string) *kms.Version { + return &kms.Version{ + CreatedAt: &testDate, + DestroyDate: &testDate, + Disabled: &disabled, + KeyId: &testKeyId, + KeyRingId: &testKeyRingId, + Number: utils.Ptr(int64(version)), + PublicKey: &testPublicKey, + State: &state, + } +} + +func TestCreateOrUpdateKeyWaitHandler(t *testing.T) { + tests := []struct { + name string + responses []keyResponse + want *kms.Key + wantErr bool + }{ + { + "create succeeded immediately", + []keyResponse{ + {fixtureKey(StatusKeyActive), nil}, + }, + fixtureKey(StatusKeyActive), + false, + }, + { + "create succeeded delayed", + []keyResponse{ + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyActive), nil}, + }, + fixtureKey(StatusKeyActive), + false, + }, + { + "create failed delayed", + []keyResponse{ + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyDeleted), nil}, + }, + fixtureKey(StatusKeyDeleted), + false, + }, + { + "timeout", + []keyResponse{ + {fixtureKey(StatusKeyNotReady), nil}, + }, + nil, + true, + }, + { + "broken state", + []keyResponse{ + {fixtureKey("bogus"), nil}, + }, + fixtureKey("bogus"), + false, + }, + // no special update tests needed as the states are the same + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ctx := context.Background() + client := &apiKmsMocked{ + keyResponses: tt.responses, + } + + handler := CreateOrUpdateKeyWaitHandler(ctx, client, testProject, testRegion, testKeyRingId, testKeyId) + got, err := handler.SetTimeout(1 * time.Second). + SetThrottle(250 * time.Millisecond). + WaitWithContext(ctx) + + if (err != nil) != tt.wantErr { + t.Fatalf("unexpected error response. want %v but got %v ", tt.wantErr, err) + } + + if diff := cmp.Diff(tt.want, got); diff != "" { + t.Errorf("differing key %s", diff) + } + }) + } +} + +func TestDeleteKeyWaitHandler(t *testing.T) { + tests := []struct { + name string + responses []keyResponse + wantErr bool + }{ + { + "Delete with '404' succeeded immediately", + []keyResponse{ + {nil, oapierror.NewError(http.StatusNotFound, "not found")}, + }, + false, + }, + { + "Delete with '404' delayed", + []keyResponse{ + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyNotReady), nil}, + {nil, oapierror.NewError(http.StatusNotFound, "not found")}, + }, + false, + }, + { + "Delete with 'gone' succeeded immediately", + []keyResponse{ + {nil, oapierror.NewError(http.StatusGone, "gone")}, + }, + false, + }, + { + "Delete with 'gone' delayed", + []keyResponse{ + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyNotReady), nil}, + {nil, oapierror.NewError(http.StatusGone, "not found")}, + }, + false, + }, + { + "Delete with error delayed", + []keyResponse{ + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyNotReady), nil}, + + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyDeleted), oapierror.NewError(http.StatusInternalServerError, "kapow")}, + }, + true, + }, + { + "Cannot delete", + []keyResponse{ + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyNotReady), nil}, + {fixtureKey(StatusKeyDeleted), oapierror.NewError(http.StatusOK, "ok")}, + }, + true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ctx := context.Background() + client := &apiKmsMocked{ + keyResponses: tt.responses, + } + handler := DeleteKeyWaitHandler(ctx, client, testProject, testRegion, testKeyRingId, testKeyId) + _, err := handler.SetTimeout(1 * time.Second). + SetThrottle(250 * time.Millisecond). + WaitWithContext(ctx) + + if tt.wantErr != (err != nil) { + t.Fatalf("wrong error result. want err: %v got %v", tt.wantErr, err) + } + if tt.wantErr { + var apiErr *oapierror.GenericOpenAPIError + if !errors.As(err, &apiErr) { + t.Fatalf("expected openapi error, got %v", err) + } + } + }) + } +} + +func TestEnableKeyVersionWaitHandler(t *testing.T) { + tests := []struct { + name string + responses []versionResponse + want *kms.Version + wantErr bool + }{ + { + "create succeeded immediately", + []versionResponse{ + {fixtureVersion(1, false, StatusKeyVersionActive), nil}, + }, + fixtureVersion(1, false, StatusKeyVersionActive), + false, + }, + { + "create succeeded delayed", + []versionResponse{ + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionActive), nil}, + }, + fixtureVersion(1, false, StatusKeyVersionActive), + false, + }, + { + "create failed delayed", + []versionResponse{ + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialInvalid), nil}, + }, + fixtureVersion(1, false, StatusKeyVersionKeyMaterialInvalid), + false, + }, + { + "timeout", + []versionResponse{ + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + }, + nil, + true, + }, + { + "broken state", + []versionResponse{ + {fixtureVersion(1, false, "bogus"), nil}, + }, + fixtureVersion(1, false, "bogus"), + false, + }, + // no special update tests needed as the states are the same + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ctx := context.Background() + client := &apiKmsMocked{ + versionResponses: tt.responses, + } + + handler := EnableKeyVersionWaitHandler(ctx, client, testProject, testRegion, testKeyRingId, testKeyId, 1) + got, err := handler.SetTimeout(1 * time.Second). + SetThrottle(250 * time.Millisecond). + WaitWithContext(ctx) + + if (err != nil) != tt.wantErr { + t.Fatalf("unexpected error response. want %v but got %v ", tt.wantErr, err) + } + + if diff := cmp.Diff(tt.want, got); diff != "" { + t.Errorf("differing key %s", diff) + } + }) + } +} + +func TestDisableKeyVersionWaitHandler(t *testing.T) { + tests := []struct { + name string + responses []versionResponse + wantErr bool + }{ + { + "Delete with '404' succeeded immediately", + []versionResponse{ + {nil, oapierror.NewError(http.StatusNotFound, "not found")}, + }, + false, + }, + { + "Delete with '404' delayed", + []versionResponse{ + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {nil, oapierror.NewError(http.StatusNotFound, "not found")}, + }, + false, + }, + { + "Delete with 'gone' succeeded immediately", + []versionResponse{ + {nil, oapierror.NewError(http.StatusGone, "gone")}, + }, + false, + }, + { + "Delete with 'gone' delayed", + []versionResponse{ + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {nil, oapierror.NewError(http.StatusGone, "not found")}, + }, + false, + }, + { + "Delete with error delayed", + []versionResponse{ + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionDestroyed), oapierror.NewError(http.StatusInternalServerError, "kapow")}, + }, + true, + }, + { + "Cannot delete", + []versionResponse{ + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionKeyMaterialNotReady), nil}, + {fixtureVersion(1, false, StatusKeyVersionDestroyed), oapierror.NewError(http.StatusOK, "ok")}, + }, + true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ctx := context.Background() + client := &apiKmsMocked{ + versionResponses: tt.responses, + } + handler := DisableKeyVersionWaitHandler(ctx, client, testProject, testRegion, testKeyRingId, testKeyId, 1) + _, err := handler.SetTimeout(1 * time.Second). + SetThrottle(250 * time.Millisecond). + WaitWithContext(ctx) + + if tt.wantErr != (err != nil) { + t.Fatalf("wrong error result. want err: %v got %v", tt.wantErr, err) + } + if tt.wantErr { + var apiErr *oapierror.GenericOpenAPIError + if !errors.As(err, &apiErr) { + t.Fatalf("expected openapi error, got %v", err) + } + } + }) + } +} + +func TestCreateWrappingWaitHandler(t *testing.T) { + tests := []struct { + name string + responses []wrappingKeyResponse + want *kms.WrappingKey + wantErr bool + }{ + { + "create succeeded immediately", + []wrappingKeyResponse{ + {fixtureWrappingKey(StatusWrappingKeyActive), nil}, + }, + fixtureWrappingKey(StatusWrappingKeyActive), + false, + }, + { + "create succeeded delayed", + []wrappingKeyResponse{ + {fixtureWrappingKey(StatusWrappingKeyKeyMaterialNotReady), nil}, + {fixtureWrappingKey(StatusWrappingKeyKeyMaterialNotReady), nil}, + {fixtureWrappingKey(StatusWrappingKeyKeyMaterialNotReady), nil}, + {fixtureWrappingKey(StatusWrappingKeyActive), nil}, + }, + fixtureWrappingKey(StatusWrappingKeyActive), + false, + }, + { + "create failed delayed", + []wrappingKeyResponse{ + {fixtureWrappingKey(StatusWrappingKeyKeyMaterialNotReady), nil}, + {fixtureWrappingKey(StatusWrappingKeyKeyMaterialNotReady), nil}, + {fixtureWrappingKey(StatusWrappingKeyKeyMaterialNotReady), nil}, + {fixtureWrappingKey(StatusWrappingKeyDeleting), nil}, + }, + fixtureWrappingKey(StatusWrappingKeyDeleting), + false, + }, + { + "timeout", + []wrappingKeyResponse{ + {fixtureWrappingKey(StatusWrappingKeyKeyMaterialNotReady), nil}, + }, + nil, + true, + }, + { + "broken state", + []wrappingKeyResponse{ + {fixtureWrappingKey("bogus"), nil}, + }, + fixtureWrappingKey("bogus"), + false, + }, + // no special update tests needed as the states are the same + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ctx := context.Background() + client := &apiKmsMocked{ + wrappingKeyResponses: tt.responses, + } + + handler := CreateWrappingKeyWaitHandler(ctx, client, testProject, testRegion, testKeyRingId, testKeyId) + got, err := handler.SetTimeout(1 * time.Second). + SetThrottle(250 * time.Millisecond). + WaitWithContext(ctx) + + if (err != nil) != tt.wantErr { + t.Fatalf("unexpected error response. want %v but got %v ", tt.wantErr, err) + } + + if diff := cmp.Diff(tt.want, got); diff != "" { + t.Errorf("differing key %s", diff) + } + }) + } +}