diff --git a/packages/core/src/auth/providers/sharedCredentialsProviderFactory.ts b/packages/core/src/auth/providers/sharedCredentialsProviderFactory.ts index 41cc3465516..4864a332db0 100644 --- a/packages/core/src/auth/providers/sharedCredentialsProviderFactory.ts +++ b/packages/core/src/auth/providers/sharedCredentialsProviderFactory.ts @@ -3,47 +3,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -import fs from '../../shared/fs/fs' import { getLogger, Logger } from '../../shared/logger' import { loadSharedCredentialsSections, updateAwsSdkLoadConfigEnvVar } from '../credentials/sharedCredentials' import { CredentialsProviderType } from './credentials' import { BaseCredentialsProviderFactory } from './credentialsProviderFactory' import { SharedCredentialsProvider } from './sharedCredentialsProvider' -import { getCredentialsFilename, getConfigFilename } from '../credentials/sharedCredentialsFile' export class SharedCredentialsProviderFactory extends BaseCredentialsProviderFactory { private readonly logger: Logger = getLogger() - private loadedCredentialsModificationMillis?: number - private loadedConfigModificationMillis?: number - public async refresh(): Promise { - if (await this.needsRefresh()) { - await this.loadSharedCredentialsProviders() - } + await this.loadSharedCredentialsProviders() } public override getProviderType(): CredentialsProviderType | undefined { return SharedCredentialsProvider.getProviderType() } - protected override resetProviders() { - this.loadedCredentialsModificationMillis = undefined - this.loadedConfigModificationMillis = undefined - - super.resetProviders() - } - - private async needsRefresh(): Promise { - const credentialsLastModMillis = await this.getLastModifiedMillis(getCredentialsFilename()) - const configLastModMillis = await this.getLastModifiedMillis(getConfigFilename()) - - return ( - this.loadedCredentialsModificationMillis !== credentialsLastModMillis || - this.loadedConfigModificationMillis !== configLastModMillis - ) - } - private async loadSharedCredentialsProviders(): Promise { this.resetProviders() @@ -52,9 +28,6 @@ export class SharedCredentialsProviderFactory extends BaseCredentialsProviderFac const errors = result.errors.map((e) => e.message).join('\t\n') getLogger().warn(`credentials: errors while parsing:\n%s`, errors) } - - this.loadedCredentialsModificationMillis = await this.getLastModifiedMillis(getCredentialsFilename()) - this.loadedConfigModificationMillis = await this.getLastModifiedMillis(getConfigFilename()) await updateAwsSdkLoadConfigEnvVar() getLogger().verbose( @@ -79,13 +52,4 @@ export class SharedCredentialsProviderFactory extends BaseCredentialsProviderFac this.addProvider(provider) } } - - private async getLastModifiedMillis(filepath: string): Promise { - try { - const stat = await fs.stat(filepath) - return stat.mtime - } catch (err) { - return undefined - } - } } diff --git a/packages/core/src/test/credentials/provider/sharedCredentialsProviderFactory.test.ts b/packages/core/src/test/credentials/provider/sharedCredentialsProviderFactory.test.ts index 09d210f18b2..84f2d378e46 100644 --- a/packages/core/src/test/credentials/provider/sharedCredentialsProviderFactory.test.ts +++ b/packages/core/src/test/credentials/provider/sharedCredentialsProviderFactory.test.ts @@ -120,7 +120,7 @@ describe('SharedCredentialsProviderFactory', async function () { ) }) - it('refresh does not reload from file if the file has not changed', async function () { + it('refresh always reloads from file', async function () { const sut = new SharedCredentialsProviderFactory() // First load @@ -129,10 +129,7 @@ describe('SharedCredentialsProviderFactory', async function () { // Expect: No reload await sut.refresh() - assert.ok( - loadSharedCredentialsSectionsStub.calledOnce, - 'Credentials should have only been loaded from disk once' - ) + assert.ok(loadSharedCredentialsSectionsStub.calledTwice, 'Credentials should have loaded from disk twice') }) it('refresh reloads from file if the file has changed', async function () {