|
| 1 | +import { BaseAPIRequestFactory } from "../../datadog-api-client-common/baseapi"; |
| 2 | +import { |
| 3 | + Configuration, |
| 4 | + applySecurityAuthentication, |
| 5 | +} from "../../datadog-api-client-common/configuration"; |
| 6 | +import { |
| 7 | + RequestContext, |
| 8 | + HttpMethod, |
| 9 | + ResponseContext, |
| 10 | +} from "../../datadog-api-client-common/http/http"; |
| 11 | + |
| 12 | +import { logger } from "../../../logger"; |
| 13 | +import { ObjectSerializer } from "../models/ObjectSerializer"; |
| 14 | +import { ApiException } from "../../datadog-api-client-common/exception"; |
| 15 | + |
| 16 | +import { APIErrorResponse } from "../models/APIErrorResponse"; |
| 17 | +import { AWSCloudAuthPersonaMappingsResponse } from "../models/AWSCloudAuthPersonaMappingsResponse"; |
| 18 | +import { JSONAPIErrorResponse } from "../models/JSONAPIErrorResponse"; |
| 19 | + |
| 20 | +export class CloudAuthenticationApiRequestFactory extends BaseAPIRequestFactory { |
| 21 | + public async listAWSCloudAuthPersonaMappings( |
| 22 | + _options?: Configuration |
| 23 | + ): Promise<RequestContext> { |
| 24 | + const _config = _options || this.configuration; |
| 25 | + |
| 26 | + logger.warn("Using unstable operation 'listAWSCloudAuthPersonaMappings'"); |
| 27 | + if (!_config.unstableOperations["v2.listAWSCloudAuthPersonaMappings"]) { |
| 28 | + throw new Error( |
| 29 | + "Unstable operation 'listAWSCloudAuthPersonaMappings' is disabled" |
| 30 | + ); |
| 31 | + } |
| 32 | + |
| 33 | + // Path Params |
| 34 | + const localVarPath = "/api/v2/cloud_auth/aws/persona_mapping"; |
| 35 | + |
| 36 | + // Make Request Context |
| 37 | + const requestContext = _config |
| 38 | + .getServer("v2.CloudAuthenticationApi.listAWSCloudAuthPersonaMappings") |
| 39 | + .makeRequestContext(localVarPath, HttpMethod.GET); |
| 40 | + requestContext.setHeaderParam("Accept", "application/json"); |
| 41 | + requestContext.setHttpConfig(_config.httpConfig); |
| 42 | + |
| 43 | + // Apply auth methods |
| 44 | + applySecurityAuthentication(_config, requestContext, [ |
| 45 | + "apiKeyAuth", |
| 46 | + "appKeyAuth", |
| 47 | + ]); |
| 48 | + |
| 49 | + return requestContext; |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +export class CloudAuthenticationApiResponseProcessor { |
| 54 | + /** |
| 55 | + * Unwraps the actual response sent by the server from the response context and deserializes the response content |
| 56 | + * to the expected objects |
| 57 | + * |
| 58 | + * @params response Response returned by the server for a request to listAWSCloudAuthPersonaMappings |
| 59 | + * @throws ApiException if the response code was not in [200, 299] |
| 60 | + */ |
| 61 | + public async listAWSCloudAuthPersonaMappings( |
| 62 | + response: ResponseContext |
| 63 | + ): Promise<AWSCloudAuthPersonaMappingsResponse> { |
| 64 | + const contentType = ObjectSerializer.normalizeMediaType( |
| 65 | + response.headers["content-type"] |
| 66 | + ); |
| 67 | + if (response.httpStatusCode === 200) { |
| 68 | + const body: AWSCloudAuthPersonaMappingsResponse = |
| 69 | + ObjectSerializer.deserialize( |
| 70 | + ObjectSerializer.parse(await response.body.text(), contentType), |
| 71 | + "AWSCloudAuthPersonaMappingsResponse" |
| 72 | + ) as AWSCloudAuthPersonaMappingsResponse; |
| 73 | + return body; |
| 74 | + } |
| 75 | + if (response.httpStatusCode === 400 || response.httpStatusCode === 403) { |
| 76 | + const bodyText = ObjectSerializer.parse( |
| 77 | + await response.body.text(), |
| 78 | + contentType |
| 79 | + ); |
| 80 | + let body: JSONAPIErrorResponse; |
| 81 | + try { |
| 82 | + body = ObjectSerializer.deserialize( |
| 83 | + bodyText, |
| 84 | + "JSONAPIErrorResponse" |
| 85 | + ) as JSONAPIErrorResponse; |
| 86 | + } catch (error) { |
| 87 | + logger.debug(`Got error deserializing error: ${error}`); |
| 88 | + throw new ApiException<JSONAPIErrorResponse>( |
| 89 | + response.httpStatusCode, |
| 90 | + bodyText |
| 91 | + ); |
| 92 | + } |
| 93 | + throw new ApiException<JSONAPIErrorResponse>( |
| 94 | + response.httpStatusCode, |
| 95 | + body |
| 96 | + ); |
| 97 | + } |
| 98 | + if (response.httpStatusCode === 429) { |
| 99 | + const bodyText = ObjectSerializer.parse( |
| 100 | + await response.body.text(), |
| 101 | + contentType |
| 102 | + ); |
| 103 | + let body: APIErrorResponse; |
| 104 | + try { |
| 105 | + body = ObjectSerializer.deserialize( |
| 106 | + bodyText, |
| 107 | + "APIErrorResponse" |
| 108 | + ) as APIErrorResponse; |
| 109 | + } catch (error) { |
| 110 | + logger.debug(`Got error deserializing error: ${error}`); |
| 111 | + throw new ApiException<APIErrorResponse>( |
| 112 | + response.httpStatusCode, |
| 113 | + bodyText |
| 114 | + ); |
| 115 | + } |
| 116 | + throw new ApiException<APIErrorResponse>(response.httpStatusCode, body); |
| 117 | + } |
| 118 | + |
| 119 | + // Work around for missing responses in specification, e.g. for petstore.yaml |
| 120 | + if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { |
| 121 | + const body: AWSCloudAuthPersonaMappingsResponse = |
| 122 | + ObjectSerializer.deserialize( |
| 123 | + ObjectSerializer.parse(await response.body.text(), contentType), |
| 124 | + "AWSCloudAuthPersonaMappingsResponse", |
| 125 | + "" |
| 126 | + ) as AWSCloudAuthPersonaMappingsResponse; |
| 127 | + return body; |
| 128 | + } |
| 129 | + |
| 130 | + const body = (await response.body.text()) || ""; |
| 131 | + throw new ApiException<string>( |
| 132 | + response.httpStatusCode, |
| 133 | + 'Unknown API Status Code!\nBody: "' + body + '"' |
| 134 | + ); |
| 135 | + } |
| 136 | +} |
| 137 | + |
| 138 | +export class CloudAuthenticationApi { |
| 139 | + private requestFactory: CloudAuthenticationApiRequestFactory; |
| 140 | + private responseProcessor: CloudAuthenticationApiResponseProcessor; |
| 141 | + private configuration: Configuration; |
| 142 | + |
| 143 | + public constructor( |
| 144 | + configuration: Configuration, |
| 145 | + requestFactory?: CloudAuthenticationApiRequestFactory, |
| 146 | + responseProcessor?: CloudAuthenticationApiResponseProcessor |
| 147 | + ) { |
| 148 | + this.configuration = configuration; |
| 149 | + this.requestFactory = |
| 150 | + requestFactory || new CloudAuthenticationApiRequestFactory(configuration); |
| 151 | + this.responseProcessor = |
| 152 | + responseProcessor || new CloudAuthenticationApiResponseProcessor(); |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * List all AWS cloud authentication persona mappings. This endpoint retrieves all configured persona mappings that associate AWS IAM principals with Datadog users. |
| 157 | + * @param param The request object |
| 158 | + */ |
| 159 | + public listAWSCloudAuthPersonaMappings( |
| 160 | + options?: Configuration |
| 161 | + ): Promise<AWSCloudAuthPersonaMappingsResponse> { |
| 162 | + const requestContextPromise = |
| 163 | + this.requestFactory.listAWSCloudAuthPersonaMappings(options); |
| 164 | + return requestContextPromise.then((requestContext) => { |
| 165 | + return this.configuration.httpApi |
| 166 | + .send(requestContext) |
| 167 | + .then((responseContext) => { |
| 168 | + return this.responseProcessor.listAWSCloudAuthPersonaMappings( |
| 169 | + responseContext |
| 170 | + ); |
| 171 | + }); |
| 172 | + }); |
| 173 | + } |
| 174 | +} |
0 commit comments