From e9a9498574e7a249b0bea268ac290a78bc6af0bc Mon Sep 17 00:00:00 2001 From: Philip Ellis Date: Tue, 15 Oct 2024 17:09:34 -0400 Subject: [PATCH 1/5] added generic api calls --- .github/workflows/build_pr.yaml | 8 + api_generic/.gitignore | 24 + api_generic/.openapi-generator-ignore | 23 + api_generic/.openapi-generator/FILES | 15 + api_generic/.openapi-generator/VERSION | 1 + api_generic/.travis.yml | 8 + api_generic/README.md | 205 +++++++ api_generic/api/openapi.yaml | 171 ++++++ api_generic/api_default.go | 553 ++++++++++++++++++ api_generic/client.go | 740 +++++++++++++++++++++++++ api_generic/configuration.go | 247 +++++++++ api_generic/docs/DefaultAPI.md | 359 ++++++++++++ api_generic/git_push.sh | 57 ++ api_generic/response.go | 47 ++ api_generic/test/api_default_test.go | 95 ++++ api_generic/utils.go | 361 ++++++++++++ client.go | 20 +- sdk-resources/generic-api.yaml | 163 ++++++ sdk-resources/generic-config.yaml | 9 + validation_test.go | 17 + 20 files changed, 3116 insertions(+), 7 deletions(-) create mode 100644 api_generic/.gitignore create mode 100644 api_generic/.openapi-generator-ignore create mode 100644 api_generic/.openapi-generator/FILES create mode 100644 api_generic/.openapi-generator/VERSION create mode 100644 api_generic/.travis.yml create mode 100644 api_generic/README.md create mode 100644 api_generic/api/openapi.yaml create mode 100644 api_generic/api_default.go create mode 100644 api_generic/client.go create mode 100644 api_generic/configuration.go create mode 100644 api_generic/docs/DefaultAPI.md create mode 100644 api_generic/git_push.sh create mode 100644 api_generic/response.go create mode 100644 api_generic/test/api_default_test.go create mode 100644 api_generic/utils.go create mode 100644 sdk-resources/generic-api.yaml create mode 100644 sdk-resources/generic-config.yaml diff --git a/.github/workflows/build_pr.yaml b/.github/workflows/build_pr.yaml index 4f8af8a04..6ac85c5b5 100644 --- a/.github/workflows/build_pr.yaml +++ b/.github/workflows/build_pr.yaml @@ -62,6 +62,14 @@ jobs: java -jar openapi-generator-cli.jar generate -i api-specs/idn/sailpoint-api.v2024.yaml -g go -o api_v2024 --global-property skipFormModel=false --config sdk-resources/v2024-config.yaml node sdk-resources/postscript.js ./api_v2024 + - name: Build Generic SDK + id: buildGeneric + if: steps.buildBeta.outcome == 'success' + run: | + rm -rf ./api_generic + java -jar openapi-generator-cli.jar generate -i sdk-resources/generic-api.yaml -g go -o api_generic --global-property skipFormModel=false --config sdk-resources/generic-config.yaml + node sdk-resources/postscript.js ./api_generic + - name: After SDK Build if: steps.buildV2024.outcome == 'success' run: | diff --git a/api_generic/.gitignore b/api_generic/.gitignore new file mode 100644 index 000000000..daf913b1b --- /dev/null +++ b/api_generic/.gitignore @@ -0,0 +1,24 @@ +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test +*.prof diff --git a/api_generic/.openapi-generator-ignore b/api_generic/.openapi-generator-ignore new file mode 100644 index 000000000..7484ee590 --- /dev/null +++ b/api_generic/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/api_generic/.openapi-generator/FILES b/api_generic/.openapi-generator/FILES new file mode 100644 index 000000000..383ba08f9 --- /dev/null +++ b/api_generic/.openapi-generator/FILES @@ -0,0 +1,15 @@ +.gitignore +.openapi-generator-ignore +.travis.yml +README.md +api/openapi.yaml +api_default.go +client.go +configuration.go +docs/DefaultAPI.md +git_push.sh +go.mod +go.sum +response.go +test/api_default_test.go +utils.go diff --git a/api_generic/.openapi-generator/VERSION b/api_generic/.openapi-generator/VERSION new file mode 100644 index 000000000..09a6d3084 --- /dev/null +++ b/api_generic/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.8.0 diff --git a/api_generic/.travis.yml b/api_generic/.travis.yml new file mode 100644 index 000000000..f5cb2ce9a --- /dev/null +++ b/api_generic/.travis.yml @@ -0,0 +1,8 @@ +language: go + +install: + - go get -d -v . + +script: + - go build -v ./ + diff --git a/api_generic/README.md b/api_generic/README.md new file mode 100644 index 000000000..816b79b7a --- /dev/null +++ b/api_generic/README.md @@ -0,0 +1,205 @@ +# Go API client for api_generic + +Generic API specification for the Identity Security Cloud platform + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. + +- API version: v2024 +- Package version: 2.1.13 +- Generator version: 7.8.0 +- Build package: org.openapitools.codegen.languages.GoClientCodegen +For more information, please visit [https://developer.sailpoint.com/discuss/api-help](https://developer.sailpoint.com/discuss/api-help) + +## Installation + +Install the following dependencies: + +```sh +go get github.com/stretchr/testify/assert +go get golang.org/x/oauth2 +go get golang.org/x/net/context +``` + +Put the package under your project folder and add the following in import: + +```go +import api_generic "github.com/sailpoint-oss/golang-sdk/v2" +``` + +To use a proxy, set the environment variable `HTTP_PROXY`: + +```go +os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port") +``` + +## Configuration of Server URL + +Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification. + +### Select Server Configuration + +For using other server than the one defined on index 0 set context value `api_generic.ContextServerIndex` of type `int`. + +```go +ctx := context.WithValue(context.Background(), api_generic.ContextServerIndex, 1) +``` + +### Templated Server URL + +Templated server URL is formatted using default variables from configuration or from context value `api_generic.ContextServerVariables` of type `map[string]string`. + +```go +ctx := context.WithValue(context.Background(), api_generic.ContextServerVariables, map[string]string{ + "basePath": "v2", +}) +``` + +Note, enum values are always validated and all unused variables are silently ignored. + +### URLs Configuration per Operation + +Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. +An operation is uniquely identified by `"{classname}Service.{nickname}"` string. +Similar rules for overriding default operation server index and variables applies by using `api_generic.ContextOperationServerIndices` and `api_generic.ContextOperationServerVariables` context maps. + +```go +ctx := context.WithValue(context.Background(), api_generic.ContextOperationServerIndices, map[string]int{ + "{classname}Service.{nickname}": 2, +}) +ctx = context.WithValue(context.Background(), api_generic.ContextOperationServerVariables, map[string]map[string]string{ + "{classname}Service.{nickname}": { + "port": "8443", + }, +}) +``` + +## Documentation for API Endpoints + +All URIs are relative to *https://sailpoint.api.identitynow.com/v2024* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DefaultAPI* | [**GenericDelete**](docs/DefaultAPI.md#genericdelete) | **Delete** /{path} | Generic DELETE request +*DefaultAPI* | [**GenericGet**](docs/DefaultAPI.md#genericget) | **Get** /{path} | Generic GET request +*DefaultAPI* | [**GenericPatch**](docs/DefaultAPI.md#genericpatch) | **Patch** /{path} | Generic PATCH request +*DefaultAPI* | [**GenericPost**](docs/DefaultAPI.md#genericpost) | **Post** /{path} | Generic POST request +*DefaultAPI* | [**GenericPut**](docs/DefaultAPI.md#genericput) | **Put** /{path} | Generic PUT request + + +## Documentation For Models + + + +## Documentation For Authorization + + +Authentication schemes defined for the API: +### userAuth + + +- **Type**: OAuth +- **Flow**: application +- **Authorization URL**: +- **Scopes**: + - **sp:scopes:default**: default scope + - **sp:scopes:all**: access to all scopes + +Example + +```go +auth := context.WithValue(context.Background(), api_generic.ContextAccessToken, "ACCESSTOKENSTRING") +r, err := client.Service.Operation(auth, args) +``` + +Or via OAuth2 module to automatically refresh tokens and perform user authentication. + +```go +import "golang.org/x/oauth2" + +/* Perform OAuth2 round trip request and obtain a token */ + +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) +auth := context.WithValue(oauth2.NoContext, api_generic.ContextOAuth2, tokenSource) +r, err := client.Service.Operation(auth, args) +``` + +### userAuth + + +- **Type**: OAuth +- **Flow**: accessCode +- **Authorization URL**: https://tenant.login.sailpoint.com/oauth/authorize +- **Scopes**: + - **sp:scopes:default**: default scope + - **sp:scopes:all**: access to all scopes + +Example + +```go +auth := context.WithValue(context.Background(), api_generic.ContextAccessToken, "ACCESSTOKENSTRING") +r, err := client.Service.Operation(auth, args) +``` + +Or via OAuth2 module to automatically refresh tokens and perform user authentication. + +```go +import "golang.org/x/oauth2" + +/* Perform OAuth2 round trip request and obtain a token */ + +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) +auth := context.WithValue(oauth2.NoContext, api_generic.ContextOAuth2, tokenSource) +r, err := client.Service.Operation(auth, args) +``` + +### applicationAuth + + +- **Type**: OAuth +- **Flow**: application +- **Authorization URL**: +- **Scopes**: + - **sp:scopes:default**: default scope + - **sp:scopes:all**: access to all scopes + +Example + +```go +auth := context.WithValue(context.Background(), api_generic.ContextAccessToken, "ACCESSTOKENSTRING") +r, err := client.Service.Operation(auth, args) +``` + +Or via OAuth2 module to automatically refresh tokens and perform user authentication. + +```go +import "golang.org/x/oauth2" + +/* Perform OAuth2 round trip request and obtain a token */ + +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) +auth := context.WithValue(oauth2.NoContext, api_generic.ContextOAuth2, tokenSource) +r, err := client.Service.Operation(auth, args) +``` + + +## Documentation for Utility Methods + +Due to the fact that model structure members are all pointers, this package contains +a number of utility functions to easily obtain pointers to values of basic types. +Each of these functions takes a value of the given basic type and returns a pointer to it: + +* `PtrBool` +* `PtrInt` +* `PtrInt32` +* `PtrInt64` +* `PtrFloat` +* `PtrFloat32` +* `PtrFloat64` +* `PtrString` +* `PtrTime` + +## Author + + + diff --git a/api_generic/api/openapi.yaml b/api_generic/api/openapi.yaml new file mode 100644 index 000000000..57f7acbb8 --- /dev/null +++ b/api_generic/api/openapi.yaml @@ -0,0 +1,171 @@ +openapi: 3.0.1 +info: + contact: + name: Developer Relations + url: https://developer.sailpoint.com/discuss/api-help + description: Generic API specification for the Identity Security Cloud platform + license: + name: MIT + url: https://opensource.org/licenses/MIT + termsOfService: https://developer.sailpoint.com/discuss/tos + title: Generic Identity Security Cloud V2024 API + version: v2024 +servers: +- description: This is the production API server. + url: "https://{tenant}.api.identitynow.com/v2024" + variables: + tenant: + default: sailpoint + description: "This is the name of your tenant, typically your company's name." +- description: This is the V2024 API server. + url: "https://{apiUrl}/v2024" + variables: + apiUrl: + default: sailpoint.api.identitynow.com + description: This is the api url of your tenant +security: +- userAuth: + - sp:scopes:all +paths: + /{path}: + delete: + operationId: genericDelete + parameters: + - explode: false + in: path + name: path + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/GenericResponse' + description: Successful response + summary: Generic DELETE request + get: + operationId: genericGet + parameters: + - explode: false + in: path + name: path + required: true + schema: + type: string + style: simple + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/GenericResponse' + description: Successful response + summary: Generic GET request + patch: + operationId: genericPatch + parameters: + - explode: false + in: path + name: path + required: true + schema: + type: string + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/GenericRequest' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/GenericResponse' + description: Successful response + summary: Generic PATCH request + post: + operationId: genericPost + parameters: + - explode: false + in: path + name: path + required: true + schema: + type: string + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/GenericRequest' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/GenericResponse' + description: Successful response + summary: Generic POST request + put: + operationId: genericPut + parameters: + - explode: false + in: path + name: path + required: true + schema: + type: string + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/GenericRequest' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/GenericResponse' + description: Successful response + summary: Generic PUT request +components: + schemas: + GenericRequest: + additionalProperties: true + type: object + GenericResponse: + additionalProperties: true + type: object + securitySchemes: + userAuth: + description: OAuth2 Bearer token (JWT) generated using either a personal access + token (PAT) or through the authorization code flow. + flows: + authorizationCode: + authorizationUrl: https://tenant.login.sailpoint.com/oauth/authorize + scopes: + sp:scopes:default: default scope + sp:scopes:all: access to all scopes + tokenUrl: https://tenant.api.identitynow.com/oauth/token + clientCredentials: + scopes: + sp:scopes:default: default scope + sp:scopes:all: access to all scopes + tokenUrl: https://tenant.api.identitynow.com/oauth/token + type: oauth2 + x-displayName: Personal Access Token + applicationAuth: + description: OAuth2 Bearer token (JWT) generated using client credentials flow. + flows: + clientCredentials: + scopes: + sp:scopes:default: default scope + sp:scopes:all: access to all scopes + tokenUrl: https://tenant.api.identitynow.com/oauth/token + type: oauth2 + x-displayName: Client Credentials diff --git a/api_generic/api_default.go b/api_generic/api_default.go new file mode 100644 index 000000000..b52d21d89 --- /dev/null +++ b/api_generic/api_default.go @@ -0,0 +1,553 @@ +/* +Generic Identity Security Cloud V2024 API + +Generic API specification for the Identity Security Cloud platform + +API version: v2024 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package api_generic + +import ( + "bytes" + "context" + "io" + "net/http" + "net/url" + "strings" +) + + +// DefaultAPIService DefaultAPI service +type DefaultAPIService service + +type ApiGenericDeleteRequest struct { + ctx context.Context + ApiService *DefaultAPIService + path string +} + +func (r ApiGenericDeleteRequest) Execute() (map[string]interface{}, *http.Response, error) { + return r.ApiService.GenericDeleteExecute(r) +} + +/* +GenericDelete Generic DELETE request + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param path + @return ApiGenericDeleteRequest +*/ +func (a *DefaultAPIService) GenericDelete(ctx context.Context, path string) ApiGenericDeleteRequest { + return ApiGenericDeleteRequest{ + ApiService: a, + ctx: ctx, + path: path, + } +} + +// Execute executes the request +// @return map[string]interface{} +func (a *DefaultAPIService) GenericDeleteExecute(r ApiGenericDeleteRequest) (map[string]interface{}, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodDelete + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue map[string]interface{} + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.GenericDelete") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/{path}" + localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", url.PathEscape(parameterValueToString(r.path, "path")), -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, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGenericGetRequest struct { + ctx context.Context + ApiService *DefaultAPIService + path string +} + +func (r ApiGenericGetRequest) Execute() (map[string]interface{}, *http.Response, error) { + return r.ApiService.GenericGetExecute(r) +} + +/* +GenericGet Generic GET request + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param path + @return ApiGenericGetRequest +*/ +func (a *DefaultAPIService) GenericGet(ctx context.Context, path string) ApiGenericGetRequest { + return ApiGenericGetRequest{ + ApiService: a, + ctx: ctx, + path: path, + } +} + +// Execute executes the request +// @return map[string]interface{} +func (a *DefaultAPIService) GenericGetExecute(r ApiGenericGetRequest) (map[string]interface{}, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue map[string]interface{} + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.GenericGet") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/{path}" + localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", url.PathEscape(parameterValueToString(r.path, "path")), -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, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGenericPatchRequest struct { + ctx context.Context + ApiService *DefaultAPIService + path string + requestBody *map[string]interface{} +} + +func (r ApiGenericPatchRequest) RequestBody(requestBody map[string]interface{}) ApiGenericPatchRequest { + r.requestBody = &requestBody + return r +} + +func (r ApiGenericPatchRequest) Execute() (map[string]interface{}, *http.Response, error) { + return r.ApiService.GenericPatchExecute(r) +} + +/* +GenericPatch Generic PATCH request + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param path + @return ApiGenericPatchRequest +*/ +func (a *DefaultAPIService) GenericPatch(ctx context.Context, path string) ApiGenericPatchRequest { + return ApiGenericPatchRequest{ + ApiService: a, + ctx: ctx, + path: path, + } +} + +// Execute executes the request +// @return map[string]interface{} +func (a *DefaultAPIService) GenericPatchExecute(r ApiGenericPatchRequest) (map[string]interface{}, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPatch + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue map[string]interface{} + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.GenericPatch") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/{path}" + localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", url.PathEscape(parameterValueToString(r.path, "path")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // 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.requestBody + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGenericPostRequest struct { + ctx context.Context + ApiService *DefaultAPIService + path string + requestBody *map[string]interface{} +} + +func (r ApiGenericPostRequest) RequestBody(requestBody map[string]interface{}) ApiGenericPostRequest { + r.requestBody = &requestBody + return r +} + +func (r ApiGenericPostRequest) Execute() (map[string]interface{}, *http.Response, error) { + return r.ApiService.GenericPostExecute(r) +} + +/* +GenericPost Generic POST request + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param path + @return ApiGenericPostRequest +*/ +func (a *DefaultAPIService) GenericPost(ctx context.Context, path string) ApiGenericPostRequest { + return ApiGenericPostRequest{ + ApiService: a, + ctx: ctx, + path: path, + } +} + +// Execute executes the request +// @return map[string]interface{} +func (a *DefaultAPIService) GenericPostExecute(r ApiGenericPostRequest) (map[string]interface{}, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPost + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue map[string]interface{} + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.GenericPost") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/{path}" + localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", url.PathEscape(parameterValueToString(r.path, "path")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // 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.requestBody + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} + +type ApiGenericPutRequest struct { + ctx context.Context + ApiService *DefaultAPIService + path string + requestBody *map[string]interface{} +} + +func (r ApiGenericPutRequest) RequestBody(requestBody map[string]interface{}) ApiGenericPutRequest { + r.requestBody = &requestBody + return r +} + +func (r ApiGenericPutRequest) Execute() (map[string]interface{}, *http.Response, error) { + return r.ApiService.GenericPutExecute(r) +} + +/* +GenericPut Generic PUT request + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @param path + @return ApiGenericPutRequest +*/ +func (a *DefaultAPIService) GenericPut(ctx context.Context, path string) ApiGenericPutRequest { + return ApiGenericPutRequest{ + ApiService: a, + ctx: ctx, + path: path, + } +} + +// Execute executes the request +// @return map[string]interface{} +func (a *DefaultAPIService) GenericPutExecute(r ApiGenericPutRequest) (map[string]interface{}, *http.Response, error) { + var ( + localVarHTTPMethod = http.MethodPut + localVarPostBody interface{} + formFiles []formFile + localVarReturnValue map[string]interface{} + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.GenericPut") + if err != nil { + return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/{path}" + localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", url.PathEscape(parameterValueToString(r.path, "path")), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // 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.requestBody + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil +} diff --git a/api_generic/client.go b/api_generic/client.go new file mode 100644 index 000000000..582f6c77a --- /dev/null +++ b/api_generic/client.go @@ -0,0 +1,740 @@ +/* +Generic Identity Security Cloud V2024 API + +Generic API specification for the Identity Security Cloud platform + +API version: v2024 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package api_generic + +import ( + "bytes" + "context" + "encoding/json" + "encoding/xml" + "errors" + "fmt" + "io" +"io/ioutil" + "log" + "mime/multipart" + "net/http" + "net/http/httputil" + "net/url" + "os" + "path/filepath" + "reflect" + "regexp" + "strconv" + "strings" + "time" + "unicode/utf8" + + "golang.org/x/oauth2" +retryablehttp "github.com/hashicorp/go-retryablehttp" +) + +var ( + JsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?json)`) + XmlCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:[^;]+\+)?xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) +) + +// APIClient manages communication with the Generic Identity Security Cloud V2024 API API vv2024 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + + DefaultAPI *DefaultAPIService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(cfg *Configuration) *APIClient { + if cfg.HTTPClient == nil { + cfg.HTTPClient = retryablehttp.NewClient() + } + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.DefaultAPI = (*DefaultAPIService)(&c.common) + + return c +} + +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{}, style string, 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, style, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToHeaderOrQuery(headerOrQueryParams, keyPrefix, t.Format(time.RFC3339Nano), style, 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 0 || (len(formFiles) > 0) { + if body != nil { + return nil, errors.New("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, errors.New("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) +localVarRequest.Header.Add("X-SailPoint-SDK", "2.1.13") + + if ctx != nil { + // add context to the request + localVarRequest = localVarRequest.WithContext(ctx) + + // Walk through any authentication. + + // OAuth2 authentication + if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { + // We were able to grab an oauth2 token from the context + var latestToken *oauth2.Token + if latestToken, err = tok.Token(); err != nil { + return nil, err + } + + latestToken.SetAuthHeader(localVarRequest) + } +if c.cfg.Token == "" && c.cfg.ClientId != "" && c.cfg.ClientSecret != "" && c.cfg.TokenURL != "" { + auth, err := getAccessToken(c.cfg.ClientId, c.cfg.ClientSecret, c.cfg.TokenURL) + if err != nil { + return nil, err + } + c.cfg.Token = auth + localVarRequest.Header.Add("Authorization", "Bearer "+auth) + } else { + localVarRequest.Header.Add("Authorization", "Bearer "+c.cfg.Token) + } + } + + if _, exists := headerParams["X-SailPoint-Experimental"]; exists && !c.cfg.Experimental { + panic("You are using Experimental APIs. Set configuration.experimental = True to enable these APIs in the SDK.") + } else if _, exists := headerParams["X-SailPoint-Experimental"]; exists && c.cfg.Experimental { + fmt.Fprintf(os.Stdout, "Warning: You are using Experimental APIs\n") + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + return localVarRequest, nil +} + +type AccessToken struct { + AccessToken string `json:"access_token"` + TokenType string `json:"token_type"` + ExpiresIn int `json:"expires_in"` + Scope string `json:"scope"` + TenantId string `json:"tenant_id"` + Pod string `json:"pod"` + StrongAuthSupported bool `json:"strong_auth_supported"` + Org string `json:"org"` + IdentityId string `json:"identity_id"` + UserName string `json:"user_name"` + StrongAuth bool `json:"strong_auth"` + Jti string `json:"jti"` +} + +func getAccessToken(clientId string, clientSecret string, tokenURL string) (string, error) { + requestUrl := tokenURL + method := "POST" + client := &http.Client{} + form := url.Values{ + "grant_type": {"client_credentials"}, + "client_id": {clientId}, + "client_secret": {clientSecret}, + } + req, err := http.NewRequest(method, requestUrl, strings.NewReader(form.Encode())) + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + + if err != nil { + fmt.Println(err) + return "", err + } + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + return "", err + } + defer res.Body.Close() + + body, err := ioutil.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + return "", err + } + + var jsonMap AccessToken + json.Unmarshal([]byte(body), &jsonMap) + + return jsonMap.AccessToken, 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 errors.New("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 errors.New("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 +} + +// 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) { + var bs []byte + bs, err = xml.Marshal(body) + if err == nil { + bodyBuf.Write(bs) + } + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("invalid body type %s\n", 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) +} + +// GenericOpenAPIError Provides access to the body, error and model on returned errors. +type GenericOpenAPIError struct { + body []byte + error string + model interface{} +} + +// Error returns non-empty string if there was an error. +func (e GenericOpenAPIError) Error() string { + return e.error +} + +// Body returns the raw bytes of the response +func (e GenericOpenAPIError) Body() []byte { + return e.body +} + +// Model returns the unpacked model of the error +func (e GenericOpenAPIError) Model() interface{} { + return e.model +} + +// format error message using title and detail when model implements rfc7807 +func formatErrorMessage(status string, v interface{}) string { + str := "" + metaValue := reflect.ValueOf(v).Elem() + + if metaValue.Kind() == reflect.Struct { + field := metaValue.FieldByName("Title") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s", field.Interface()) + } + + field = metaValue.FieldByName("Detail") + if field != (reflect.Value{}) { + str = fmt.Sprintf("%s (%s)", str, field.Interface()) + } + } + + return strings.TrimSpace(fmt.Sprintf("%s %s", status, str)) +} diff --git a/api_generic/configuration.go b/api_generic/configuration.go new file mode 100644 index 000000000..adbe579cd --- /dev/null +++ b/api_generic/configuration.go @@ -0,0 +1,247 @@ +/* +Generic Identity Security Cloud V2024 API + +Generic API specification for the Identity Security Cloud platform + +API version: v2024 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package api_generic + +import ( + "context" + "fmt" + "strings" + + retryablehttp "github.com/hashicorp/go-retryablehttp" +) + +// contextKeys are used to identify the type of value in the context. +// Since these are string, it is possible to get a short description of the +// context key for logging and debugging using key.String(). + +type contextKey string + +func (c contextKey) String() string { + return "auth " + string(c) +} + +var ( + // ContextOAuth2 takes an oauth2.TokenSource as authentication for the request. + ContextOAuth2 = contextKey("token") + + // ContextServerIndex uses a server configuration from the index. + ContextServerIndex = contextKey("serverIndex") + + // ContextOperationServerIndices uses a server configuration from the index mapping. + ContextOperationServerIndices = contextKey("serverOperationIndices") + + // ContextServerVariables overrides a server configuration variables. + ContextServerVariables = contextKey("serverVariables") + + // ContextOperationServerVariables overrides a server configuration variables using operation specific values. + ContextOperationServerVariables = contextKey("serverOperationVariables") +) + +// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth +type BasicAuth struct { + UserName string `json:"userName,omitempty"` + Password string `json:"password,omitempty"` +} + +// APIKey provides API key based authentication to a request passed via context using ContextAPIKey +type APIKey struct { + Key string + Prefix string +} + +// ServerVariable stores the information about a server variable +type ServerVariable struct { + Description string + DefaultValue string + EnumValues []string +} + +// ServerConfiguration stores the information about a server +type ServerConfiguration struct { + URL string + Description string + Variables map[string]ServerVariable +} + +// ServerConfigurations stores multiple ServerConfiguration items +type ServerConfigurations []ServerConfiguration + +// Configuration stores the configuration of the API client +type Configuration struct { + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + Debug bool `json:"debug,omitempty"` + Experimental bool `json:"experimental,omitempty"` + Servers ServerConfigurations + OperationServers map[string]ServerConfigurations + HTTPClient *retryablehttp.Client +ClientId string + ClientSecret string + BaseURL string + TokenURL string + Token string +} + +// NewConfiguration returns a new Configuration object +func NewConfiguration(clientId string, clientSecret string, baseURL string, tokenURL string, token string, experimental bool) *Configuration { + cfg := &Configuration{ +ClientId: clientId, + ClientSecret: clientSecret, + BaseURL: baseURL, + TokenURL: tokenURL, + Token: token, + DefaultHeader: make(map[string]string), + UserAgent: "OpenAPI-Generator/2.1.13/go", + Debug: false, + Experimental: experimental, + Servers: ServerConfigurations{ + { + URL: baseURL, + Description: "This is the production API server.", + Variables: map[string]ServerVariable{ + "tenant": ServerVariable{ + Description: "This is the name of your tenant, typically your company's name.", + DefaultValue: "sailpoint", + }, + }, + }, + { + URL: baseURL, + Description: "This is the V2024 API server.", + Variables: map[string]ServerVariable{ + "apiUrl": ServerVariable{ + Description: "This is the api url of your tenant", + DefaultValue: "sailpoint.api.identitynow.com", + }, + }, + }, + }, + OperationServers: map[string]ServerConfigurations{ + }, + } + return cfg +} + +// AddDefaultHeader adds a new HTTP header to the default header in the request +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value +} + +// URL formats template on a index using given variables +func (sc ServerConfigurations) URL(index int, variables map[string]string) (string, error) { + if index < 0 || len(sc) <= index { + return "", fmt.Errorf("index %v out of range %v", index, len(sc)-1) + } + server := sc[index] + url := server.URL + + // go through variables and replace placeholders + for name, variable := range server.Variables { + if value, ok := variables[name]; ok { + found := bool(len(variable.EnumValues) == 0) + for _, enumValue := range variable.EnumValues { + if value == enumValue { + found = true + } + } + if !found { + return "", fmt.Errorf("the variable %s in the server URL has invalid value %v. Must be %v", name, value, variable.EnumValues) + } + url = strings.Replace(url, "{"+name+"}", value, -1) + } else { + url = strings.Replace(url, "{"+name+"}", variable.DefaultValue, -1) + } + } + return url, nil +} + +// ServerURL returns URL based on server settings +func (c *Configuration) ServerURL(index int, variables map[string]string) (string, error) { + return c.Servers.URL(index, variables) +} + +func getServerIndex(ctx context.Context) (int, error) { + si := ctx.Value(ContextServerIndex) + if si != nil { + if index, ok := si.(int); ok { + return index, nil + } + return 0, reportError("Invalid type %T should be int", si) + } + return 0, nil +} + +func getServerOperationIndex(ctx context.Context, endpoint string) (int, error) { + osi := ctx.Value(ContextOperationServerIndices) + if osi != nil { + if operationIndices, ok := osi.(map[string]int); !ok { + return 0, reportError("Invalid type %T should be map[string]int", osi) + } else { + index, ok := operationIndices[endpoint] + if ok { + return index, nil + } + } + } + return getServerIndex(ctx) +} + +func getServerVariables(ctx context.Context) (map[string]string, error) { + sv := ctx.Value(ContextServerVariables) + if sv != nil { + if variables, ok := sv.(map[string]string); ok { + return variables, nil + } + return nil, reportError("ctx value of ContextServerVariables has invalid type %T should be map[string]string", sv) + } + return nil, nil +} + +func getServerOperationVariables(ctx context.Context, endpoint string) (map[string]string, error) { + osv := ctx.Value(ContextOperationServerVariables) + if osv != nil { + if operationVariables, ok := osv.(map[string]map[string]string); !ok { + return nil, reportError("ctx value of ContextOperationServerVariables has invalid type %T should be map[string]map[string]string", osv) + } else { + variables, ok := operationVariables[endpoint] + if ok { + return variables, nil + } + } + } + return getServerVariables(ctx) +} + +// ServerURLWithContext returns a new server URL given an endpoint +func (c *Configuration) ServerURLWithContext(ctx context.Context, endpoint string) (string, error) { + sc, ok := c.OperationServers[endpoint] + if !ok { + sc = c.Servers + } + + if ctx == nil { + return sc.URL(0, nil) + } + + index, err := getServerOperationIndex(ctx, endpoint) + if err != nil { + return "", err + } + + variables, err := getServerOperationVariables(ctx, endpoint) + if err != nil { + return "", err + } + + return sc.URL(index, variables) +} diff --git a/api_generic/docs/DefaultAPI.md b/api_generic/docs/DefaultAPI.md new file mode 100644 index 000000000..0d02fca65 --- /dev/null +++ b/api_generic/docs/DefaultAPI.md @@ -0,0 +1,359 @@ +# \DefaultAPI + +All URIs are relative to *https://sailpoint.api.identitynow.com/v2024* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**GenericDelete**](DefaultAPI.md#GenericDelete) | **Delete** /{path} | Generic DELETE request +[**GenericGet**](DefaultAPI.md#GenericGet) | **Get** /{path} | Generic GET request +[**GenericPatch**](DefaultAPI.md#GenericPatch) | **Patch** /{path} | Generic PATCH request +[**GenericPost**](DefaultAPI.md#GenericPost) | **Post** /{path} | Generic POST request +[**GenericPut**](DefaultAPI.md#GenericPut) | **Put** /{path} | Generic PUT request + + + +## GenericDelete + +> map[string]interface{} GenericDelete(ctx, path).Execute() + +Generic DELETE request + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openapiclient "github.com/sailpoint-oss/golang-sdk/v2" +) + +func main() { + path := "path_example" // string | + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + resp, r, err := apiClient.DefaultAPI.GenericDelete(context.Background(), path).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DefaultAPI.GenericDelete``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + // response from `GenericDelete`: map[string]interface{} + fmt.Fprintf(os.Stdout, "Response from `DefaultAPI.GenericDelete`: %v\n", resp) +} +``` + +### Path Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**path** | **string** | | + +### Other Parameters + +Other parameters are passed through a pointer to a apiGenericDeleteRequest struct via the builder pattern + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + + +### Return type + +**map[string]interface{}** + +### Authorization + +[userAuth](../README.md#userAuth), [userAuth](../README.md#userAuth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + + +## GenericGet + +> map[string]interface{} GenericGet(ctx, path).Execute() + +Generic GET request + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openapiclient "github.com/sailpoint-oss/golang-sdk/v2" +) + +func main() { + path := "path_example" // string | + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + resp, r, err := apiClient.DefaultAPI.GenericGet(context.Background(), path).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DefaultAPI.GenericGet``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + // response from `GenericGet`: map[string]interface{} + fmt.Fprintf(os.Stdout, "Response from `DefaultAPI.GenericGet`: %v\n", resp) +} +``` + +### Path Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**path** | **string** | | + +### Other Parameters + +Other parameters are passed through a pointer to a apiGenericGetRequest struct via the builder pattern + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + + +### Return type + +**map[string]interface{}** + +### Authorization + +[userAuth](../README.md#userAuth), [userAuth](../README.md#userAuth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + + +## GenericPatch + +> map[string]interface{} GenericPatch(ctx, path).RequestBody(requestBody).Execute() + +Generic PATCH request + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openapiclient "github.com/sailpoint-oss/golang-sdk/v2" +) + +func main() { + path := "path_example" // string | + requestBody := map[string]interface{}{"key": interface{}(123)} // map[string]interface{} | (optional) + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + resp, r, err := apiClient.DefaultAPI.GenericPatch(context.Background(), path).RequestBody(requestBody).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DefaultAPI.GenericPatch``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + // response from `GenericPatch`: map[string]interface{} + fmt.Fprintf(os.Stdout, "Response from `DefaultAPI.GenericPatch`: %v\n", resp) +} +``` + +### Path Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**path** | **string** | | + +### Other Parameters + +Other parameters are passed through a pointer to a apiGenericPatchRequest struct via the builder pattern + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + + **requestBody** | **map[string]interface{}** | | + +### Return type + +**map[string]interface{}** + +### Authorization + +[userAuth](../README.md#userAuth), [userAuth](../README.md#userAuth) + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + + +## GenericPost + +> map[string]interface{} GenericPost(ctx, path).RequestBody(requestBody).Execute() + +Generic POST request + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openapiclient "github.com/sailpoint-oss/golang-sdk/v2" +) + +func main() { + path := "path_example" // string | + requestBody := map[string]interface{}{"key": interface{}(123)} // map[string]interface{} | (optional) + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + resp, r, err := apiClient.DefaultAPI.GenericPost(context.Background(), path).RequestBody(requestBody).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DefaultAPI.GenericPost``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + // response from `GenericPost`: map[string]interface{} + fmt.Fprintf(os.Stdout, "Response from `DefaultAPI.GenericPost`: %v\n", resp) +} +``` + +### Path Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**path** | **string** | | + +### Other Parameters + +Other parameters are passed through a pointer to a apiGenericPostRequest struct via the builder pattern + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + + **requestBody** | **map[string]interface{}** | | + +### Return type + +**map[string]interface{}** + +### Authorization + +[userAuth](../README.md#userAuth), [userAuth](../README.md#userAuth) + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + + +## GenericPut + +> map[string]interface{} GenericPut(ctx, path).RequestBody(requestBody).Execute() + +Generic PUT request + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openapiclient "github.com/sailpoint-oss/golang-sdk/v2" +) + +func main() { + path := "path_example" // string | + requestBody := map[string]interface{}{"key": interface{}(123)} // map[string]interface{} | (optional) + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + resp, r, err := apiClient.DefaultAPI.GenericPut(context.Background(), path).RequestBody(requestBody).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DefaultAPI.GenericPut``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + // response from `GenericPut`: map[string]interface{} + fmt.Fprintf(os.Stdout, "Response from `DefaultAPI.GenericPut`: %v\n", resp) +} +``` + +### Path Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. +**path** | **string** | | + +### Other Parameters + +Other parameters are passed through a pointer to a apiGenericPutRequest struct via the builder pattern + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + + **requestBody** | **map[string]interface{}** | | + +### Return type + +**map[string]interface{}** + +### Authorization + +[userAuth](../README.md#userAuth), [userAuth](../README.md#userAuth) + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + diff --git a/api_generic/git_push.sh b/api_generic/git_push.sh new file mode 100644 index 000000000..33f67d59b --- /dev/null +++ b/api_generic/git_push.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="sailpoint-oss" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="golang-sdk/v2" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=$(git remote) +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' diff --git a/api_generic/response.go b/api_generic/response.go new file mode 100644 index 000000000..6b95aae74 --- /dev/null +++ b/api_generic/response.go @@ -0,0 +1,47 @@ +/* +Generic Identity Security Cloud V2024 API + +Generic API specification for the Identity Security Cloud platform + +API version: v2024 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package api_generic + +import ( + "net/http" +) + +// APIResponse stores the API response returned by the server. +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the OpenAPI operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +// NewAPIResponse returns a new APIResponse object. +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +// NewAPIResponseWithError returns a new APIResponse object with the provided error message. +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/api_generic/test/api_default_test.go b/api_generic/test/api_default_test.go new file mode 100644 index 000000000..5a7d5737c --- /dev/null +++ b/api_generic/test/api_default_test.go @@ -0,0 +1,95 @@ +/* +Generic Identity Security Cloud V2024 API + +Testing DefaultAPIService + +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); + +package api_generic + +import ( + "context" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "testing" + openapiclient "github.com/sailpoint-oss/golang-sdk/v2" +) + +func Test_api_generic_DefaultAPIService(t *testing.T) { + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + + t.Run("Test DefaultAPIService GenericDelete", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var path string + + resp, httpRes, err := apiClient.DefaultAPI.GenericDelete(context.Background(), path).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DefaultAPIService GenericGet", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var path string + + resp, httpRes, err := apiClient.DefaultAPI.GenericGet(context.Background(), path).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DefaultAPIService GenericPatch", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var path string + + resp, httpRes, err := apiClient.DefaultAPI.GenericPatch(context.Background(), path).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DefaultAPIService GenericPost", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var path string + + resp, httpRes, err := apiClient.DefaultAPI.GenericPost(context.Background(), path).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + + t.Run("Test DefaultAPIService GenericPut", func(t *testing.T) { + + t.Skip("skip test") // remove to run test + + var path string + + resp, httpRes, err := apiClient.DefaultAPI.GenericPut(context.Background(), path).Execute() + + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, httpRes.StatusCode) + + }) + +} diff --git a/api_generic/utils.go b/api_generic/utils.go new file mode 100644 index 000000000..f0a0ebece --- /dev/null +++ b/api_generic/utils.go @@ -0,0 +1,361 @@ +/* +Generic Identity Security Cloud V2024 API + +Generic API specification for the Identity Security Cloud platform + +API version: v2024 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package api_generic + +import ( + "bytes" + "encoding/json" + "fmt" + "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 json.Marshal(v.value) +} + +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) +} + +// A wrapper for strict JSON decoding +func newStrictDecoder(data []byte) *json.Decoder { + dec := json.NewDecoder(bytes.NewBuffer(data)) + dec.DisallowUnknownFields() + return dec +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) error { + return fmt.Errorf(format, a...) +} \ No newline at end of file diff --git a/client.go b/client.go index e56777956..82a380acf 100644 --- a/client.go +++ b/client.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/go-retryablehttp" beta "github.com/sailpoint-oss/golang-sdk/v2/api_beta" + generic "github.com/sailpoint-oss/golang-sdk/v2/api_generic" v2024 "github.com/sailpoint-oss/golang-sdk/v2/api_v2024" v3 "github.com/sailpoint-oss/golang-sdk/v2/api_v3" ) @@ -30,16 +31,18 @@ type APIClient struct { // API Services - V3 *v3.APIClient - Beta *beta.APIClient - V2024 *v2024.APIClient - token string + V3 *v3.APIClient + Beta *beta.APIClient + V2024 *v2024.APIClient + Generic *generic.APIClient + token string } type service struct { - client *v3.APIClient - betaClient *beta.APIClient - v2024Client *v2024.APIClient + client *v3.APIClient + betaClient *beta.APIClient + v2024Client *v2024.APIClient + genericClient *generic.APIClient } // NewAPIClient creates a new API client. Requires a userAgent string describing your application. @@ -54,14 +57,17 @@ func NewAPIClient(cfg *Configuration) *APIClient { CV3 := v3.NewConfiguration(cfg.ClientConfiguration.ClientId, cfg.ClientConfiguration.ClientSecret, cfg.ClientConfiguration.BaseURL+"/v3", cfg.ClientConfiguration.TokenURL, cfg.ClientConfiguration.Token, cfg.Experimental) CBeta := beta.NewConfiguration(cfg.ClientConfiguration.ClientId, cfg.ClientConfiguration.ClientSecret, cfg.ClientConfiguration.BaseURL+"/beta", cfg.ClientConfiguration.TokenURL, cfg.ClientConfiguration.Token, cfg.Experimental) CV2024 := v2024.NewConfiguration(cfg.ClientConfiguration.ClientId, cfg.ClientConfiguration.ClientSecret, cfg.ClientConfiguration.BaseURL+"/v2024", cfg.ClientConfiguration.TokenURL, cfg.ClientConfiguration.Token, cfg.Experimental) + CVGeneric := generic.NewConfiguration(cfg.ClientConfiguration.ClientId, cfg.ClientConfiguration.ClientSecret, cfg.ClientConfiguration.BaseURL, cfg.ClientConfiguration.TokenURL, cfg.ClientConfiguration.Token, cfg.Experimental) CV3.HTTPClient = cfg.HTTPClient CBeta.HTTPClient = cfg.HTTPClient CV2024.HTTPClient = cfg.HTTPClient + CVGeneric.HTTPClient = cfg.HTTPClient c.V3 = v3.NewAPIClient(CV3) c.Beta = beta.NewAPIClient(CBeta) c.V2024 = v2024.NewAPIClient(CV2024) + c.Generic = generic.NewAPIClient(CVGeneric) // API Services diff --git a/sdk-resources/generic-api.yaml b/sdk-resources/generic-api.yaml new file mode 100644 index 000000000..4f58a9668 --- /dev/null +++ b/sdk-resources/generic-api.yaml @@ -0,0 +1,163 @@ +openapi: 3.0.1 +info: + title: Generic Identity Security Cloud V2024 API + description: Generic API specification for the Identity Security Cloud platform + termsOfService: https://developer.sailpoint.com/discuss/tos + contact: + name: Developer Relations + url: https://developer.sailpoint.com/discuss/api-help + license: + name: MIT + url: https://opensource.org/licenses/MIT + version: v2024 +servers: +- url: https://{tenant}.api.identitynow.com/v2024 + description: This is the production API server. + variables: + tenant: + default: sailpoint + description: This is the name of your tenant, typically your company's name. +- url: https://{apiUrl}/v2024 + description: This is the V2024 API server. + variables: + apiUrl: + default: sailpoint.api.identitynow.com + description: This is the api url of your tenant + +security: +- userAuth: + - "sp:scopes:all" + +paths: + /{path}: + get: + summary: Generic GET request + operationId: genericGet + parameters: + - name: path + in: path + required: true + schema: + type: string + responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '#/components/schemas/GenericResponse' + post: + summary: Generic POST request + operationId: genericPost + parameters: + - name: path + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/GenericRequest' + responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '#/components/schemas/GenericResponse' + put: + summary: Generic PUT request + operationId: genericPut + parameters: + - name: path + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/GenericRequest' + responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '#/components/schemas/GenericResponse' + patch: + summary: Generic PATCH request + operationId: genericPatch + parameters: + - name: path + in: path + required: true + schema: + type: string + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/GenericRequest' + responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '#/components/schemas/GenericResponse' + delete: + summary: Generic DELETE request + operationId: genericDelete + parameters: + - name: path + in: path + required: true + schema: + type: string + responses: + '200': + description: Successful response + content: + application/json: + schema: + $ref: '#/components/schemas/GenericResponse' + +components: + schemas: + GenericRequest: + type: object + additionalProperties: true + GenericResponse: + type: object + additionalProperties: true + securitySchemes: + userAuth: + type: oauth2 + x-displayName: Personal Access Token + description: OAuth2 Bearer token (JWT) generated using either a personal access token (PAT) or through the authorization code flow. + flows: + clientCredentials: + tokenUrl: https://tenant.api.identitynow.com/oauth/token + scopes: + "sp:scopes:default": "default scope" + "sp:scopes:all": "access to all scopes" + authorizationCode: + authorizationUrl: https://tenant.login.sailpoint.com/oauth/authorize + tokenUrl: https://tenant.api.identitynow.com/oauth/token + scopes: + "sp:scopes:default": "default scope" + "sp:scopes:all": "access to all scopes" + applicationAuth: + type: oauth2 + x-displayName: Client Credentials + description: OAuth2 Bearer token (JWT) generated using client credentials flow. + flows: + clientCredentials: + tokenUrl: https://tenant.api.identitynow.com/oauth/token + scopes: + "sp:scopes:default": "default scope" + "sp:scopes:all": "access to all scopes" \ No newline at end of file diff --git a/sdk-resources/generic-config.yaml b/sdk-resources/generic-config.yaml new file mode 100644 index 000000000..7d3b3f93a --- /dev/null +++ b/sdk-resources/generic-config.yaml @@ -0,0 +1,9 @@ +templateDir: ./sdk-resources/resources +packageName: api_generic +packageVersion: 2.1.13 +generateInterfaces: false +disallowAdditionalPropertiesIfNotPresent: false +useOneOfDiscriminatorLookup: false +enumClassPrefix: true +gitRepoId: golang-sdk/v2 +gitUserId: sailpoint-oss diff --git a/validation_test.go b/validation_test.go index 5610a5fbe..d43c1707a 100644 --- a/validation_test.go +++ b/validation_test.go @@ -163,3 +163,20 @@ func Test_v2024(t *testing.T) { }) } + +func Test_generic(t *testing.T) { + + configuration := NewDefaultConfiguration() + apiClient := NewAPIClient(configuration) + + t.Run("Test List Accounts", func(t *testing.T) { + + resp, r, err := apiClient.Generic.DefaultAPI.GenericGet(context.TODO(), "v2024/accounts").Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "during test`: %v\n", err) + } + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, r.StatusCode) + }) +} From 605a3b82da9981d27e0013fc09805f8f130d1a25 Mon Sep 17 00:00:00 2001 From: Philip Ellis Date: Tue, 15 Oct 2024 17:16:57 -0400 Subject: [PATCH 2/5] updated generic call to use full url --- api_generic/api_default.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/api_generic/api_default.go b/api_generic/api_default.go index b52d21d89..6c6f70fde 100644 --- a/api_generic/api_default.go +++ b/api_generic/api_default.go @@ -164,8 +164,24 @@ func (a *DefaultAPIService) GenericGetExecute(r ApiGenericGetRequest) (map[strin return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} } - localVarPath := localBasePath + "/{path}" - localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", url.PathEscape(parameterValueToString(r.path, "path")), -1) + // Remove the {path} placeholder from localBasePath + localVarPath := strings.TrimSuffix(localBasePath, "/{path}") + + // Append the path parameter directly + if r.path != "" { + // Ensure the path starts with a forward slash + if !strings.HasPrefix(r.path, "/") { + localVarPath += "/" + } + localVarPath += r.path + } + + // URL encode each path segment separately + segments := strings.Split(localVarPath, "/") + for i, segment := range segments { + segments[i] = url.PathEscape(segment) + } + localVarPath = strings.Join(segments, "/") localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} From 5f5f4f676a052cb616e81ae0d997f0cfd62a76b8 Mon Sep 17 00:00:00 2001 From: Philip Ellis Date: Mon, 18 Nov 2024 11:25:15 -0500 Subject: [PATCH 3/5] added logic to postscript to adjust files --- api_generic/.openapi-generator/FILES | 4 +- api_generic/README.md | 1 + api_generic/api/openapi.yaml | 9 +++- api_generic/api_default.go | 40 ++++++++-------- api_generic/docs/DefaultAPI.md | 30 ++++++------ sdk-resources/generic-api.yaml | 9 +++- sdk-resources/postscript.js | 26 ++++++++++ validation_test.go | 71 ++++++++++++++++++++++++++++ 8 files changed, 149 insertions(+), 41 deletions(-) diff --git a/api_generic/.openapi-generator/FILES b/api_generic/.openapi-generator/FILES index 383ba08f9..e0b26054b 100644 --- a/api_generic/.openapi-generator/FILES +++ b/api_generic/.openapi-generator/FILES @@ -1,5 +1,4 @@ .gitignore -.openapi-generator-ignore .travis.yml README.md api/openapi.yaml @@ -7,9 +6,10 @@ api_default.go client.go configuration.go docs/DefaultAPI.md +docs/GenericResponse.md git_push.sh go.mod go.sum +model_generic_response.go response.go -test/api_default_test.go utils.go diff --git a/api_generic/README.md b/api_generic/README.md index 816b79b7a..86f54853d 100644 --- a/api_generic/README.md +++ b/api_generic/README.md @@ -89,6 +89,7 @@ Class | Method | HTTP request | Description ## Documentation For Models + - [GenericResponse](docs/GenericResponse.md) ## Documentation For Authorization diff --git a/api_generic/api/openapi.yaml b/api_generic/api/openapi.yaml index 57f7acbb8..4f9b1ae4d 100644 --- a/api_generic/api/openapi.yaml +++ b/api_generic/api/openapi.yaml @@ -139,8 +139,13 @@ components: additionalProperties: true type: object GenericResponse: - additionalProperties: true - type: object + oneOf: + - additionalProperties: true + type: object + - items: + additionalProperties: true + type: object + type: array securitySchemes: userAuth: description: OAuth2 Bearer token (JWT) generated using either a personal access diff --git a/api_generic/api_default.go b/api_generic/api_default.go index 6c6f70fde..f81da0ffb 100644 --- a/api_generic/api_default.go +++ b/api_generic/api_default.go @@ -29,7 +29,7 @@ type ApiGenericDeleteRequest struct { path string } -func (r ApiGenericDeleteRequest) Execute() (map[string]interface{}, *http.Response, error) { +func (r ApiGenericDeleteRequest) Execute() (*GenericResponse, *http.Response, error) { return r.ApiService.GenericDeleteExecute(r) } @@ -49,13 +49,13 @@ func (a *DefaultAPIService) GenericDelete(ctx context.Context, path string) ApiG } // Execute executes the request -// @return map[string]interface{} -func (a *DefaultAPIService) GenericDeleteExecute(r ApiGenericDeleteRequest) (map[string]interface{}, *http.Response, error) { +// @return GenericResponse +func (a *DefaultAPIService) GenericDeleteExecute(r ApiGenericDeleteRequest) (*GenericResponse, *http.Response, error) { var ( localVarHTTPMethod = http.MethodDelete localVarPostBody interface{} formFiles []formFile - localVarReturnValue map[string]interface{} + localVarReturnValue *GenericResponse ) localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.GenericDelete") @@ -130,7 +130,7 @@ type ApiGenericGetRequest struct { path string } -func (r ApiGenericGetRequest) Execute() (map[string]interface{}, *http.Response, error) { +func (r ApiGenericGetRequest) Execute() (*GenericResponse, *http.Response, error) { return r.ApiService.GenericGetExecute(r) } @@ -150,13 +150,13 @@ func (a *DefaultAPIService) GenericGet(ctx context.Context, path string) ApiGene } // Execute executes the request -// @return map[string]interface{} -func (a *DefaultAPIService) GenericGetExecute(r ApiGenericGetRequest) (map[string]interface{}, *http.Response, error) { +// @return GenericResponse +func (a *DefaultAPIService) GenericGetExecute(r ApiGenericGetRequest) (*GenericResponse, *http.Response, error) { var ( localVarHTTPMethod = http.MethodGet localVarPostBody interface{} formFiles []formFile - localVarReturnValue map[string]interface{} + localVarReturnValue *GenericResponse ) localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.GenericGet") @@ -253,7 +253,7 @@ func (r ApiGenericPatchRequest) RequestBody(requestBody map[string]interface{}) return r } -func (r ApiGenericPatchRequest) Execute() (map[string]interface{}, *http.Response, error) { +func (r ApiGenericPatchRequest) Execute() (*GenericResponse, *http.Response, error) { return r.ApiService.GenericPatchExecute(r) } @@ -273,13 +273,13 @@ func (a *DefaultAPIService) GenericPatch(ctx context.Context, path string) ApiGe } // Execute executes the request -// @return map[string]interface{} -func (a *DefaultAPIService) GenericPatchExecute(r ApiGenericPatchRequest) (map[string]interface{}, *http.Response, error) { +// @return GenericResponse +func (a *DefaultAPIService) GenericPatchExecute(r ApiGenericPatchRequest) (*GenericResponse, *http.Response, error) { var ( localVarHTTPMethod = http.MethodPatch localVarPostBody interface{} formFiles []formFile - localVarReturnValue map[string]interface{} + localVarReturnValue *GenericResponse ) localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.GenericPatch") @@ -362,7 +362,7 @@ func (r ApiGenericPostRequest) RequestBody(requestBody map[string]interface{}) A return r } -func (r ApiGenericPostRequest) Execute() (map[string]interface{}, *http.Response, error) { +func (r ApiGenericPostRequest) Execute() (*GenericResponse, *http.Response, error) { return r.ApiService.GenericPostExecute(r) } @@ -382,13 +382,13 @@ func (a *DefaultAPIService) GenericPost(ctx context.Context, path string) ApiGen } // Execute executes the request -// @return map[string]interface{} -func (a *DefaultAPIService) GenericPostExecute(r ApiGenericPostRequest) (map[string]interface{}, *http.Response, error) { +// @return GenericResponse +func (a *DefaultAPIService) GenericPostExecute(r ApiGenericPostRequest) (*GenericResponse, *http.Response, error) { var ( localVarHTTPMethod = http.MethodPost localVarPostBody interface{} formFiles []formFile - localVarReturnValue map[string]interface{} + localVarReturnValue *GenericResponse ) localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.GenericPost") @@ -471,7 +471,7 @@ func (r ApiGenericPutRequest) RequestBody(requestBody map[string]interface{}) Ap return r } -func (r ApiGenericPutRequest) Execute() (map[string]interface{}, *http.Response, error) { +func (r ApiGenericPutRequest) Execute() (*GenericResponse, *http.Response, error) { return r.ApiService.GenericPutExecute(r) } @@ -491,13 +491,13 @@ func (a *DefaultAPIService) GenericPut(ctx context.Context, path string) ApiGene } // Execute executes the request -// @return map[string]interface{} -func (a *DefaultAPIService) GenericPutExecute(r ApiGenericPutRequest) (map[string]interface{}, *http.Response, error) { +// @return GenericResponse +func (a *DefaultAPIService) GenericPutExecute(r ApiGenericPutRequest) (*GenericResponse, *http.Response, error) { var ( localVarHTTPMethod = http.MethodPut localVarPostBody interface{} formFiles []formFile - localVarReturnValue map[string]interface{} + localVarReturnValue *GenericResponse ) localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "DefaultAPIService.GenericPut") diff --git a/api_generic/docs/DefaultAPI.md b/api_generic/docs/DefaultAPI.md index 0d02fca65..2eccd7bdb 100644 --- a/api_generic/docs/DefaultAPI.md +++ b/api_generic/docs/DefaultAPI.md @@ -14,7 +14,7 @@ Method | HTTP request | Description ## GenericDelete -> map[string]interface{} GenericDelete(ctx, path).Execute() +> GenericResponse GenericDelete(ctx, path).Execute() Generic DELETE request @@ -40,7 +40,7 @@ func main() { fmt.Fprintf(os.Stderr, "Error when calling `DefaultAPI.GenericDelete``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } - // response from `GenericDelete`: map[string]interface{} + // response from `GenericDelete`: GenericResponse fmt.Fprintf(os.Stdout, "Response from `DefaultAPI.GenericDelete`: %v\n", resp) } ``` @@ -64,7 +64,7 @@ Name | Type | Description | Notes ### Return type -**map[string]interface{}** +[**GenericResponse**](GenericResponse.md) ### Authorization @@ -82,7 +82,7 @@ Name | Type | Description | Notes ## GenericGet -> map[string]interface{} GenericGet(ctx, path).Execute() +> GenericResponse GenericGet(ctx, path).Execute() Generic GET request @@ -108,7 +108,7 @@ func main() { fmt.Fprintf(os.Stderr, "Error when calling `DefaultAPI.GenericGet``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } - // response from `GenericGet`: map[string]interface{} + // response from `GenericGet`: GenericResponse fmt.Fprintf(os.Stdout, "Response from `DefaultAPI.GenericGet`: %v\n", resp) } ``` @@ -132,7 +132,7 @@ Name | Type | Description | Notes ### Return type -**map[string]interface{}** +[**GenericResponse**](GenericResponse.md) ### Authorization @@ -150,7 +150,7 @@ Name | Type | Description | Notes ## GenericPatch -> map[string]interface{} GenericPatch(ctx, path).RequestBody(requestBody).Execute() +> GenericResponse GenericPatch(ctx, path).RequestBody(requestBody).Execute() Generic PATCH request @@ -177,7 +177,7 @@ func main() { fmt.Fprintf(os.Stderr, "Error when calling `DefaultAPI.GenericPatch``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } - // response from `GenericPatch`: map[string]interface{} + // response from `GenericPatch`: GenericResponse fmt.Fprintf(os.Stdout, "Response from `DefaultAPI.GenericPatch`: %v\n", resp) } ``` @@ -202,7 +202,7 @@ Name | Type | Description | Notes ### Return type -**map[string]interface{}** +[**GenericResponse**](GenericResponse.md) ### Authorization @@ -220,7 +220,7 @@ Name | Type | Description | Notes ## GenericPost -> map[string]interface{} GenericPost(ctx, path).RequestBody(requestBody).Execute() +> GenericResponse GenericPost(ctx, path).RequestBody(requestBody).Execute() Generic POST request @@ -247,7 +247,7 @@ func main() { fmt.Fprintf(os.Stderr, "Error when calling `DefaultAPI.GenericPost``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } - // response from `GenericPost`: map[string]interface{} + // response from `GenericPost`: GenericResponse fmt.Fprintf(os.Stdout, "Response from `DefaultAPI.GenericPost`: %v\n", resp) } ``` @@ -272,7 +272,7 @@ Name | Type | Description | Notes ### Return type -**map[string]interface{}** +[**GenericResponse**](GenericResponse.md) ### Authorization @@ -290,7 +290,7 @@ Name | Type | Description | Notes ## GenericPut -> map[string]interface{} GenericPut(ctx, path).RequestBody(requestBody).Execute() +> GenericResponse GenericPut(ctx, path).RequestBody(requestBody).Execute() Generic PUT request @@ -317,7 +317,7 @@ func main() { fmt.Fprintf(os.Stderr, "Error when calling `DefaultAPI.GenericPut``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } - // response from `GenericPut`: map[string]interface{} + // response from `GenericPut`: GenericResponse fmt.Fprintf(os.Stdout, "Response from `DefaultAPI.GenericPut`: %v\n", resp) } ``` @@ -342,7 +342,7 @@ Name | Type | Description | Notes ### Return type -**map[string]interface{}** +[**GenericResponse**](GenericResponse.md) ### Authorization diff --git a/sdk-resources/generic-api.yaml b/sdk-resources/generic-api.yaml index 4f58a9668..a9eb97763 100644 --- a/sdk-resources/generic-api.yaml +++ b/sdk-resources/generic-api.yaml @@ -132,8 +132,13 @@ components: type: object additionalProperties: true GenericResponse: - type: object - additionalProperties: true + oneOf: + - type: object + additionalProperties: true + - type: array + items: + additionalProperties: true + type: object securitySchemes: userAuth: type: oauth2 diff --git a/sdk-resources/postscript.js b/sdk-resources/postscript.js index 925861476..dd672cbaa 100644 --- a/sdk-resources/postscript.js +++ b/sdk-resources/postscript.js @@ -22,6 +22,32 @@ const fixFiles = function (myArray) { fs.unlinkSync(file) continue } + + if (file.includes("api_default.go")) { + let rawdata = fs.readFileSync(file).toString(); + let updatedData = rawdata.replace( + /localVarPath\s*:=\s*localBasePath\s*\+\s*"\{path\}"\s*\n\s*localVarPath\s*=\s*strings\.Replace\(localVarPath,\s*"\{\s*\+\s*"path"\s*\+\s*"\}",\s*url\.PathEscape\(parameterValueToString\(r\.path,\s*"path"\)\),\s*-1\)/, + `// Added this code segment to allow for paths to be replaced fully +localVarPath := strings.TrimSuffix(localBasePath, "/{path}") + +if r.path != "" { + // Ensure the path starts with a forward slash + if !strings.HasPrefix(r.path, "/") { + localVarPath += "/" + } + localVarPath += r.path +} + +segments := strings.Split(localVarPath, "/") +for i, segment := range segments { + segments[i] = url.PathEscape(segment) +} +localVarPath = strings.Join(segments, "/") +// Done adding path replacement` + ); + fs.writeFileSync(file, updatedData); + continue; + } let fileOut = []; diff --git a/validation_test.go b/validation_test.go index d43c1707a..83ae4b010 100644 --- a/validation_test.go +++ b/validation_test.go @@ -2,7 +2,9 @@ package sailpoint import ( "context" + "encoding/json" "fmt" + "io" "os" "testing" @@ -179,4 +181,73 @@ func Test_generic(t *testing.T) { require.NotNil(t, resp) assert.Equal(t, 200, r.StatusCode) }) + + t.Run("Test get transforms", func(t *testing.T) { + + resp, r, err := apiClient.Generic.DefaultAPI.GenericGet(context.TODO(), "v2024/transforms").Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "during test`: %v\n", err) + } + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, r.StatusCode) + }) + + t.Run("Test create workflow", func(t *testing.T) { + + jsonStr := `{ + "name": "Send Email2", + "description": "Send an email to the identity who's attributes changed.", + "definition": { + "start": "Send Email Test", + "steps": { + "Send Email": { + "actionId": "sp:send-email", + "attributes": { + "body": "This is a test", + "from": "sailpoint@sailpoint.com", + "recipientId.$": "$.identity.id", + "subject": "test" + }, + "nextStep": "success", + "selectResult": null, + "type": "action" + }, + "success": { + "type": "success" + } + } + }, + "enabled": false, + "trigger": { + "type": "EVENT", + "attributes": { + "id": "idn:identity-attributes-changed", + "filter": "$.changes[?(@.attribute == 'manager')]" + } + } +}` + + var result map[string]interface{} + err := json.Unmarshal([]byte(jsonStr), &result) + if err != nil { + fmt.Println("Error:", err) + return + } + + resp, r, err := apiClient.Generic.DefaultAPI.GenericPost(context.TODO(), "v2024/workflows").RequestBody(result).Execute() + bodyBytes, err := io.ReadAll(r.Body) + if err != nil { + fmt.Println("Error reading response body:", err) + return + } + bodyString := string(bodyBytes) + fmt.Println("Response Body:", bodyString) + if err != nil { + fmt.Fprintf(os.Stderr, "during test`: %v\n", err) + } + require.Nil(t, err) + require.NotNil(t, resp) + assert.Equal(t, 200, r.StatusCode) + }) } From 8a6287510d329af03b985f11f8f64be9aa669871 Mon Sep 17 00:00:00 2001 From: Philip Ellis Date: Mon, 18 Nov 2024 11:25:39 -0500 Subject: [PATCH 4/5] allow for generic response to work with arrays --- api_generic/docs/GenericResponse.md | 30 +++++ api_generic/model_generic_response.go | 157 ++++++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 api_generic/docs/GenericResponse.md create mode 100644 api_generic/model_generic_response.go diff --git a/api_generic/docs/GenericResponse.md b/api_generic/docs/GenericResponse.md new file mode 100644 index 000000000..c0a381960 --- /dev/null +++ b/api_generic/docs/GenericResponse.md @@ -0,0 +1,30 @@ +# GenericResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +## Methods + +### NewGenericResponse + +`func NewGenericResponse() *GenericResponse` + +NewGenericResponse instantiates a new GenericResponse object +This constructor will assign default values to properties that have it defined, +and makes sure properties required by API are set, but the set of arguments +will change when the set of required properties is changed + +### NewGenericResponseWithDefaults + +`func NewGenericResponseWithDefaults() *GenericResponse` + +NewGenericResponseWithDefaults instantiates a new GenericResponse object +This constructor will only assign default values to properties that have it defined, +but it doesn't guarantee that properties required by API are set + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/api_generic/model_generic_response.go b/api_generic/model_generic_response.go new file mode 100644 index 000000000..4240946a1 --- /dev/null +++ b/api_generic/model_generic_response.go @@ -0,0 +1,157 @@ +/* +Generic Identity Security Cloud V2024 API + +Generic API specification for the Identity Security Cloud platform + +API version: v2024 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package api_generic + +import ( + "encoding/json" + "gopkg.in/validator.v2" + "fmt" +) + +// GenericResponse - struct for GenericResponse +type GenericResponse struct { + ArrayOfMapmapOfStringAny *[]map[string]interface{} + MapmapOfStringAny *map[string]interface{} +} + +// []map[string]interface{}AsGenericResponse is a convenience function that returns []map[string]interface{} wrapped in GenericResponse +func ArrayOfMapmapOfStringAnyAsGenericResponse(v *[]map[string]interface{}) GenericResponse { + return GenericResponse{ + ArrayOfMapmapOfStringAny: v, + } +} + +// map[string]interface{}AsGenericResponse is a convenience function that returns map[string]interface{} wrapped in GenericResponse +func MapmapOfStringAnyAsGenericResponse(v *map[string]interface{}) GenericResponse { + return GenericResponse{ + MapmapOfStringAny: v, + } +} + + +// Unmarshal JSON data into one of the pointers in the struct +func (dst *GenericResponse) UnmarshalJSON(data []byte) error { + var err error + match := 0 + // try to unmarshal data into ArrayOfMapmapOfStringAny + err = newStrictDecoder(data).Decode(&dst.ArrayOfMapmapOfStringAny) + if err == nil { + jsonArrayOfMapmapOfStringAny, _ := json.Marshal(dst.ArrayOfMapmapOfStringAny) + if string(jsonArrayOfMapmapOfStringAny) == "{}" { // empty struct + dst.ArrayOfMapmapOfStringAny = nil + } else { + if err = validator.Validate(dst.ArrayOfMapmapOfStringAny); err != nil { + dst.ArrayOfMapmapOfStringAny = nil + } else { + match++ + } + } + } else { + dst.ArrayOfMapmapOfStringAny = nil + } + + // try to unmarshal data into MapmapOfStringAny + err = newStrictDecoder(data).Decode(&dst.MapmapOfStringAny) + if err == nil { + jsonMapmapOfStringAny, _ := json.Marshal(dst.MapmapOfStringAny) + if string(jsonMapmapOfStringAny) == "{}" { // empty struct + dst.MapmapOfStringAny = nil + } else { + if err = validator.Validate(dst.MapmapOfStringAny); err != nil { + dst.MapmapOfStringAny = nil + } else { + match++ + } + } + } else { + dst.MapmapOfStringAny = nil + } + + if match > 1 { // more than 1 match + // reset to nil + dst.ArrayOfMapmapOfStringAny = nil + dst.MapmapOfStringAny = nil + + return fmt.Errorf("data matches more than one schema in oneOf(GenericResponse)") + } else if match == 1 { + return nil // exactly one match + } else { // no match + return fmt.Errorf("data failed to match schemas in oneOf(GenericResponse)") + } +} + +// Marshal data from the first non-nil pointers in the struct to JSON +func (src GenericResponse) MarshalJSON() ([]byte, error) { + if src.ArrayOfMapmapOfStringAny != nil { + return json.Marshal(&src.ArrayOfMapmapOfStringAny) + } + + if src.MapmapOfStringAny != nil { + return json.Marshal(&src.MapmapOfStringAny) + } + + return nil, nil // no data in oneOf schemas +} + +// Get the actual instance +func (obj *GenericResponse) GetActualInstance() (interface{}) { + if obj == nil { + return nil + } + if obj.ArrayOfMapmapOfStringAny != nil { + return obj.ArrayOfMapmapOfStringAny + } + + if obj.MapmapOfStringAny != nil { + return obj.MapmapOfStringAny + } + + // all schemas are nil + return nil +} + +type NullableGenericResponse struct { + value *GenericResponse + isSet bool +} + +func (v NullableGenericResponse) Get() *GenericResponse { + return v.value +} + +func (v *NullableGenericResponse) Set(val *GenericResponse) { + v.value = val + v.isSet = true +} + +func (v NullableGenericResponse) IsSet() bool { + return v.isSet +} + +func (v *NullableGenericResponse) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableGenericResponse(val *GenericResponse) *NullableGenericResponse { + return &NullableGenericResponse{value: val, isSet: true} +} + +func (v NullableGenericResponse) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableGenericResponse) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + + From 7849c9f3793dd29248eb8b91b5ef03befc8b5ca7 Mon Sep 17 00:00:00 2001 From: Philip Ellis Date: Mon, 18 Nov 2024 13:12:00 -0500 Subject: [PATCH 5/5] fixed some small issues in generation and added tests --- api_generic/api_default.go | 81 ++++++++++++++++++++---- sdk-resources/postscript.js | 44 +++++++------ validation_test.go | 123 ++++++++++++++++++++++++------------ 3 files changed, 178 insertions(+), 70 deletions(-) diff --git a/api_generic/api_default.go b/api_generic/api_default.go index f81da0ffb..584618284 100644 --- a/api_generic/api_default.go +++ b/api_generic/api_default.go @@ -63,8 +63,23 @@ func (a *DefaultAPIService) GenericDeleteExecute(r ApiGenericDeleteRequest) (*Ge return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} } - localVarPath := localBasePath + "/{path}" - localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", url.PathEscape(parameterValueToString(r.path, "path")), -1) + // Added this code segment to allow for paths to be replaced fully + localVarPath := strings.TrimSuffix(localBasePath, "/{path}") + + if r.path != "" { + // Ensure the path starts with a forward slash + if !strings.HasPrefix(r.path, "/") { + localVarPath += "/" + } + localVarPath += r.path + } + + segments := strings.Split(localVarPath, "/") + for i, segment := range segments { + segments[i] = url.PathEscape(segment) + } + localVarPath = strings.Join(segments, "/") + // Done adding path replacement localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -164,10 +179,9 @@ func (a *DefaultAPIService) GenericGetExecute(r ApiGenericGetRequest) (*GenericR return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} } - // Remove the {path} placeholder from localBasePath + // Added this code segment to allow for paths to be replaced fully localVarPath := strings.TrimSuffix(localBasePath, "/{path}") - // Append the path parameter directly if r.path != "" { // Ensure the path starts with a forward slash if !strings.HasPrefix(r.path, "/") { @@ -176,12 +190,12 @@ func (a *DefaultAPIService) GenericGetExecute(r ApiGenericGetRequest) (*GenericR localVarPath += r.path } - // URL encode each path segment separately segments := strings.Split(localVarPath, "/") for i, segment := range segments { segments[i] = url.PathEscape(segment) } localVarPath = strings.Join(segments, "/") + // Done adding path replacement localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -287,8 +301,23 @@ func (a *DefaultAPIService) GenericPatchExecute(r ApiGenericPatchRequest) (*Gene return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} } - localVarPath := localBasePath + "/{path}" - localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", url.PathEscape(parameterValueToString(r.path, "path")), -1) + // Added this code segment to allow for paths to be replaced fully + localVarPath := strings.TrimSuffix(localBasePath, "/{path}") + + if r.path != "" { + // Ensure the path starts with a forward slash + if !strings.HasPrefix(r.path, "/") { + localVarPath += "/" + } + localVarPath += r.path + } + + segments := strings.Split(localVarPath, "/") + for i, segment := range segments { + segments[i] = url.PathEscape(segment) + } + localVarPath = strings.Join(segments, "/") + // Done adding path replacement localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -396,8 +425,23 @@ func (a *DefaultAPIService) GenericPostExecute(r ApiGenericPostRequest) (*Generi return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} } - localVarPath := localBasePath + "/{path}" - localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", url.PathEscape(parameterValueToString(r.path, "path")), -1) + // Added this code segment to allow for paths to be replaced fully + localVarPath := strings.TrimSuffix(localBasePath, "/{path}") + + if r.path != "" { + // Ensure the path starts with a forward slash + if !strings.HasPrefix(r.path, "/") { + localVarPath += "/" + } + localVarPath += r.path + } + + segments := strings.Split(localVarPath, "/") + for i, segment := range segments { + segments[i] = url.PathEscape(segment) + } + localVarPath = strings.Join(segments, "/") + // Done adding path replacement localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -505,8 +549,23 @@ func (a *DefaultAPIService) GenericPutExecute(r ApiGenericPutRequest) (*GenericR return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} } - localVarPath := localBasePath + "/{path}" - localVarPath = strings.Replace(localVarPath, "{"+"path"+"}", url.PathEscape(parameterValueToString(r.path, "path")), -1) + // Added this code segment to allow for paths to be replaced fully + localVarPath := strings.TrimSuffix(localBasePath, "/{path}") + + if r.path != "" { + // Ensure the path starts with a forward slash + if !strings.HasPrefix(r.path, "/") { + localVarPath += "/" + } + localVarPath += r.path + } + + segments := strings.Split(localVarPath, "/") + for i, segment := range segments { + segments[i] = url.PathEscape(segment) + } + localVarPath = strings.Join(segments, "/") + // Done adding path replacement localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} diff --git a/sdk-resources/postscript.js b/sdk-resources/postscript.js index dd672cbaa..2cca023c7 100644 --- a/sdk-resources/postscript.js +++ b/sdk-resources/postscript.js @@ -22,30 +22,36 @@ const fixFiles = function (myArray) { fs.unlinkSync(file) continue } - + if (file.includes("api_default.go")) { - let rawdata = fs.readFileSync(file).toString(); + let rawdata = fs.readFileSync(file, 'utf8'); let updatedData = rawdata.replace( - /localVarPath\s*:=\s*localBasePath\s*\+\s*"\{path\}"\s*\n\s*localVarPath\s*=\s*strings\.Replace\(localVarPath,\s*"\{\s*\+\s*"path"\s*\+\s*"\}",\s*url\.PathEscape\(parameterValueToString\(r\.path,\s*"path"\)\),\s*-1\)/, + /localVarPath\s*:=\s*localBasePath\s*\+\s*"\/\{path\}"\s*\n\s*localVarPath\s*=\s*strings\.Replace\(localVarPath,\s*"\{"\s*\+\s*"path"\s*\+\s*"\}",\s*url\.PathEscape\(parameterValueToString\(r\.path,\s*"path"\)\),\s*-1\)/g, `// Added this code segment to allow for paths to be replaced fully -localVarPath := strings.TrimSuffix(localBasePath, "/{path}") - -if r.path != "" { - // Ensure the path starts with a forward slash - if !strings.HasPrefix(r.path, "/") { - localVarPath += "/" + localVarPath := strings.TrimSuffix(localBasePath, "/{path}") + + if r.path != "" { + // Ensure the path starts with a forward slash + if !strings.HasPrefix(r.path, "/") { + localVarPath += "/" + } + localVarPath += r.path } - localVarPath += r.path -} - -segments := strings.Split(localVarPath, "/") -for i, segment := range segments { - segments[i] = url.PathEscape(segment) -} -localVarPath = strings.Join(segments, "/") -// Done adding path replacement` + + segments := strings.Split(localVarPath, "/") + for i, segment := range segments { + segments[i] = url.PathEscape(segment) + } + localVarPath = strings.Join(segments, "/") + // Done adding path replacement` ); - fs.writeFileSync(file, updatedData); + + if (rawdata !== updatedData) { + fs.writeFileSync(file, updatedData, 'utf8'); + console.log(`Updated ${file}`); + } else { + console.log(`No changes needed in ${file}`); + } continue; } diff --git a/validation_test.go b/validation_test.go index 83ae4b010..c47813776 100644 --- a/validation_test.go +++ b/validation_test.go @@ -4,11 +4,12 @@ import ( "context" "encoding/json" "fmt" - "io" + "math/rand" "os" "testing" beta "github.com/sailpoint-oss/golang-sdk/v2/api_beta" + v2024 "github.com/sailpoint-oss/golang-sdk/v2/api_v2024" v3 "github.com/sailpoint-oss/golang-sdk/v2/api_v3" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -194,39 +195,42 @@ func Test_generic(t *testing.T) { }) t.Run("Test create workflow", func(t *testing.T) { + // Generate a random string for the workflow name + randomName := fmt.Sprintf("Test Workflow %s", randString(8)) - jsonStr := `{ - "name": "Send Email2", - "description": "Send an email to the identity who's attributes changed.", - "definition": { - "start": "Send Email Test", - "steps": { - "Send Email": { - "actionId": "sp:send-email", - "attributes": { - "body": "This is a test", - "from": "sailpoint@sailpoint.com", - "recipientId.$": "$.identity.id", - "subject": "test" - }, - "nextStep": "success", - "selectResult": null, - "type": "action" - }, - "success": { - "type": "success" - } - } - }, - "enabled": false, - "trigger": { - "type": "EVENT", - "attributes": { - "id": "idn:identity-attributes-changed", - "filter": "$.changes[?(@.attribute == 'manager')]" - } - } -}` + jsonStr := fmt.Sprintf(` + { + "name": "%s", + "description": "Send an email to the identity who's attributes changed.", + "definition": { + "start": "Send Email Test", + "steps": { + "Send Email": { + "actionId": "sp:send-email", + "attributes": { + "body": "This is a test", + "from": "sailpoint@sailpoint.com", + "recipientId.$": "$.identity.id", + "subject": "test" + }, + "nextStep": "success", + "selectResult": null, + "type": "action" + }, + "success": { + "type": "success" + } + } + }, + "enabled": false, + "trigger": { + "type": "EVENT", + "attributes": { + "id": "idn:identity-attributes-changed", + "filter": "$.changes[?(@.attribute == 'manager')]" + } + } + }`, randomName) var result map[string]interface{} err := json.Unmarshal([]byte(jsonStr), &result) @@ -236,18 +240,57 @@ func Test_generic(t *testing.T) { } resp, r, err := apiClient.Generic.DefaultAPI.GenericPost(context.TODO(), "v2024/workflows").RequestBody(result).Execute() - bodyBytes, err := io.ReadAll(r.Body) - if err != nil { - fmt.Println("Error reading response body:", err) - return - } - bodyString := string(bodyBytes) - fmt.Println("Response Body:", bodyString) if err != nil { fmt.Fprintf(os.Stderr, "during test`: %v\n", err) } require.Nil(t, err) require.NotNil(t, resp) assert.Equal(t, 200, r.StatusCode) + + getResp, r, err := apiClient.Generic.DefaultAPI.GenericGet(context.TODO(), "v2024/workflows").Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "during test: %v\n", err) + t.FailNow() + } + require.Nil(t, err) + require.NotNil(t, getResp) + assert.Equal(t, 200, r.StatusCode) + + // Convert getResp to []v2024.Workflow + jsonBytes, err := getResp.MarshalJSON() + if err != nil { + fmt.Fprintf(os.Stderr, "error marshaling response: %v\n", err) + t.FailNow() + } + + var response []v2024.Workflow + err = json.Unmarshal(jsonBytes, &response) + if err != nil { + fmt.Fprintf(os.Stderr, "error unmarshaling response: %v\n", err) + t.FailNow() + } + + for _, wf := range response { + if *wf.Name == randomName { + _, r, err := apiClient.Generic.DefaultAPI.GenericDelete(context.TODO(), "v2024/workflows/"+*wf.Id).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "during test: %v\n", err) + t.FailNow() + } + require.Nil(t, err) + assert.Equal(t, 204, r.StatusCode) + } + } }) + +} + +// Helper function to generate a random string +func randString(n int) string { + const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + b := make([]byte, n) + for i := range b { + b[i] = letterBytes[rand.Intn(len(letterBytes))] + } + return string(b) }