UNPKG

cdk-ssm-secure-iam-access-key

Version:

Creates an IAM Access Key for a provided IAM User and stores the result in an SSM SecureString Parameter

347 lines (346 loc) 14.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.de_LogoutCommand = exports.de_ListAccountsCommand = exports.de_ListAccountRolesCommand = exports.de_GetRoleCredentialsCommand = exports.se_LogoutCommand = exports.se_ListAccountsCommand = exports.se_ListAccountRolesCommand = exports.se_GetRoleCredentialsCommand = void 0; const core_1 = require("@smithy/core"); const smithy_client_1 = require("@smithy/smithy-client"); const models_0_1 = require("../models/models_0"); const SSOServiceException_1 = require("../models/SSOServiceException"); const se_GetRoleCredentialsCommand = async (input, context) => { const b = (0, core_1.requestBuilder)(input, context); const headers = (0, smithy_client_1.map)({}, isSerializableHeaderValue, { [_xasbt]: input[_aT], }); b.bp("/federation/credentials"); const query = (0, smithy_client_1.map)({ [_rn]: [, (0, smithy_client_1.expectNonNull)(input[_rN], `roleName`)], [_ai]: [, (0, smithy_client_1.expectNonNull)(input[_aI], `accountId`)], }); let body; b.m("GET").h(headers).q(query).b(body); return b.build(); }; exports.se_GetRoleCredentialsCommand = se_GetRoleCredentialsCommand; const se_ListAccountRolesCommand = async (input, context) => { const b = (0, core_1.requestBuilder)(input, context); const headers = (0, smithy_client_1.map)({}, isSerializableHeaderValue, { [_xasbt]: input[_aT], }); b.bp("/assignment/roles"); const query = (0, smithy_client_1.map)({ [_nt]: [, input[_nT]], [_mr]: [() => input.maxResults !== void 0, () => input[_mR].toString()], [_ai]: [, (0, smithy_client_1.expectNonNull)(input[_aI], `accountId`)], }); let body; b.m("GET").h(headers).q(query).b(body); return b.build(); }; exports.se_ListAccountRolesCommand = se_ListAccountRolesCommand; const se_ListAccountsCommand = async (input, context) => { const b = (0, core_1.requestBuilder)(input, context); const headers = (0, smithy_client_1.map)({}, isSerializableHeaderValue, { [_xasbt]: input[_aT], }); b.bp("/assignment/accounts"); const query = (0, smithy_client_1.map)({ [_nt]: [, input[_nT]], [_mr]: [() => input.maxResults !== void 0, () => input[_mR].toString()], }); let body; b.m("GET").h(headers).q(query).b(body); return b.build(); }; exports.se_ListAccountsCommand = se_ListAccountsCommand; const se_LogoutCommand = async (input, context) => { const b = (0, core_1.requestBuilder)(input, context); const headers = (0, smithy_client_1.map)({}, isSerializableHeaderValue, { [_xasbt]: input[_aT], }); b.bp("/logout"); let body; b.m("POST").h(headers).b(body); return b.build(); }; exports.se_LogoutCommand = se_LogoutCommand; const de_GetRoleCredentialsCommand = async (output, context) => { if (output.statusCode !== 200 && output.statusCode >= 300) { return de_GetRoleCredentialsCommandError(output, context); } const contents = (0, smithy_client_1.map)({ $metadata: deserializeMetadata(output), }); const data = (0, smithy_client_1.expectNonNull)((0, smithy_client_1.expectObject)(await parseBody(output.body, context)), "body"); const doc = (0, smithy_client_1.take)(data, { roleCredentials: smithy_client_1._json, }); Object.assign(contents, doc); return contents; }; exports.de_GetRoleCredentialsCommand = de_GetRoleCredentialsCommand; const de_GetRoleCredentialsCommandError = async (output, context) => { const parsedOutput = { ...output, body: await parseErrorBody(output.body, context), }; const errorCode = loadRestJsonErrorCode(output, parsedOutput.body); switch (errorCode) { case "InvalidRequestException": case "com.amazonaws.sso#InvalidRequestException": throw await de_InvalidRequestExceptionRes(parsedOutput, context); case "ResourceNotFoundException": case "com.amazonaws.sso#ResourceNotFoundException": throw await de_ResourceNotFoundExceptionRes(parsedOutput, context); case "TooManyRequestsException": case "com.amazonaws.sso#TooManyRequestsException": throw await de_TooManyRequestsExceptionRes(parsedOutput, context); case "UnauthorizedException": case "com.amazonaws.sso#UnauthorizedException": throw await de_UnauthorizedExceptionRes(parsedOutput, context); default: const parsedBody = parsedOutput.body; return throwDefaultError({ output, parsedBody, errorCode, }); } }; const de_ListAccountRolesCommand = async (output, context) => { if (output.statusCode !== 200 && output.statusCode >= 300) { return de_ListAccountRolesCommandError(output, context); } const contents = (0, smithy_client_1.map)({ $metadata: deserializeMetadata(output), }); const data = (0, smithy_client_1.expectNonNull)((0, smithy_client_1.expectObject)(await parseBody(output.body, context)), "body"); const doc = (0, smithy_client_1.take)(data, { nextToken: smithy_client_1.expectString, roleList: smithy_client_1._json, }); Object.assign(contents, doc); return contents; }; exports.de_ListAccountRolesCommand = de_ListAccountRolesCommand; const de_ListAccountRolesCommandError = async (output, context) => { const parsedOutput = { ...output, body: await parseErrorBody(output.body, context), }; const errorCode = loadRestJsonErrorCode(output, parsedOutput.body); switch (errorCode) { case "InvalidRequestException": case "com.amazonaws.sso#InvalidRequestException": throw await de_InvalidRequestExceptionRes(parsedOutput, context); case "ResourceNotFoundException": case "com.amazonaws.sso#ResourceNotFoundException": throw await de_ResourceNotFoundExceptionRes(parsedOutput, context); case "TooManyRequestsException": case "com.amazonaws.sso#TooManyRequestsException": throw await de_TooManyRequestsExceptionRes(parsedOutput, context); case "UnauthorizedException": case "com.amazonaws.sso#UnauthorizedException": throw await de_UnauthorizedExceptionRes(parsedOutput, context); default: const parsedBody = parsedOutput.body; return throwDefaultError({ output, parsedBody, errorCode, }); } }; const de_ListAccountsCommand = async (output, context) => { if (output.statusCode !== 200 && output.statusCode >= 300) { return de_ListAccountsCommandError(output, context); } const contents = (0, smithy_client_1.map)({ $metadata: deserializeMetadata(output), }); const data = (0, smithy_client_1.expectNonNull)((0, smithy_client_1.expectObject)(await parseBody(output.body, context)), "body"); const doc = (0, smithy_client_1.take)(data, { accountList: smithy_client_1._json, nextToken: smithy_client_1.expectString, }); Object.assign(contents, doc); return contents; }; exports.de_ListAccountsCommand = de_ListAccountsCommand; const de_ListAccountsCommandError = async (output, context) => { const parsedOutput = { ...output, body: await parseErrorBody(output.body, context), }; const errorCode = loadRestJsonErrorCode(output, parsedOutput.body); switch (errorCode) { case "InvalidRequestException": case "com.amazonaws.sso#InvalidRequestException": throw await de_InvalidRequestExceptionRes(parsedOutput, context); case "ResourceNotFoundException": case "com.amazonaws.sso#ResourceNotFoundException": throw await de_ResourceNotFoundExceptionRes(parsedOutput, context); case "TooManyRequestsException": case "com.amazonaws.sso#TooManyRequestsException": throw await de_TooManyRequestsExceptionRes(parsedOutput, context); case "UnauthorizedException": case "com.amazonaws.sso#UnauthorizedException": throw await de_UnauthorizedExceptionRes(parsedOutput, context); default: const parsedBody = parsedOutput.body; return throwDefaultError({ output, parsedBody, errorCode, }); } }; const de_LogoutCommand = async (output, context) => { if (output.statusCode !== 200 && output.statusCode >= 300) { return de_LogoutCommandError(output, context); } const contents = (0, smithy_client_1.map)({ $metadata: deserializeMetadata(output), }); await (0, smithy_client_1.collectBody)(output.body, context); return contents; }; exports.de_LogoutCommand = de_LogoutCommand; const de_LogoutCommandError = async (output, context) => { const parsedOutput = { ...output, body: await parseErrorBody(output.body, context), }; const errorCode = loadRestJsonErrorCode(output, parsedOutput.body); switch (errorCode) { case "InvalidRequestException": case "com.amazonaws.sso#InvalidRequestException": throw await de_InvalidRequestExceptionRes(parsedOutput, context); case "TooManyRequestsException": case "com.amazonaws.sso#TooManyRequestsException": throw await de_TooManyRequestsExceptionRes(parsedOutput, context); case "UnauthorizedException": case "com.amazonaws.sso#UnauthorizedException": throw await de_UnauthorizedExceptionRes(parsedOutput, context); default: const parsedBody = parsedOutput.body; return throwDefaultError({ output, parsedBody, errorCode, }); } }; const throwDefaultError = (0, smithy_client_1.withBaseException)(SSOServiceException_1.SSOServiceException); const de_InvalidRequestExceptionRes = async (parsedOutput, context) => { const contents = (0, smithy_client_1.map)({}); const data = parsedOutput.body; const doc = (0, smithy_client_1.take)(data, { message: smithy_client_1.expectString, }); Object.assign(contents, doc); const exception = new models_0_1.InvalidRequestException({ $metadata: deserializeMetadata(parsedOutput), ...contents, }); return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body); }; const de_ResourceNotFoundExceptionRes = async (parsedOutput, context) => { const contents = (0, smithy_client_1.map)({}); const data = parsedOutput.body; const doc = (0, smithy_client_1.take)(data, { message: smithy_client_1.expectString, }); Object.assign(contents, doc); const exception = new models_0_1.ResourceNotFoundException({ $metadata: deserializeMetadata(parsedOutput), ...contents, }); return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body); }; const de_TooManyRequestsExceptionRes = async (parsedOutput, context) => { const contents = (0, smithy_client_1.map)({}); const data = parsedOutput.body; const doc = (0, smithy_client_1.take)(data, { message: smithy_client_1.expectString, }); Object.assign(contents, doc); const exception = new models_0_1.TooManyRequestsException({ $metadata: deserializeMetadata(parsedOutput), ...contents, }); return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body); }; const de_UnauthorizedExceptionRes = async (parsedOutput, context) => { const contents = (0, smithy_client_1.map)({}); const data = parsedOutput.body; const doc = (0, smithy_client_1.take)(data, { message: smithy_client_1.expectString, }); Object.assign(contents, doc); const exception = new models_0_1.UnauthorizedException({ $metadata: deserializeMetadata(parsedOutput), ...contents, }); return (0, smithy_client_1.decorateServiceException)(exception, parsedOutput.body); }; const deserializeMetadata = (output) => ({ httpStatusCode: output.statusCode, requestId: output.headers["x-amzn-requestid"] ?? output.headers["x-amzn-request-id"] ?? output.headers["x-amz-request-id"], extendedRequestId: output.headers["x-amz-id-2"], cfId: output.headers["x-amz-cf-id"], }); const collectBodyString = (streamBody, context) => (0, smithy_client_1.collectBody)(streamBody, context).then((body) => context.utf8Encoder(body)); const isSerializableHeaderValue = (value) => value !== undefined && value !== null && value !== "" && (!Object.getOwnPropertyNames(value).includes("length") || value.length != 0) && (!Object.getOwnPropertyNames(value).includes("size") || value.size != 0); const _aI = "accountId"; const _aT = "accessToken"; const _ai = "account_id"; const _mR = "maxResults"; const _mr = "max_result"; const _nT = "nextToken"; const _nt = "next_token"; const _rN = "roleName"; const _rn = "role_name"; const _xasbt = "x-amz-sso_bearer_token"; const parseBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => { if (encoded.length) { return JSON.parse(encoded); } return {}; }); const parseErrorBody = async (errorBody, context) => { const value = await parseBody(errorBody, context); value.message = value.message ?? value.Message; return value; }; const loadRestJsonErrorCode = (output, data) => { const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()); const sanitizeErrorCode = (rawValue) => { let cleanValue = rawValue; if (typeof cleanValue === "number") { cleanValue = cleanValue.toString(); } if (cleanValue.indexOf(",") >= 0) { cleanValue = cleanValue.split(",")[0]; } if (cleanValue.indexOf(":") >= 0) { cleanValue = cleanValue.split(":")[0]; } if (cleanValue.indexOf("#") >= 0) { cleanValue = cleanValue.split("#")[1]; } return cleanValue; }; const headerKey = findKey(output.headers, "x-amzn-errortype"); if (headerKey !== undefined) { return sanitizeErrorCode(output.headers[headerKey]); } if (data.code !== undefined) { return sanitizeErrorCode(data.code); } if (data["__type"] !== undefined) { return sanitizeErrorCode(data["__type"]); } };