diff --git a/packages/amplify-provider-awscloudformation/src/configuration-manager.ts b/packages/amplify-provider-awscloudformation/src/configuration-manager.ts index 4fc145249c1..da9dad4961a 100644 --- a/packages/amplify-provider-awscloudformation/src/configuration-manager.ts +++ b/packages/amplify-provider-awscloudformation/src/configuration-manager.ts @@ -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'; diff --git a/packages/amplify-provider-awscloudformation/src/system-config-manager.js b/packages/amplify-provider-awscloudformation/src/system-config-manager.ts similarity index 95% rename from packages/amplify-provider-awscloudformation/src/system-config-manager.js rename to packages/amplify-provider-awscloudformation/src/system-config-manager.ts index 4c36cd7e99c..65ab061ca44 100644 --- a/packages/amplify-provider-awscloudformation/src/system-config-manager.js +++ b/packages/amplify-provider-awscloudformation/src/system-config-manager.ts @@ -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 = {}; @@ -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); @@ -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); @@ -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)) { @@ -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); @@ -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')); @@ -343,12 +342,3 @@ function getNamedProfiles() { } return namedProfiles; } - -module.exports = { - setProfile, - getProfiledAwsConfig, - getProfileCredentials, - getProfileRegion, - getNamedProfiles, - resetCache, -};