diff --git a/CHANGELOG.md b/CHANGELOG.md index 630b36089..f17703c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +## Release (2024-02-07) + +> The `membership` module has been replaced with the `authorization` module, which connects to the same API. +> +> **This module will receive no further updates.** Use `github.com/stackitcloud/stackit-sdk-go/services/authorization` instead. + +## Highlights + +- `authorization`: [v0.1.0](services/authorization/CHANGELOG.md#v010-2024-02-07) + - First release. This module offers the same functionalities as `membership` (release v0.4.0). +- `membership`: [v0.4.0](services/membership/CHANGELOG.md#v040-2024-02-07) + - Add deprecation note + ## Release (2024-02-06) > **The STACKIT PostgreSQL service will reach its end of support on June 30th 2024. All calls done to the API after that will stop working.** diff --git a/go.work b/go.work index c49dcde54..1de42a656 100644 --- a/go.work +++ b/go.work @@ -25,6 +25,7 @@ use ( ./examples/ske ./examples/waiter ./services/argus + ./services/authorization ./services/dns ./services/loadbalancer ./services/logme diff --git a/services/authorization/.openapi-generator/VERSION b/services/authorization/.openapi-generator/VERSION new file mode 100644 index 000000000..cd802a1ec --- /dev/null +++ b/services/authorization/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.6.0 \ No newline at end of file diff --git a/services/authorization/CHANGELOG.md b/services/authorization/CHANGELOG.md new file mode 100644 index 000000000..6bccebe05 --- /dev/null +++ b/services/authorization/CHANGELOG.md @@ -0,0 +1,5 @@ +## v0.1.0 (2024-02-07) + +First release. + +This module offers the same functionalities as `membership` (release v0.4.0). diff --git a/services/authorization/LICENSE.md b/services/authorization/LICENSE.md new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/services/authorization/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 [yyyy] [name of copyright owner] + + 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/authorization/NOTICE.txt b/services/authorization/NOTICE.txt new file mode 100644 index 000000000..aa8833526 --- /dev/null +++ b/services/authorization/NOTICE.txt @@ -0,0 +1,2 @@ +STACKIT Authorization SDK for Go +Copyright 2023 Schwarz IT GmBH & Co. KG \ No newline at end of file diff --git a/services/authorization/api_default.go b/services/authorization/api_default.go new file mode 100644 index 000000000..83fe2a78c --- /dev/null +++ b/services/authorization/api_default.go @@ -0,0 +1,963 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +import ( + "bytes" + "context" + "fmt" + "io" + "net/http" + "net/url" + "strings" + + "github.com/stackitcloud/stackit-sdk-go/core/config" + "github.com/stackitcloud/stackit-sdk-go/core/oapierror" +) + +// DefaultApiService DefaultApi service +type DefaultApiService service + +type ApiAddMembersRequest struct { + ctx context.Context + apiService *DefaultApiService + resourceId string + addMembersPayload *AddMembersPayload +} + +func (r ApiAddMembersRequest) AddMembersPayload(addMembersPayload AddMembersPayload) ApiAddMembersRequest { + r.addMembersPayload = &addMembersPayload + return r +} + +func (r ApiAddMembersRequest) Execute() (*MembersResponse, error) { + var ( + localVarHTTPMethod = http.MethodPatch + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *MembersResponse + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.AddMembers") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v2/{resourceId}/members" + localVarPath = strings.Replace(localVarPath, "{"+"resourceId"+"}", url.PathEscape(ParameterValueToString(r.resourceId, "resourceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.addMembersPayload == nil { + return localVarReturnValue, fmt.Errorf("addMembersPayload 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.addMembersPayload + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, err + } + + 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 ErrorResponse + 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 ErrorResponse + 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 == 403 { + var v ErrorResponse + 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 +} + +/* +AddMembers Add members to a resource + +Add members to the given resource with specified roles. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param resourceId + @return ApiAddMembersRequest +*/ +func (a *APIClient) AddMembers(ctx context.Context, resourceId string) ApiAddMembersRequest { + return ApiAddMembersRequest{ + apiService: a.defaultApi, + ctx: ctx, + resourceId: resourceId, + } +} + +func (a *APIClient) AddMembersExecute(ctx context.Context, resourceId string) (*MembersResponse, error) { + r := ApiAddMembersRequest{ + apiService: a.defaultApi, + ctx: ctx, + resourceId: resourceId, + } + return r.Execute() +} + +type ApiListMembersRequest struct { + ctx context.Context + apiService *DefaultApiService + resourceType string + resourceId string + subject *string +} + +func (r ApiListMembersRequest) Subject(subject string) ApiListMembersRequest { + r.subject = &subject + return r +} + +func (r ApiListMembersRequest) Execute() (*ListMembersResponse, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ListMembersResponse + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListMembers") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v2/{resourceType}/{resourceId}/members" + localVarPath = strings.Replace(localVarPath, "{"+"resourceType"+"}", url.PathEscape(ParameterValueToString(r.resourceType, "resourceType")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"resourceId"+"}", url.PathEscape(ParameterValueToString(r.resourceId, "resourceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.subject != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "subject", r.subject, "") + } + // 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 + } + + 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 ErrorResponse + 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 ErrorResponse + 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 == 403 { + var v ErrorResponse + 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 +} + +/* +ListMembers Get members to a resource + +List members of the given resource. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param resourceType + @param resourceId + @return ApiListMembersRequest +*/ +func (a *APIClient) ListMembers(ctx context.Context, resourceType string, resourceId string) ApiListMembersRequest { + return ApiListMembersRequest{ + apiService: a.defaultApi, + ctx: ctx, + resourceType: resourceType, + resourceId: resourceId, + } +} + +func (a *APIClient) ListMembersExecute(ctx context.Context, resourceType string, resourceId string) (*ListMembersResponse, error) { + r := ApiListMembersRequest{ + apiService: a.defaultApi, + ctx: ctx, + resourceType: resourceType, + resourceId: resourceId, + } + return r.Execute() +} + +type ApiListPermissionsRequest struct { + ctx context.Context + apiService *DefaultApiService + resourceType *string +} + +func (r ApiListPermissionsRequest) ResourceType(resourceType string) ApiListPermissionsRequest { + r.resourceType = &resourceType + return r +} + +func (r ApiListPermissionsRequest) Execute() (*ListPermissionsResponse, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ListPermissionsResponse + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListPermissions") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v2/permissions" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.resourceType != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "resourceType", r.resourceType, "") + } + // 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 + } + + 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 ErrorResponse + 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 ErrorResponse + 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 == 403 { + var v ErrorResponse + 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 +} + +/* +ListPermissions Get available permissions + +Get available permissions + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiListPermissionsRequest +*/ +func (a *APIClient) ListPermissions(ctx context.Context) ApiListPermissionsRequest { + return ApiListPermissionsRequest{ + apiService: a.defaultApi, + ctx: ctx, + } +} + +func (a *APIClient) ListPermissionsExecute(ctx context.Context) (*ListPermissionsResponse, error) { + r := ApiListPermissionsRequest{ + apiService: a.defaultApi, + ctx: ctx, + } + return r.Execute() +} + +type ApiListRolesRequest struct { + ctx context.Context + apiService *DefaultApiService + resourceType string + resourceId string +} + +func (r ApiListRolesRequest) Execute() (*RolesResponse, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *RolesResponse + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListRoles") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v2/{resourceType}/{resourceId}/roles" + localVarPath = strings.Replace(localVarPath, "{"+"resourceType"+"}", url.PathEscape(ParameterValueToString(r.resourceType, "resourceType")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"resourceId"+"}", url.PathEscape(ParameterValueToString(r.resourceId, "resourceId")), -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 + } + + 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 ErrorResponse + 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 ErrorResponse + 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 == 403 { + var v ErrorResponse + 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 +} + +/* +ListRoles Get roles and permissions of a resource + +Get roles and permissions of a resource + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param resourceType + @param resourceId + @return ApiListRolesRequest +*/ +func (a *APIClient) ListRoles(ctx context.Context, resourceType string, resourceId string) ApiListRolesRequest { + return ApiListRolesRequest{ + apiService: a.defaultApi, + ctx: ctx, + resourceType: resourceType, + resourceId: resourceId, + } +} + +func (a *APIClient) ListRolesExecute(ctx context.Context, resourceType string, resourceId string) (*RolesResponse, error) { + r := ApiListRolesRequest{ + apiService: a.defaultApi, + ctx: ctx, + resourceType: resourceType, + resourceId: resourceId, + } + return r.Execute() +} + +type ApiListUserMembershipsRequest struct { + ctx context.Context + apiService *DefaultApiService + email string + resourceType *string + resourceId *string + parentResourceId *string +} + +func (r ApiListUserMembershipsRequest) ResourceType(resourceType string) ApiListUserMembershipsRequest { + r.resourceType = &resourceType + return r +} + +func (r ApiListUserMembershipsRequest) ResourceId(resourceId string) ApiListUserMembershipsRequest { + r.resourceId = &resourceId + return r +} + +func (r ApiListUserMembershipsRequest) ParentResourceId(parentResourceId string) ApiListUserMembershipsRequest { + r.parentResourceId = &parentResourceId + return r +} + +func (r ApiListUserMembershipsRequest) Execute() (*ListUserMembershipsResponse, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *ListUserMembershipsResponse + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.ListUserMemberships") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v2/users/{email}/memberships" + localVarPath = strings.Replace(localVarPath, "{"+"email"+"}", url.PathEscape(ParameterValueToString(r.email, "email")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.resourceType != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "resourceType", r.resourceType, "") + } + if r.resourceId != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "resourceId", r.resourceId, "") + } + if r.parentResourceId != nil { + parameterAddToHeaderOrQuery(localVarQueryParams, "parentResourceId", r.parentResourceId, "") + } + // 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 + } + + 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 ErrorResponse + 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 ErrorResponse + 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 == 403 { + var v ErrorResponse + 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 +} + +/* +ListUserMemberships List memberships of a user + +List memberships of a user. An administrative access is needed to list any user's memberships, while the user can do it on his/her own email. You can use filters to scope the request to a project/folder/organization. In this case -if caller is not the subject-, owner permissions are required. Because of hierarchical role bindings, the user might have permissions on more resources. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param email + @return ApiListUserMembershipsRequest +*/ +func (a *APIClient) ListUserMemberships(ctx context.Context, email string) ApiListUserMembershipsRequest { + return ApiListUserMembershipsRequest{ + apiService: a.defaultApi, + ctx: ctx, + email: email, + } +} + +func (a *APIClient) ListUserMembershipsExecute(ctx context.Context, email string) (*ListUserMembershipsResponse, error) { + r := ApiListUserMembershipsRequest{ + apiService: a.defaultApi, + ctx: ctx, + email: email, + } + return r.Execute() +} + +type ApiRemoveMembersRequest struct { + ctx context.Context + apiService *DefaultApiService + resourceId string + removeMembersPayload *RemoveMembersPayload +} + +func (r ApiRemoveMembersRequest) RemoveMembersPayload(removeMembersPayload RemoveMembersPayload) ApiRemoveMembersRequest { + r.removeMembersPayload = &removeMembersPayload + return r +} + +func (r ApiRemoveMembersRequest) Execute() (*MembersResponse, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue *MembersResponse + ) + a := r.apiService + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultApiService.RemoveMembers") + if err != nil { + return localVarReturnValue, &oapierror.GenericOpenAPIError{ErrorMessage: err.Error()} + } + + localVarPath := localBasePath + "/v2/{resourceId}/members/remove" + localVarPath = strings.Replace(localVarPath, "{"+"resourceId"+"}", url.PathEscape(ParameterValueToString(r.resourceId, "resourceId")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + if r.removeMembersPayload == nil { + return localVarReturnValue, fmt.Errorf("removeMembersPayload 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.removeMembersPayload + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, err + } + + 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 ErrorResponse + 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 ErrorResponse + 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 == 403 { + var v ErrorResponse + 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 +} + +/* +RemoveMembers Remove members from a resource + +Remove members from the given resource with specified roles. + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param resourceId + @return ApiRemoveMembersRequest +*/ +func (a *APIClient) RemoveMembers(ctx context.Context, resourceId string) ApiRemoveMembersRequest { + return ApiRemoveMembersRequest{ + apiService: a.defaultApi, + ctx: ctx, + resourceId: resourceId, + } +} + +func (a *APIClient) RemoveMembersExecute(ctx context.Context, resourceId string) (*MembersResponse, error) { + r := ApiRemoveMembersRequest{ + apiService: a.defaultApi, + ctx: ctx, + resourceId: resourceId, + } + return r.Execute() +} diff --git a/services/authorization/api_default_test.go b/services/authorization/api_default_test.go new file mode 100644 index 000000000..3fa9986f1 --- /dev/null +++ b/services/authorization/api_default_test.go @@ -0,0 +1,342 @@ +/* +STACKIT Membership API + +Testing DefaultApiService + +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); + +package authorization + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "net/url" + "strings" + "testing" + + "github.com/stackitcloud/stackit-sdk-go/core/config" +) + +func Test_authorization_DefaultApiService(t *testing.T) { + + t.Run("Test DefaultApiService AddMembers", func(t *testing.T) { + path := "/v2/{resourceId}/members" + resourceIdValue := "resourceId" + path = strings.Replace(path, "{"+"resourceId"+"}", url.PathEscape(ParameterValueToString(resourceIdValue, "resourceId")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(path, func(w http.ResponseWriter, req *http.Request) { + data := MembersResponse{} + w.Header().Add("Content-Type", "application/json") + json.NewEncoder(w).Encode(data) + }) + testServer := httptest.NewServer(testDefaultApiServeMux) + defer testServer.Close() + + configuration := &config.Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Region: "test_region", + Servers: config.ServerConfigurations{ + { + URL: testServer.URL, + Description: "Localhost for authorization_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) + } + + resourceId := "resourceId" + addMembersPayload := AddMembersPayload{} + + resp, reqErr := apiClient.AddMembers(context.Background(), resourceId).AddMembersPayload(addMembersPayload).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", err) + } + if resp == nil { + t.Fatalf("response not present") + } + }) + + t.Run("Test DefaultApiService ListMembers", func(t *testing.T) { + path := "/v2/{resourceType}/{resourceId}/members" + resourceTypeValue := "resourceType" + path = strings.Replace(path, "{"+"resourceType"+"}", url.PathEscape(ParameterValueToString(resourceTypeValue, "resourceType")), -1) + resourceIdValue := "resourceId" + path = strings.Replace(path, "{"+"resourceId"+"}", url.PathEscape(ParameterValueToString(resourceIdValue, "resourceId")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(path, func(w http.ResponseWriter, req *http.Request) { + data := ListMembersResponse{} + w.Header().Add("Content-Type", "application/json") + json.NewEncoder(w).Encode(data) + }) + testServer := httptest.NewServer(testDefaultApiServeMux) + defer testServer.Close() + + configuration := &config.Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Region: "test_region", + Servers: config.ServerConfigurations{ + { + URL: testServer.URL, + Description: "Localhost for authorization_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) + } + + resourceType := "resourceType" + resourceId := "resourceId" + + resp, reqErr := apiClient.ListMembers(context.Background(), resourceType, resourceId).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", err) + } + if resp == nil { + t.Fatalf("response not present") + } + }) + + t.Run("Test DefaultApiService ListPermissions", func(t *testing.T) { + path := "/v2/permissions" + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(path, func(w http.ResponseWriter, req *http.Request) { + data := ListPermissionsResponse{} + w.Header().Add("Content-Type", "application/json") + json.NewEncoder(w).Encode(data) + }) + testServer := httptest.NewServer(testDefaultApiServeMux) + defer testServer.Close() + + configuration := &config.Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Region: "test_region", + Servers: config.ServerConfigurations{ + { + URL: testServer.URL, + Description: "Localhost for authorization_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) + } + + resp, reqErr := apiClient.ListPermissions(context.Background()).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", err) + } + if resp == nil { + t.Fatalf("response not present") + } + }) + + t.Run("Test DefaultApiService ListRoles", func(t *testing.T) { + path := "/v2/{resourceType}/{resourceId}/roles" + resourceTypeValue := "resourceType" + path = strings.Replace(path, "{"+"resourceType"+"}", url.PathEscape(ParameterValueToString(resourceTypeValue, "resourceType")), -1) + resourceIdValue := "resourceId" + path = strings.Replace(path, "{"+"resourceId"+"}", url.PathEscape(ParameterValueToString(resourceIdValue, "resourceId")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(path, func(w http.ResponseWriter, req *http.Request) { + data := RolesResponse{} + w.Header().Add("Content-Type", "application/json") + json.NewEncoder(w).Encode(data) + }) + testServer := httptest.NewServer(testDefaultApiServeMux) + defer testServer.Close() + + configuration := &config.Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Region: "test_region", + Servers: config.ServerConfigurations{ + { + URL: testServer.URL, + Description: "Localhost for authorization_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) + } + + resourceType := "resourceType" + resourceId := "resourceId" + + resp, reqErr := apiClient.ListRoles(context.Background(), resourceType, resourceId).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", err) + } + if resp == nil { + t.Fatalf("response not present") + } + }) + + t.Run("Test DefaultApiService ListUserMemberships", func(t *testing.T) { + path := "/v2/users/{email}/memberships" + emailValue := "email" + path = strings.Replace(path, "{"+"email"+"}", url.PathEscape(ParameterValueToString(emailValue, "email")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(path, func(w http.ResponseWriter, req *http.Request) { + data := ListUserMembershipsResponse{} + w.Header().Add("Content-Type", "application/json") + json.NewEncoder(w).Encode(data) + }) + testServer := httptest.NewServer(testDefaultApiServeMux) + defer testServer.Close() + + configuration := &config.Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Region: "test_region", + Servers: config.ServerConfigurations{ + { + URL: testServer.URL, + Description: "Localhost for authorization_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) + } + + email := "email" + + resp, reqErr := apiClient.ListUserMemberships(context.Background(), email).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", err) + } + if resp == nil { + t.Fatalf("response not present") + } + }) + + t.Run("Test DefaultApiService RemoveMembers", func(t *testing.T) { + path := "/v2/{resourceId}/members/remove" + resourceIdValue := "resourceId" + path = strings.Replace(path, "{"+"resourceId"+"}", url.PathEscape(ParameterValueToString(resourceIdValue, "resourceId")), -1) + + testDefaultApiServeMux := http.NewServeMux() + testDefaultApiServeMux.HandleFunc(path, func(w http.ResponseWriter, req *http.Request) { + data := MembersResponse{} + w.Header().Add("Content-Type", "application/json") + json.NewEncoder(w).Encode(data) + }) + testServer := httptest.NewServer(testDefaultApiServeMux) + defer testServer.Close() + + configuration := &config.Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Region: "test_region", + Servers: config.ServerConfigurations{ + { + URL: testServer.URL, + Description: "Localhost for authorization_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) + } + + resourceId := "resourceId" + removeMembersPayload := RemoveMembersPayload{} + + resp, reqErr := apiClient.RemoveMembers(context.Background(), resourceId).RemoveMembersPayload(removeMembersPayload).Execute() + + if reqErr != nil { + t.Fatalf("error in call: %v", err) + } + if resp == nil { + t.Fatalf("response not present") + } + }) + +} diff --git a/services/authorization/client.go b/services/authorization/client.go new file mode 100644 index 000000000..c7d824ac8 --- /dev/null +++ b/services/authorization/client.go @@ -0,0 +1,626 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +import ( + "bytes" + "context" + "encoding/json" + "encoding/xml" + "fmt" + "io" + "log" + "mime/multipart" + "net/http" + "net/http/httputil" + "net/url" + "os" + "path/filepath" + "reflect" + "regexp" + "strconv" + "strings" + "time" + "unicode/utf8" + + "github.com/stackitcloud/stackit-sdk-go/core/auth" + "github.com/stackitcloud/stackit-sdk-go/core/config" +) + +var ( + jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) + xmlCheck = regexp.MustCompile(`(?i:(?:application|text)/xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer("%5B", "[", "%5D", "]") +) + +// APIClient manages communication with the STACKIT Membership API API v2.0 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *config.Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + defaultApi *DefaultApiService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. +// Optionally receives configuration options +func NewAPIClient(opts ...config.ConfigurationOption) (*APIClient, error) { + cfg := NewConfiguration() + + for _, option := range opts { + err := option(cfg) + if err != nil { + return nil, fmt.Errorf("configuring the client: %w", err) + } + } + + err := config.ConfigureRegion(cfg) + if err != nil { + return nil, fmt.Errorf("configuring region: %w", err) + } + + if cfg.HTTPClient == nil { + cfg.HTTPClient = &http.Client{} + } + + authRoundTripper, err := auth.SetupAuth(cfg) + if err != nil { + return nil, fmt.Errorf("setting up authentication: %w", err) + } + + cfg.HTTPClient.Transport = authRoundTripper + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + c.defaultApi = (*DefaultApiService)(&c.common) + + return c, nil +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func selectHeaderContentType(contentTypes []string) string { + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insensitive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.EqualFold(a, needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("expected %s to be of type %s but received %s", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +func ParameterValueToString(obj interface{}, key string) string { + if reflect.TypeOf(obj).Kind() != reflect.Ptr { + return fmt.Sprintf("%v", obj) + } + var param, ok = obj.(MappedNullable) + if !ok { + return "" + } + dataMap, err := param.ToMap() + if err != nil { + return "" + } + return fmt.Sprintf("%v", dataMap[key]) +} + +// parameterAddToHeaderOrQuery adds the provided object to the request header or url query +// supporting deep object syntax +func parameterAddToHeaderOrQuery(headerOrQueryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { + var v = reflect.ValueOf(obj) + var value = "" + if v == reflect.ValueOf(nil) { + value = "null" + } else { + switch v.Kind() { + case reflect.Invalid: + value = "invalid" + + case reflect.Struct: + if t, ok := obj.(MappedNullable); ok { + dataMap, err := t.ToMap() + if err != nil { + return + } + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, dataMap, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339), collectionType) + return + } + value = v.Type().String() + " value" + case reflect.Slice: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + var lenIndValue = indValue.Len() + for i := 0; i < lenIndValue; i++ { + var arrayValue = indValue.Index(i) + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, arrayValue.Interface(), collectionType) + } + return + + case reflect.Map: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + iter := indValue.MapRange() + for iter.Next() { + k, v := iter.Key(), iter.Value() + parameterAddToHeaderOrQuery(headerOrQueryParams, fmt.Sprintf("%s[%s]", keyPrefix, k.String()), v.Interface(), collectionType) + } + return + + case reflect.Interface: + fallthrough + case reflect.Ptr: + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, v.Elem().Interface(), collectionType) + return + + case reflect.Int, reflect.Int8, reflect.Int16, + reflect.Int32, reflect.Int64: + value = strconv.FormatInt(v.Int(), 10) + case reflect.Uint, reflect.Uint8, reflect.Uint16, + reflect.Uint32, reflect.Uint64, reflect.Uintptr: + value = strconv.FormatUint(v.Uint(), 10) + case reflect.Float32, reflect.Float64: + value = strconv.FormatFloat(v.Float(), 'g', -1, 32) + case reflect.Bool: + value = strconv.FormatBool(v.Bool()) + case reflect.String: + value = v.String() + default: + value = v.Type().String() + " value" + } + } + + switch valuesMap := headerOrQueryParams.(type) { + case url.Values: + if collectionType == "csv" && valuesMap.Get(keyPrefix) != "" { + valuesMap.Set(keyPrefix, valuesMap.Get(keyPrefix)+","+value) + } else { + valuesMap.Add(keyPrefix, value) + } + break + case map[string]string: + valuesMap[keyPrefix] = value + break + } +} + +// helper for converting interface{} parameters to json strings +func parameterToJson(obj interface{}) (string, error) { + jsonBuf, err := json.Marshal(obj) + if err != nil { + return "", err + } + return string(jsonBuf), err +} + +// callAPI do the request. +func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { + if c.cfg.Debug { + dump, err := httputil.DumpRequestOut(request, true) + if err != nil { + return nil, err + } + log.Printf("\n%s\n", string(dump)) + } + + resp, err := c.cfg.HTTPClient.Do(request) + if err != nil { + return resp, err + } + + if c.cfg.Debug { + dump, err := httputil.DumpResponse(resp, true) + if err != nil { + return resp, err + } + log.Printf("\n%s\n", string(dump)) + } + return resp, err +} + +// Allow modification of underlying config for alternate implementations and testing +// Caution: modifying the configuration while live can cause data races and potentially unwanted behavior +func (c *APIClient) GetConfig() *config.Configuration { + return c.cfg +} + +type formFile struct { + fileBytes []byte + fileName string + formFileName string +} + +// prepareRequest build the request +func (c *APIClient) prepareRequest( + ctx context.Context, + path string, method string, + postBody interface{}, + headerParams map[string]string, + queryParams url.Values, + formParams url.Values, + formFiles []formFile) (localVarRequest *http.Request, err error) { + + var body *bytes.Buffer + + // Detect postBody type and post. + if postBody != nil { + contentType := headerParams["Content-Type"] + if contentType == "" { + contentType = detectContentType(postBody) + headerParams["Content-Type"] = contentType + } + + body, err = setBody(postBody, contentType) + if err != nil { + return nil, err + } + } + + // add form parameters and file if available. + if strings.HasPrefix(headerParams["Content-Type"], "multipart/form-data") && len(formParams) > 0 || (len(formFiles) > 0) { + if body != nil { + return nil, fmt.Errorf("cannot specify postBody and multipart form at the same time.") + } + body = &bytes.Buffer{} + w := multipart.NewWriter(body) + + for k, v := range formParams { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return nil, err + } + } else { // form value + w.WriteField(k, iv) + } + } + } + for _, formFile := range formFiles { + if len(formFile.fileBytes) > 0 && formFile.fileName != "" { + w.Boundary() + part, err := w.CreateFormFile(formFile.formFileName, filepath.Base(formFile.fileName)) + if err != nil { + return nil, err + } + _, err = part.Write(formFile.fileBytes) + if err != nil { + return nil, err + } + } + } + + // Set the Boundary in the Content-Type + headerParams["Content-Type"] = w.FormDataContentType() + + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + w.Close() + } + + if strings.HasPrefix(headerParams["Content-Type"], "application/x-www-form-urlencoded") && len(formParams) > 0 { + if body != nil { + return nil, fmt.Errorf("cannot specify postBody and x-www-form-urlencoded form at the same time.") + } + body = &bytes.Buffer{} + body.WriteString(formParams.Encode()) + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + } + + // Setup path and query parameters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Override request host, if applicable + if c.cfg.Host != "" { + url.Host = c.cfg.Host + } + + // Override request scheme, if applicable + if c.cfg.Scheme != "" { + url.Scheme = c.cfg.Scheme + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = queryParamSplit.ReplaceAllStringFunc(query.Encode(), func(s string) string { + pieces := strings.Split(s, "=") + pieces[0] = queryDescape.Replace(pieces[0]) + return strings.Join(pieces, "=") + }) + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers[h] = []string{v} + } + localVarRequest.Header = headers + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) + + if ctx != nil { + // add context to the request + localVarRequest = localVarRequest.WithContext(ctx) + + // Walk through any authentication. + + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + return localVarRequest, nil +} + +func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) { + if len(b) == 0 { + return nil + } + if s, ok := v.(*string); ok { + *s = string(b) + return nil + } + if f, ok := v.(*os.File); ok { + f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = f.Write(b) + if err != nil { + return + } + _, err = f.Seek(0, io.SeekStart) + return + } + if f, ok := v.(**os.File); ok { + *f, err = os.CreateTemp("", "HttpClientFile") + if err != nil { + return + } + _, err = (*f).Write(b) + if err != nil { + return + } + _, err = (*f).Seek(0, io.SeekStart) + return + } + if xmlCheck.MatchString(contentType) { + if err = xml.Unmarshal(b, v); err != nil { + return err + } + return nil + } + if jsonCheck.MatchString(contentType) { + if actualObj, ok := v.(interface{ GetActualInstance() interface{} }); ok { // oneOf, anyOf schemas + if unmarshalObj, ok := actualObj.(interface{ UnmarshalJSON([]byte) error }); ok { // make sure it has UnmarshalJSON defined + if err = unmarshalObj.UnmarshalJSON(b); err != nil { + return err + } + } else { + return fmt.Errorf("unknown type with GetActualInstance but no unmarshalObj.UnmarshalJSON defined") + } + } else if err = json.Unmarshal(b, v); err != nil { // simple model + return err + } + return nil + } + return fmt.Errorf("undefined response type") +} + +// Add a file to the multipart request +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(filepath.Clean(path)) + if err != nil { + return err + } + err = file.Close() + if err != nil { + return err + } + + part, err := w.CreateFormFile(fieldName, filepath.Base(path)) + if err != nil { + return err + } + _, err = io.Copy(part, file) + + return err +} + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Set request body from an interface{} +func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { + if bodyBuf == nil { + bodyBuf = &bytes.Buffer{} + } + + if reader, ok := body.(io.Reader); ok { + _, err = bodyBuf.ReadFrom(reader) + } else if fp, ok := body.(*os.File); ok { + _, err = bodyBuf.ReadFrom(fp) + } else if b, ok := body.([]byte); ok { + _, err = bodyBuf.Write(b) + } else if s, ok := body.(string); ok { + _, err = bodyBuf.WriteString(s) + } else if s, ok := body.(*string); ok { + _, err = bodyBuf.WriteString(*s) + } else if jsonCheck.MatchString(contentType) { + err = json.NewEncoder(bodyBuf).Encode(body) + } else if xmlCheck.MatchString(contentType) { + err = xml.NewEncoder(bodyBuf).Encode(body) + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("invalid body type %s", contentType) + return nil, err + } + return bodyBuf, nil +} + +// detectContentType method is used to figure out `Request.Body` content type for request header +func detectContentType(body interface{}) string { + contentType := "text/plain; charset=utf-8" + kind := reflect.TypeOf(body).Kind() + + switch kind { + case reflect.Struct, reflect.Map, reflect.Ptr: + contentType = "application/json; charset=utf-8" + case reflect.String: + contentType = "text/plain; charset=utf-8" + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = "application/json; charset=utf-8" + } + } + + return contentType +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) time.Time { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } else { + expires = now.Add(lifetime) + } + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) int { + return utf8.RuneCountInString(s) +} diff --git a/services/authorization/configuration.go b/services/authorization/configuration.go new file mode 100644 index 000000000..2fe0fca51 --- /dev/null +++ b/services/authorization/configuration.go @@ -0,0 +1,38 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +import ( + "github.com/stackitcloud/stackit-sdk-go/core/config" +) + +// NewConfiguration returns a new Configuration object +func NewConfiguration() *config.Configuration { + cfg := &config.Configuration{ + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/1.0.0/go", + Debug: false, + Servers: config.ServerConfigurations{ + { + URL: "https://authorization.api.{region}stackit.cloud", + Description: "No description provided", + Variables: map[string]config.ServerVariable{ + "region": { + Description: "No description provided", + DefaultValue: "", + }, + }, + }, + }, + OperationServers: map[string]config.ServerConfigurations{}, + } + return cfg +} diff --git a/services/authorization/go.mod b/services/authorization/go.mod new file mode 100644 index 000000000..626965b98 --- /dev/null +++ b/services/authorization/go.mod @@ -0,0 +1,17 @@ +module github.com/stackitcloud/stackit-sdk-go/services/authorization + +go 1.18 + +require github.com/stackitcloud/stackit-sdk-go/core v0.7.7 + +require ( + github.com/MicahParks/keyfunc/v2 v2.1.0 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/golang-jwt/jwt/v5 v5.2.0 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/google/uuid v1.6.0 // indirect + golang.org/x/net v0.20.0 // indirect + golang.org/x/oauth2 v0.16.0 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/protobuf v1.31.0 // indirect +) diff --git a/services/authorization/go.sum b/services/authorization/go.sum new file mode 100644 index 000000000..9e2ba235d --- /dev/null +++ b/services/authorization/go.sum @@ -0,0 +1,33 @@ +github.com/MicahParks/keyfunc/v2 v2.1.0 h1:6ZXKb9Rp6qp1bDbJefnG7cTH8yMN1IC/4nf+GVjO99k= +github.com/MicahParks/keyfunc/v2 v2.1.0/go.mod h1:rW42fi+xgLJ2FRRXAfNx9ZA8WpD4OeE/yHVMteCkw9k= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw= +github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +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.7.7 h1:w1T8I2ERT5xPHXS+UV9maSseK8tyUJQjzS21hhRSWjU= +github.com/stackitcloud/stackit-sdk-go/core v0.7.7/go.mod h1:nfC2Tbjd73Ivn8wEp3lvG/dmiXHgl6QX+HY2Ih3aGgw= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ= +golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/services/authorization/model_add_members_payload.go b/services/authorization/model_add_members_payload.go new file mode 100644 index 000000000..37c789b1f --- /dev/null +++ b/services/authorization/model_add_members_payload.go @@ -0,0 +1,18 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type AddMembersPayload struct { + // REQUIRED + Members *[]Member `json:"members"` + // REQUIRED + ResourceType *string `json:"resourceType"` +} diff --git a/services/authorization/model_add_roles_payload.go b/services/authorization/model_add_roles_payload.go new file mode 100644 index 000000000..5467919cd --- /dev/null +++ b/services/authorization/model_add_roles_payload.go @@ -0,0 +1,18 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type AddRolesPayload struct { + // REQUIRED + ResourceType *string `json:"resourceType"` + // REQUIRED + Roles *[]AddRolesPayloadItem `json:"roles"` +} diff --git a/services/authorization/model_add_roles_payload_item.go b/services/authorization/model_add_roles_payload_item.go new file mode 100644 index 000000000..992508302 --- /dev/null +++ b/services/authorization/model_add_roles_payload_item.go @@ -0,0 +1,20 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type AddRolesPayloadItem struct { + // REQUIRED + Description *string `json:"description"` + // REQUIRED + Name *string `json:"name"` + // REQUIRED + Permissions *[]PermissionRequest `json:"permissions"` +} diff --git a/services/authorization/model_consistency.go b/services/authorization/model_consistency.go new file mode 100644 index 000000000..73feee62b --- /dev/null +++ b/services/authorization/model_consistency.go @@ -0,0 +1,18 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type Consistency struct { + AtExactSnapshot *Zookie `json:"atExactSnapshot,omitempty"` + AtLeastAsFresh *Zookie `json:"atLeastAsFresh,omitempty"` + FullyConsistent *bool `json:"fullyConsistent,omitempty"` + MinimizeLatency *bool `json:"minimizeLatency,omitempty"` +} diff --git a/services/authorization/model_create_resource_payload.go b/services/authorization/model_create_resource_payload.go new file mode 100644 index 000000000..1ad2dc036 --- /dev/null +++ b/services/authorization/model_create_resource_payload.go @@ -0,0 +1,22 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type CreateResourcePayload struct { + Members *[]Member `json:"members,omitempty"` + // REQUIRED + ParentId *string `json:"parentId"` + // REQUIRED + ParentType *string `json:"parentType"` + ResourceAlias *string `json:"resourceAlias,omitempty"` + // REQUIRED + ResourceId *string `json:"resourceId"` +} diff --git a/services/authorization/model_create_resource_response.go b/services/authorization/model_create_resource_response.go new file mode 100644 index 000000000..11ac841ae --- /dev/null +++ b/services/authorization/model_create_resource_response.go @@ -0,0 +1,25 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type CreateResourceResponse struct { + Members *[]Member `json:"members,omitempty"` + // REQUIRED + ParentId *string `json:"parentId"` + // REQUIRED + ParentType *string `json:"parentType"` + ResourceAlias *string `json:"resourceAlias,omitempty"` + // REQUIRED + ResourceId *string `json:"resourceId"` + // REQUIRED + ResourceType *string `json:"resourceType"` + WrittenAt *Zookie `json:"writtenAt,omitempty"` +} diff --git a/services/authorization/model_delete_resource_response.go b/services/authorization/model_delete_resource_response.go new file mode 100644 index 000000000..c2fc075c0 --- /dev/null +++ b/services/authorization/model_delete_resource_response.go @@ -0,0 +1,15 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type DeleteResourceResponse struct { + WrittenAt *Zookie `json:"writtenAt,omitempty"` +} diff --git a/services/authorization/model_delete_subject_response.go b/services/authorization/model_delete_subject_response.go new file mode 100644 index 000000000..2dc7a8df7 --- /dev/null +++ b/services/authorization/model_delete_subject_response.go @@ -0,0 +1,17 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type DeleteSubjectResponse struct { + DeletedAt *Zookie `json:"deletedAt,omitempty"` + // REQUIRED + DeletedFromResourceIds *[]string `json:"deletedFromResourceIds"` +} diff --git a/services/authorization/model_enforce_permission_payload.go b/services/authorization/model_enforce_permission_payload.go new file mode 100644 index 000000000..60fe155ed --- /dev/null +++ b/services/authorization/model_enforce_permission_payload.go @@ -0,0 +1,23 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type EnforcePermissionPayload struct { + // REQUIRED + Actions *[]string `json:"actions"` + Consistency *Consistency `json:"consistency,omitempty"` + // REQUIRED + Resource *string `json:"resource"` + // REQUIRED + ResourceType *string `json:"resourceType"` + // REQUIRED + Subject *string `json:"subject"` +} diff --git a/services/authorization/model_error_response.go b/services/authorization/model_error_response.go new file mode 100644 index 000000000..da45f4878 --- /dev/null +++ b/services/authorization/model_error_response.go @@ -0,0 +1,28 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +import ( + "time" +) + +type ErrorResponse struct { + // REQUIRED + Error *string `json:"error"` + // REQUIRED + Message *string `json:"message"` + // REQUIRED + Path *string `json:"path"` + // REQUIRED + Status *int64 `json:"status"` + // REQUIRED + TimeStamp *time.Time `json:"timeStamp"` +} diff --git a/services/authorization/model_existing_permission.go b/services/authorization/model_existing_permission.go new file mode 100644 index 000000000..9293de857 --- /dev/null +++ b/services/authorization/model_existing_permission.go @@ -0,0 +1,18 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type ExistingPermission struct { + // REQUIRED + Description *string `json:"description"` + // REQUIRED + Name *string `json:"name"` +} diff --git a/services/authorization/model_list_members_response.go b/services/authorization/model_list_members_response.go new file mode 100644 index 000000000..f12e85839 --- /dev/null +++ b/services/authorization/model_list_members_response.go @@ -0,0 +1,20 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type ListMembersResponse struct { + // REQUIRED + Members *[]Member `json:"members"` + // REQUIRED + ResourceId *string `json:"resourceId"` + // REQUIRED + ResourceType *string `json:"resourceType"` +} diff --git a/services/authorization/model_list_permissions_response.go b/services/authorization/model_list_permissions_response.go new file mode 100644 index 000000000..66f2bc5c6 --- /dev/null +++ b/services/authorization/model_list_permissions_response.go @@ -0,0 +1,16 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type ListPermissionsResponse struct { + // REQUIRED + Permissions *[]Permission `json:"permissions"` +} diff --git a/services/authorization/model_list_subject_ids_response.go b/services/authorization/model_list_subject_ids_response.go new file mode 100644 index 000000000..95b9f3a21 --- /dev/null +++ b/services/authorization/model_list_subject_ids_response.go @@ -0,0 +1,19 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type ListSubjectIdsResponse struct { + Cursor *string `json:"cursor,omitempty"` + // REQUIRED + Items *[]string `json:"items"` + // Can be cast to int32 without loss of precision. + Limit *int64 `json:"limit,omitempty"` +} diff --git a/services/authorization/model_list_subjects_response.go b/services/authorization/model_list_subjects_response.go new file mode 100644 index 000000000..dae90b3da --- /dev/null +++ b/services/authorization/model_list_subjects_response.go @@ -0,0 +1,16 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type ListSubjectsResponse struct { + // REQUIRED + Items *[]Subject `json:"items"` +} diff --git a/services/authorization/model_list_user_memberships_response.go b/services/authorization/model_list_user_memberships_response.go new file mode 100644 index 000000000..1ccf15e17 --- /dev/null +++ b/services/authorization/model_list_user_memberships_response.go @@ -0,0 +1,16 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type ListUserMembershipsResponse struct { + // REQUIRED + Items *[]UserMembership `json:"items"` +} diff --git a/services/authorization/model_list_user_permissions_response.go b/services/authorization/model_list_user_permissions_response.go new file mode 100644 index 000000000..54bf747cc --- /dev/null +++ b/services/authorization/model_list_user_permissions_response.go @@ -0,0 +1,16 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type ListUserPermissionsResponse struct { + // REQUIRED + Items *[]UserPermission `json:"items"` +} diff --git a/services/authorization/model_member.go b/services/authorization/model_member.go new file mode 100644 index 000000000..ca4ddbed2 --- /dev/null +++ b/services/authorization/model_member.go @@ -0,0 +1,18 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type Member struct { + // REQUIRED + Role *string `json:"role"` + // REQUIRED + Subject *string `json:"subject"` +} diff --git a/services/authorization/model_members_response.go b/services/authorization/model_members_response.go new file mode 100644 index 000000000..061f4dcc5 --- /dev/null +++ b/services/authorization/model_members_response.go @@ -0,0 +1,21 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type MembersResponse struct { + // REQUIRED + Members *[]Member `json:"members"` + // REQUIRED + ResourceId *string `json:"resourceId"` + // REQUIRED + ResourceType *string `json:"resourceType"` + WrittenAt *Zookie `json:"writtenAt,omitempty"` +} diff --git a/services/authorization/model_permission.go b/services/authorization/model_permission.go new file mode 100644 index 000000000..88f8f134e --- /dev/null +++ b/services/authorization/model_permission.go @@ -0,0 +1,18 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type Permission struct { + // REQUIRED + Description *string `json:"description"` + // REQUIRED + Name *string `json:"name"` +} diff --git a/services/authorization/model_permission_request.go b/services/authorization/model_permission_request.go new file mode 100644 index 000000000..35b1f0ccf --- /dev/null +++ b/services/authorization/model_permission_request.go @@ -0,0 +1,16 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type PermissionRequest struct { + // REQUIRED + Name *string `json:"name"` +} diff --git a/services/authorization/model_remove_members_payload.go b/services/authorization/model_remove_members_payload.go new file mode 100644 index 000000000..369aeed18 --- /dev/null +++ b/services/authorization/model_remove_members_payload.go @@ -0,0 +1,19 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type RemoveMembersPayload struct { + ForceRemove *bool `json:"forceRemove,omitempty"` + // REQUIRED + Members *[]Member `json:"members"` + // REQUIRED + ResourceType *string `json:"resourceType"` +} diff --git a/services/authorization/model_remove_role_request.go b/services/authorization/model_remove_role_request.go new file mode 100644 index 000000000..478e1ecdc --- /dev/null +++ b/services/authorization/model_remove_role_request.go @@ -0,0 +1,16 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type RemoveRoleRequest struct { + // REQUIRED + Name *string `json:"name"` +} diff --git a/services/authorization/model_remove_roles_payload.go b/services/authorization/model_remove_roles_payload.go new file mode 100644 index 000000000..bc23b6279 --- /dev/null +++ b/services/authorization/model_remove_roles_payload.go @@ -0,0 +1,18 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type RemoveRolesPayload struct { + // REQUIRED + ResourceType *string `json:"resourceType"` + // REQUIRED + Roles *[]RemoveRoleRequest `json:"roles"` +} diff --git a/services/authorization/model_resource.go b/services/authorization/model_resource.go new file mode 100644 index 000000000..9600a2b14 --- /dev/null +++ b/services/authorization/model_resource.go @@ -0,0 +1,19 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type Resource struct { + ResourceAlias *string `json:"resourceAlias,omitempty"` + // REQUIRED + ResourceId *string `json:"resourceId"` + // REQUIRED + ResourceType *string `json:"resourceType"` +} diff --git a/services/authorization/model_role.go b/services/authorization/model_role.go new file mode 100644 index 000000000..e794c8797 --- /dev/null +++ b/services/authorization/model_role.go @@ -0,0 +1,20 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type Role struct { + // REQUIRED + Description *string `json:"description"` + // REQUIRED + Name *string `json:"name"` + // REQUIRED + Permissions *[]Permission `json:"permissions"` +} diff --git a/services/authorization/model_roles_response.go b/services/authorization/model_roles_response.go new file mode 100644 index 000000000..191ab1b64 --- /dev/null +++ b/services/authorization/model_roles_response.go @@ -0,0 +1,20 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type RolesResponse struct { + // REQUIRED + ResourceId *string `json:"resourceId"` + // REQUIRED + ResourceType *string `json:"resourceType"` + // REQUIRED + Roles *[]Role `json:"roles"` +} diff --git a/services/authorization/model_subject.go b/services/authorization/model_subject.go new file mode 100644 index 000000000..9fb9dbc18 --- /dev/null +++ b/services/authorization/model_subject.go @@ -0,0 +1,20 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type Subject struct { + // REQUIRED + Email *string `json:"email"` + // REQUIRED + Id *string `json:"id"` + // REQUIRED + Type *string `json:"type"` +} diff --git a/services/authorization/model_transfer_subject_memberships_payload.go b/services/authorization/model_transfer_subject_memberships_payload.go new file mode 100644 index 000000000..9c5aee2bd --- /dev/null +++ b/services/authorization/model_transfer_subject_memberships_payload.go @@ -0,0 +1,16 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type TransferSubjectMembershipsPayload struct { + // REQUIRED + TargetSubjectId *string `json:"targetSubjectId"` +} diff --git a/services/authorization/model_user_membership.go b/services/authorization/model_user_membership.go new file mode 100644 index 000000000..b8f2f20e0 --- /dev/null +++ b/services/authorization/model_user_membership.go @@ -0,0 +1,22 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type UserMembership struct { + // REQUIRED + ResourceId *string `json:"resourceId"` + // REQUIRED + ResourceType *string `json:"resourceType"` + // REQUIRED + Role *string `json:"role"` + // REQUIRED + Subject *string `json:"subject"` +} diff --git a/services/authorization/model_user_permission.go b/services/authorization/model_user_permission.go new file mode 100644 index 000000000..c29c3514b --- /dev/null +++ b/services/authorization/model_user_permission.go @@ -0,0 +1,20 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type UserPermission struct { + // REQUIRED + Permissions *[]ExistingPermission `json:"permissions"` + // REQUIRED + ResourceId *string `json:"resourceId"` + // REQUIRED + ResourceType *string `json:"resourceType"` +} diff --git a/services/authorization/model_user_resources_response.go b/services/authorization/model_user_resources_response.go new file mode 100644 index 000000000..7e8c6595e --- /dev/null +++ b/services/authorization/model_user_resources_response.go @@ -0,0 +1,21 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type UserResourcesResponse struct { + // REQUIRED + Cursor *string `json:"cursor"` + // REQUIRED + Items *[]Resource `json:"items"` + // Can be cast to int32 without loss of precision. + // REQUIRED + Limit *int64 `json:"limit"` +} diff --git a/services/authorization/model_validate_child_members_payload.go b/services/authorization/model_validate_child_members_payload.go new file mode 100644 index 000000000..557065a09 --- /dev/null +++ b/services/authorization/model_validate_child_members_payload.go @@ -0,0 +1,20 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type ValidateChildMembersPayload struct { + // REQUIRED + ChildResourceType *string `json:"childResourceType"` + // REQUIRED + Members *[]Member `json:"members"` + // REQUIRED + ResourceType *string `json:"resourceType"` +} diff --git a/services/authorization/model_write_schema_payload.go b/services/authorization/model_write_schema_payload.go new file mode 100644 index 000000000..6d87a1c24 --- /dev/null +++ b/services/authorization/model_write_schema_payload.go @@ -0,0 +1,16 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type WriteSchemaPayload struct { + // REQUIRED + Schema *string `json:"schema"` +} diff --git a/services/authorization/model_write_schema_response.go b/services/authorization/model_write_schema_response.go new file mode 100644 index 000000000..5b66b06ef --- /dev/null +++ b/services/authorization/model_write_schema_response.go @@ -0,0 +1,16 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type WriteSchemaResponse struct { + // REQUIRED + WrittenAt *Zookie `json:"writtenAt"` +} diff --git a/services/authorization/model_zookie.go b/services/authorization/model_zookie.go new file mode 100644 index 000000000..c01d3255b --- /dev/null +++ b/services/authorization/model_zookie.go @@ -0,0 +1,15 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +type Zookie struct { + Zookie *string `json:"zookie,omitempty"` +} diff --git a/services/authorization/utils.go b/services/authorization/utils.go new file mode 100644 index 000000000..293a1b638 --- /dev/null +++ b/services/authorization/utils.go @@ -0,0 +1,347 @@ +/* +STACKIT Membership API + +The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources. + +API version: 2.0 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package authorization + +import ( + "encoding/json" + "reflect" + "time" +) + +// PtrBool is a helper routine that returns a pointer to given boolean value. +func PtrBool(v bool) *bool { return &v } + +// PtrInt is a helper routine that returns a pointer to given integer value. +func PtrInt(v int) *int { return &v } + +// PtrInt32 is a helper routine that returns a pointer to given integer value. +func PtrInt32(v int32) *int32 { return &v } + +// PtrInt64 is a helper routine that returns a pointer to given integer value. +func PtrInt64(v int64) *int64 { return &v } + +// PtrFloat32 is a helper routine that returns a pointer to given float value. +func PtrFloat32(v float32) *float32 { return &v } + +// PtrFloat64 is a helper routine that returns a pointer to given float value. +func PtrFloat64(v float64) *float64 { return &v } + +// PtrString is a helper routine that returns a pointer to given string value. +func PtrString(v string) *string { return &v } + +// PtrTime is helper routine that returns a pointer to given Time value. +func PtrTime(v time.Time) *time.Time { return &v } + +type NullableBool struct { + value *bool + isSet bool +} + +func (v NullableBool) Get() *bool { + return v.value +} + +func (v *NullableBool) Set(val *bool) { + v.value = val + v.isSet = true +} + +func (v NullableBool) IsSet() bool { + return v.isSet +} + +func (v *NullableBool) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableBool(val *bool) *NullableBool { + return &NullableBool{value: val, isSet: true} +} + +func (v NullableBool) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableBool) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt struct { + value *int + isSet bool +} + +func (v NullableInt) Get() *int { + return v.value +} + +func (v *NullableInt) Set(val *int) { + v.value = val + v.isSet = true +} + +func (v NullableInt) IsSet() bool { + return v.isSet +} + +func (v *NullableInt) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt(val *int) *NullableInt { + return &NullableInt{value: val, isSet: true} +} + +func (v NullableInt) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt32 struct { + value *int32 + isSet bool +} + +func (v NullableInt32) Get() *int32 { + return v.value +} + +func (v *NullableInt32) Set(val *int32) { + v.value = val + v.isSet = true +} + +func (v NullableInt32) IsSet() bool { + return v.isSet +} + +func (v *NullableInt32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt32(val *int32) *NullableInt32 { + return &NullableInt32{value: val, isSet: true} +} + +func (v NullableInt32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableInt64 struct { + value *int64 + isSet bool +} + +func (v NullableInt64) Get() *int64 { + return v.value +} + +func (v *NullableInt64) Set(val *int64) { + v.value = val + v.isSet = true +} + +func (v NullableInt64) IsSet() bool { + return v.isSet +} + +func (v *NullableInt64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableInt64(val *int64) *NullableInt64 { + return &NullableInt64{value: val, isSet: true} +} + +func (v NullableInt64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableInt64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat32 struct { + value *float32 + isSet bool +} + +func (v NullableFloat32) Get() *float32 { + return v.value +} + +func (v *NullableFloat32) Set(val *float32) { + v.value = val + v.isSet = true +} + +func (v NullableFloat32) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat32) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat32(val *float32) *NullableFloat32 { + return &NullableFloat32{value: val, isSet: true} +} + +func (v NullableFloat32) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat32) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableFloat64 struct { + value *float64 + isSet bool +} + +func (v NullableFloat64) Get() *float64 { + return v.value +} + +func (v *NullableFloat64) Set(val *float64) { + v.value = val + v.isSet = true +} + +func (v NullableFloat64) IsSet() bool { + return v.isSet +} + +func (v *NullableFloat64) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableFloat64(val *float64) *NullableFloat64 { + return &NullableFloat64{value: val, isSet: true} +} + +func (v NullableFloat64) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableFloat64) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableString struct { + value *string + isSet bool +} + +func (v NullableString) Get() *string { + return v.value +} + +func (v *NullableString) Set(val *string) { + v.value = val + v.isSet = true +} + +func (v NullableString) IsSet() bool { + return v.isSet +} + +func (v *NullableString) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableString(val *string) *NullableString { + return &NullableString{value: val, isSet: true} +} + +func (v NullableString) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableString) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +type NullableTime struct { + value *time.Time + isSet bool +} + +func (v NullableTime) Get() *time.Time { + return v.value +} + +func (v *NullableTime) Set(val *time.Time) { + v.value = val + v.isSet = true +} + +func (v NullableTime) IsSet() bool { + return v.isSet +} + +func (v *NullableTime) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTime(val *time.Time) *NullableTime { + return &NullableTime{value: val, isSet: true} +} + +func (v NullableTime) MarshalJSON() ([]byte, error) { + return v.value.MarshalJSON() +} + +func (v *NullableTime) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// IsNil checks if an input is nil +func IsNil(i interface{}) bool { + if i == nil { + return true + } + switch reflect.TypeOf(i).Kind() { + case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.UnsafePointer, reflect.Interface, reflect.Slice: + return reflect.ValueOf(i).IsNil() + case reflect.Array: + return reflect.ValueOf(i).IsZero() + } + return false +} + +type MappedNullable interface { + ToMap() (map[string]interface{}, error) +} diff --git a/services/membership/CHANGELOG.md b/services/membership/CHANGELOG.md index 5cce5f2a5..fe18da8d2 100644 --- a/services/membership/CHANGELOG.md +++ b/services/membership/CHANGELOG.md @@ -1,3 +1,11 @@ +> This module has been replaced with the authorization module, which connects to the same API. +> +> **This module will receive no further updates.** Use `github.com/stackitcloud/stackit-sdk-go/services/authorization` instead. + +## v0.4.0 (2024-02-07) + +- Add deprecation note + ## v0.3.5 (2024-02-02) - Update `core` to `v0.7.7`. The `http.request` context is now passed in the client `Do` call. diff --git a/services/membership/go.mod b/services/membership/go.mod index d2ad5481e..1707384df 100644 --- a/services/membership/go.mod +++ b/services/membership/go.mod @@ -1,3 +1,4 @@ +// Deprecated: this module has been replaced with the authorization module, which connects to the same API. This module will receive no further updates. Use github.com/stackitcloud/stackit-sdk-go/services/authorization instead module github.com/stackitcloud/stackit-sdk-go/services/membership go 1.18