Skip to content

Commit

Permalink
fix(amplify-provider-awscloudformation): fix tests failing due to sys…
Browse files Browse the repository at this point in the history
…tem-config-manager.js (#7053)
  • Loading branch information
rajrajhans authored Apr 10, 2021
1 parent ebdaa59 commit 07525b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import awsRegions from './aws-regions';
import constants from './constants';
import setupNewUser from './setup-new-user';
import obfuscateUtil from './utility-obfuscate';
import systemConfigManager from './system-config-manager';
import * as systemConfigManager from './system-config-manager';
import { doAdminTokensExist, getTempCredsWithAdminTokens, isAmplifyAdminApp } from './utils/admin-helpers';
import { resolveAppId } from './utils/resolve-appId';
import { AuthFlow, AuthFlowConfig, AwsSdkConfig } from './utils/auth-types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const logger = fileLogger('system-config-manager');
const credentialsFilePath = pathManager.getAWSCredentialsFilePath();
const configFilePath = pathManager.getAWSConfigFilePath();

function setProfile(awsConfig, profileName) {
export function setProfile(awsConfig, profileName) {
fs.ensureDirSync(pathManager.getDotAWSDirPath());

let credentials = {};
Expand Down Expand Up @@ -64,7 +64,7 @@ function setProfile(awsConfig, profileName) {
fs.writeFileSync(configFilePath, ini.stringify(config), { mode: SecretFileMode });
}

async function getProfiledAwsConfig(context, profileName, isRoleSourceProfile) {
export async function getProfiledAwsConfig(context, profileName, isRoleSourceProfile?) {
let awsConfig;
const httpProxy = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
const profileConfig = getProfileConfig(profileName);
Expand Down Expand Up @@ -218,15 +218,14 @@ function isCredentialsExpired(roleCredentials) {

if (roleCredentials && roleCredentials.expiration) {
const TOTAL_MILLISECONDS_IN_ONE_MINUTE = 1000 * 60;
const now = new Date();
const expirationDate = new Date(roleCredentials.expiration);
isExpired = expirationDate - now < TOTAL_MILLISECONDS_IN_ONE_MINUTE;
isExpired = expirationDate.getTime() - Date.now() < TOTAL_MILLISECONDS_IN_ONE_MINUTE;
}

return isExpired;
}

async function resetCache(context, profileName) {
export async function resetCache(context, profileName) {
let awsConfig;
const profileConfig = getProfileConfig(profileName);
const cacheFilePath = getCacheFilePath(context);
Expand Down Expand Up @@ -271,7 +270,7 @@ function getProfileConfig(profileName) {
return normalizeKeys(profileConfig);
}

function getProfileCredentials(profileName) {
export function getProfileCredentials(profileName) {
let profileCredentials;
logger('getProfileCredentials', [profileName])();
if (fs.existsSync(credentialsFilePath)) {
Expand Down Expand Up @@ -317,7 +316,7 @@ function normalizeKeys(config) {
return config;
}

function getProfileRegion(profileName) {
export function getProfileRegion(profileName) {
let profileRegion;
logger('getProfileRegion', [profileName])();
const profileConfig = getProfileConfig(profileName);
Expand All @@ -329,7 +328,7 @@ function getProfileRegion(profileName) {
return profileRegion;
}

function getNamedProfiles() {
export function getNamedProfiles() {
let namedProfiles;
if (fs.existsSync(configFilePath)) {
const config = ini.parse(fs.readFileSync(configFilePath, 'utf-8'));
Expand All @@ -343,12 +342,3 @@ function getNamedProfiles() {
}
return namedProfiles;
}

module.exports = {
setProfile,
getProfiledAwsConfig,
getProfileCredentials,
getProfileRegion,
getNamedProfiles,
resetCache,
};

0 comments on commit 07525b3

Please sign in to comment.