(nodeData: INodeData, options: ICommonObject, region?: string)
| 74 | * External ID) — The full error is logged server-side. |
| 75 | */ |
| 76 | export async function getAWSCredentialConfig(nodeData: INodeData, options: ICommonObject, region?: string): Promise<AWSCredentialConfig> { |
| 77 | const credentialData = await getCredentialData(nodeData.credential ?? '', options) |
| 78 | const awsRegion = region || DEFAULT_AWS_REGION |
| 79 | |
| 80 | const accessKeyId = getCredentialParam('awsKey', credentialData, nodeData) |
| 81 | const secretAccessKey = getCredentialParam('awsSecret', credentialData, nodeData) |
| 82 | const sessionToken = getCredentialParam('awsSession', credentialData, nodeData) |
| 83 | const roleArn = getCredentialParam('roleArn', credentialData, nodeData) |
| 84 | const externalId = getCredentialParam('externalId', credentialData, nodeData) |
| 85 | |
| 86 | // --- AssumeRole flow --- |
| 87 | if (roleArn) { |
| 88 | if (!AWS_ROLE_ARN_REGEX.test(roleArn)) { |
| 89 | throw new Error('Invalid Role ARN format: Expected format: arn:aws:iam::<12-digit-account-id>:role/<role-name>') |
| 90 | } |
| 91 | const assumedCredentials = await assumeRole({ |
| 92 | accessKeyId, |
| 93 | secretAccessKey, |
| 94 | sessionToken, |
| 95 | roleArn, |
| 96 | externalId, |
| 97 | region: awsRegion, |
| 98 | logger: options.logger |
| 99 | }) |
| 100 | return { credentials: assumedCredentials, region: awsRegion } |
| 101 | } |
| 102 | |
| 103 | // --- Static credentials flow (backward-compatible) --- |
| 104 | if (accessKeyId && secretAccessKey) { |
| 105 | const credentials: AWSCredentials = { |
| 106 | accessKeyId, |
| 107 | secretAccessKey, |
| 108 | ...(sessionToken && { sessionToken }) |
| 109 | } |
| 110 | return { credentials, region: awsRegion } |
| 111 | } |
| 112 | |
| 113 | // No explicit keys and no role — let SDK use default chain |
| 114 | return { credentials: undefined, region: awsRegion } |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Assume an IAM role using AWS STS and return temporary session credentials. |
no test coverage detected