|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. |
| 2 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 3 | +// Copyright 2019-Present Datadog, Inc. |
| 4 | + |
| 5 | +package datadogV2 |
| 6 | + |
| 7 | +import ( |
| 8 | + _context "context" |
| 9 | + _fmt "fmt" |
| 10 | + _log "log" |
| 11 | + _nethttp "net/http" |
| 12 | + _neturl "net/url" |
| 13 | + |
| 14 | + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" |
| 15 | +) |
| 16 | + |
| 17 | +// CloudAuthenticationApi service type |
| 18 | +type CloudAuthenticationApi datadog.Service |
| 19 | + |
| 20 | +// ListAWSCloudAuthPersonaMappings List AWS cloud authentication persona mappings. |
| 21 | +// List all AWS cloud authentication persona mappings. This endpoint retrieves all configured persona mappings that associate AWS IAM principals with Datadog users. |
| 22 | +func (a *CloudAuthenticationApi) ListAWSCloudAuthPersonaMappings(ctx _context.Context) (AWSCloudAuthPersonaMappingsResponse, *_nethttp.Response, error) { |
| 23 | + var ( |
| 24 | + localVarHTTPMethod = _nethttp.MethodGet |
| 25 | + localVarPostBody interface{} |
| 26 | + localVarReturnValue AWSCloudAuthPersonaMappingsResponse |
| 27 | + ) |
| 28 | + |
| 29 | + operationId := "v2.ListAWSCloudAuthPersonaMappings" |
| 30 | + isOperationEnabled := a.Client.Cfg.IsUnstableOperationEnabled(operationId) |
| 31 | + if !isOperationEnabled { |
| 32 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} |
| 33 | + } |
| 34 | + if isOperationEnabled && a.Client.Cfg.Debug { |
| 35 | + _log.Printf("WARNING: Using unstable operation '%s'", operationId) |
| 36 | + } |
| 37 | + |
| 38 | + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.CloudAuthenticationApi.ListAWSCloudAuthPersonaMappings") |
| 39 | + if err != nil { |
| 40 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} |
| 41 | + } |
| 42 | + |
| 43 | + localVarPath := localBasePath + "/api/v2/cloud_auth/aws/persona_mapping" |
| 44 | + |
| 45 | + localVarHeaderParams := make(map[string]string) |
| 46 | + localVarQueryParams := _neturl.Values{} |
| 47 | + localVarFormParams := _neturl.Values{} |
| 48 | + localVarHeaderParams["Accept"] = "application/json" |
| 49 | + |
| 50 | + if a.Client.Cfg.DelegatedTokenConfig != nil { |
| 51 | + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) |
| 52 | + if err != nil { |
| 53 | + return localVarReturnValue, nil, err |
| 54 | + } |
| 55 | + } else { |
| 56 | + datadog.SetAuthKeys( |
| 57 | + ctx, |
| 58 | + &localVarHeaderParams, |
| 59 | + [2]string{"apiKeyAuth", "DD-API-KEY"}, |
| 60 | + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, |
| 61 | + ) |
| 62 | + } |
| 63 | + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) |
| 64 | + if err != nil { |
| 65 | + return localVarReturnValue, nil, err |
| 66 | + } |
| 67 | + |
| 68 | + localVarHTTPResponse, err := a.Client.CallAPI(req) |
| 69 | + if err != nil || localVarHTTPResponse == nil { |
| 70 | + return localVarReturnValue, localVarHTTPResponse, err |
| 71 | + } |
| 72 | + |
| 73 | + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) |
| 74 | + if err != nil { |
| 75 | + return localVarReturnValue, localVarHTTPResponse, err |
| 76 | + } |
| 77 | + |
| 78 | + if localVarHTTPResponse.StatusCode >= 300 { |
| 79 | + newErr := datadog.GenericOpenAPIError{ |
| 80 | + ErrorBody: localVarBody, |
| 81 | + ErrorMessage: localVarHTTPResponse.Status, |
| 82 | + } |
| 83 | + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 { |
| 84 | + var v JSONAPIErrorResponse |
| 85 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 86 | + if err != nil { |
| 87 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 88 | + } |
| 89 | + newErr.ErrorModel = v |
| 90 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 91 | + } |
| 92 | + if localVarHTTPResponse.StatusCode == 429 { |
| 93 | + var v APIErrorResponse |
| 94 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 95 | + if err != nil { |
| 96 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 97 | + } |
| 98 | + newErr.ErrorModel = v |
| 99 | + } |
| 100 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 101 | + } |
| 102 | + |
| 103 | + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 104 | + if err != nil { |
| 105 | + newErr := datadog.GenericOpenAPIError{ |
| 106 | + ErrorBody: localVarBody, |
| 107 | + ErrorMessage: err.Error(), |
| 108 | + } |
| 109 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 110 | + } |
| 111 | + |
| 112 | + return localVarReturnValue, localVarHTTPResponse, nil |
| 113 | +} |
| 114 | + |
| 115 | +// NewCloudAuthenticationApi Returns NewCloudAuthenticationApi. |
| 116 | +func NewCloudAuthenticationApi(client *datadog.APIClient) *CloudAuthenticationApi { |
| 117 | + return &CloudAuthenticationApi{ |
| 118 | + Client: client, |
| 119 | + } |
| 120 | +} |
0 commit comments