Skip to content

Commit

Permalink
fix: profile validation to include source_profile and role_arn (aws-a…
Browse files Browse the repository at this point in the history
  • Loading branch information
jhockett authored Apr 23, 2021
1 parent ec1a5a7 commit 70a980f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ describe('profile tests', () => {
expect(fs_mock.readFileSync).toHaveBeenCalledTimes(1);
});

it('should return profile credentials when using a source_profile and role_arn', () => {
fs_mock.readFileSync.mockImplementationOnce(() => {
return '[fake]\nrole_arn=arn:aws:iam::123456789012:role/fakerole\nsource_profile=fakeuser\n';
});
const creds = getProfileCredentials('fake');
expect(creds).toBeDefined();
expect(fs_mock.existsSync).toHaveBeenCalledTimes(1);
expect(fs_mock.readFileSync).toHaveBeenCalledTimes(1);
});

it('should fail to return profile credentials', () => {
fs_mock.readFileSync.mockImplementationOnce(() => {
return '[fake]\nmalformed_access_key_id=fakeAccessKey\naws_secret_access_key=fakeSecretKey\n';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { $TSAny, pathManager, SecretFileMode } from 'amplify-cli-core';

const aws = require('aws-sdk');
const fs = require('fs-extra');
const path = require('path');
const ini = require('ini');
const inquirer = require('inquirer');
const constants = require('./constants');
const proxyAgent = require('proxy-agent');
const { pathManager, SecretFileMode } = require('amplify-cli-core');
const { fileLogger } = require('./utils/aws-logger');
const logger = fileLogger('system-config-manager');

Expand Down Expand Up @@ -288,8 +289,11 @@ export function getProfileCredentials(profileName) {
return profileCredentials;
}

function validateCredentials(credentials, profileName) {
function validateCredentials(credentials: $TSAny, profileName: string) {
const missingKeys = [];
if (credentials?.source_profile && credentials?.role_arn) {
return;
}
if (!credentials?.accessKeyId) {
missingKeys.push('aws_access_key_id');
}
Expand Down

0 comments on commit 70a980f

Please sign in to comment.