Skip to content

Commit 70a980f

Browse files
authored
fix: profile validation to include source_profile and role_arn (#7173)
1 parent ec1a5a7 commit 70a980f

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/amplify-provider-awscloudformation/src/__tests__/system-config-manager.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ describe('profile tests', () => {
3636
expect(fs_mock.readFileSync).toHaveBeenCalledTimes(1);
3737
});
3838

39+
it('should return profile credentials when using a source_profile and role_arn', () => {
40+
fs_mock.readFileSync.mockImplementationOnce(() => {
41+
return '[fake]\nrole_arn=arn:aws:iam::123456789012:role/fakerole\nsource_profile=fakeuser\n';
42+
});
43+
const creds = getProfileCredentials('fake');
44+
expect(creds).toBeDefined();
45+
expect(fs_mock.existsSync).toHaveBeenCalledTimes(1);
46+
expect(fs_mock.readFileSync).toHaveBeenCalledTimes(1);
47+
});
48+
3949
it('should fail to return profile credentials', () => {
4050
fs_mock.readFileSync.mockImplementationOnce(() => {
4151
return '[fake]\nmalformed_access_key_id=fakeAccessKey\naws_secret_access_key=fakeSecretKey\n';

packages/amplify-provider-awscloudformation/src/system-config-manager.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { $TSAny, pathManager, SecretFileMode } from 'amplify-cli-core';
2+
13
const aws = require('aws-sdk');
24
const fs = require('fs-extra');
35
const path = require('path');
46
const ini = require('ini');
57
const inquirer = require('inquirer');
68
const constants = require('./constants');
79
const proxyAgent = require('proxy-agent');
8-
const { pathManager, SecretFileMode } = require('amplify-cli-core');
910
const { fileLogger } = require('./utils/aws-logger');
1011
const logger = fileLogger('system-config-manager');
1112

@@ -288,8 +289,11 @@ export function getProfileCredentials(profileName) {
288289
return profileCredentials;
289290
}
290291

291-
function validateCredentials(credentials, profileName) {
292+
function validateCredentials(credentials: $TSAny, profileName: string) {
292293
const missingKeys = [];
294+
if (credentials?.source_profile && credentials?.role_arn) {
295+
return;
296+
}
293297
if (!credentials?.accessKeyId) {
294298
missingKeys.push('aws_access_key_id');
295299
}

0 commit comments

Comments
 (0)