Skip to content

Commit 0878966

Browse files
committed
chore(credential-provider-node): refactor provider chain
1 parent f1e190c commit 0878966

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

packages/credential-provider-node/src/index.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ describe("defaultProvider", () => {
226226
await expect(defaultProvider(iniConfig)()).resolves;
227227

228228
expect((fromIni as any).mock.calls.length).toBe(1);
229-
expect((fromIni as any).mock.calls[0][0]).toBe(iniConfig);
229+
expect((fromIni as any).mock.calls[0][0]).toEqual(iniConfig);
230230
});
231231

232232
it("should pass configuration on to the process provider", async () => {
@@ -249,7 +249,7 @@ describe("defaultProvider", () => {
249249
await expect(defaultProvider(processConfig)()).resolves;
250250
expect((fromProcess as any).mock.calls.length).toBe(1);
251251
expect((fromProcess as any).mock.calls.length).toBe(1);
252-
expect((fromProcess as any).mock.calls[0][0]).toBe(processConfig);
252+
expect((fromProcess as any).mock.calls[0][0]).toEqual(processConfig);
253253
});
254254

255255
it("should pass configuration on to the IMDS provider", async () => {
@@ -273,7 +273,7 @@ describe("defaultProvider", () => {
273273
await expect(defaultProvider(imdsConfig)()).resolves;
274274

275275
expect((fromInstanceMetadata as any).mock.calls.length).toBe(1);
276-
expect((fromInstanceMetadata as any).mock.calls[0][0]).toBe(imdsConfig);
276+
expect((fromInstanceMetadata as any).mock.calls[0][0]).toEqual(imdsConfig);
277277
});
278278

279279
it("should pass configuration on to the ECS IMDS provider", async () => {
@@ -298,7 +298,7 @@ describe("defaultProvider", () => {
298298
await expect(defaultProvider(ecsImdsConfig)()).resolves;
299299

300300
expect((fromContainerMetadata as any).mock.calls.length).toBe(1);
301-
expect((fromContainerMetadata as any).mock.calls[0][0]).toBe(ecsImdsConfig);
301+
expect((fromContainerMetadata as any).mock.calls[0][0]).toEqual(ecsImdsConfig);
302302
});
303303

304304
it("should return the same promise across invocations", async () => {

packages/credential-provider-node/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ export const ENV_IMDS_DISABLED = "AWS_EC2_METADATA_DISABLED";
4242
* ECS Container Metadata Service
4343
*/
4444
export function defaultProvider(init: FromIniInit & RemoteProviderInit & FromProcessInit = {}): CredentialProvider {
45-
const { profile = process.env[ENV_PROFILE] } = init;
46-
const providerChain = profile
47-
? chain(fromIni(init), fromProcess(init))
48-
: chain(fromEnv(), fromIni(init), fromProcess(init), remoteProvider(init));
45+
const options = { profile: process.env[ENV_PROFILE], ...init };
46+
const providers = [fromIni(options), fromProcess(options), remoteProvider(options)];
47+
if (!options.profile) providers.unshift(fromEnv());
48+
const providerChain = chain(...providers);
4949

5050
return memoize(
5151
providerChain,

packages/credential-provider-process/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { ParsedIniData, SharedConfigFiles, SharedConfigInit } from "@aws-sdk/sha
44
import { CredentialProvider, Credentials } from "@aws-sdk/types";
55
import { exec } from "child_process";
66

7+
/**
8+
* @internal
9+
*/
710
export const ENV_PROFILE = "AWS_PROFILE";
811

912
export interface FromProcessInit extends SharedConfigInit {

0 commit comments

Comments
 (0)