Skip to content

Commit 1b200b5

Browse files
authored
chore(token-providers): add feature ID 'BEARER_SERVICE_ENV_VARS' (#7168)
1 parent 0f3e62f commit 1b200b5

File tree

7 files changed

+72
-7
lines changed

7 files changed

+72
-7
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./emitWarningIfUnsupportedVersion";
22
export * from "./setCredentialFeature";
33
export * from "./setFeature";
4+
export * from "./setTokenFeature";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { AttributedTokenIdentity } from "@aws-sdk/types";
2+
import { describe, expect, test as it } from "vitest";
3+
4+
import { setTokenFeature } from "./setTokenFeature";
5+
6+
describe(setTokenFeature.name, () => {
7+
it("should create the data path if it does't exist", () => {
8+
const token = { token: "" } as AttributedTokenIdentity;
9+
10+
expect(setTokenFeature(token, "BEARER_SERVICE_ENV_VARS", "3")).toEqual({
11+
token: "",
12+
$source: {
13+
BEARER_SERVICE_ENV_VARS: "3",
14+
},
15+
});
16+
});
17+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { AttributedTokenIdentity, AwsSdkTokenFeatures } from "@aws-sdk/types";
2+
3+
/**
4+
* @internal
5+
*
6+
* @returns the token with source feature attribution.
7+
*/
8+
export function setTokenFeature<F extends keyof AwsSdkTokenFeatures>(
9+
token: AttributedTokenIdentity,
10+
feature: F,
11+
value: AwsSdkTokenFeatures[F]
12+
): AttributedTokenIdentity {
13+
if (!token.$source) {
14+
token.$source = {};
15+
}
16+
token.$source![feature] = value;
17+
return token;
18+
}

packages/token-providers/src/fromEnvSigningName.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { getBearerTokenEnvKey } from "@aws-sdk/core";
1+
import { getBearerTokenEnvKey } from "@aws-sdk/core/httpAuthSchemes";
22
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
33

44
import { fromEnvSigningName } from "./fromEnvSigningName";
55

6-
vi.mock("@aws-sdk/core");
6+
vi.mock("@aws-sdk/core/httpAuthSchemes");
77

88
describe(fromEnvSigningName.name, () => {
99
const originalEnv = process.env;
@@ -40,7 +40,12 @@ describe(fromEnvSigningName.name, () => {
4040
const mockBearerToken = "mock-bearer-token";
4141
process.env[mockBearerTokenEnvKey] = mockBearerToken;
4242
const token = await fromEnvSigningName(mockInit)();
43-
expect(token).toEqual({ token: mockBearerToken });
43+
expect(token).toEqual({
44+
token: mockBearerToken,
45+
$source: {
46+
BEARER_SERVICE_ENV_VARS: "3",
47+
},
48+
});
4449
expect(getBearerTokenEnvKey).toHaveBeenCalledWith(mockInit.signingName);
4550
});
4651
});

packages/token-providers/src/fromEnvSigningName.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { getBearerTokenEnvKey } from "@aws-sdk/core";
2-
import type { CredentialProviderOptions, TokenIdentityProvider } from "@aws-sdk/types";
1+
import { setTokenFeature } from "@aws-sdk/core/client";
2+
import { getBearerTokenEnvKey } from "@aws-sdk/core/httpAuthSchemes";
3+
import type { AttributedTokenIdentity, CredentialProviderOptions, TokenIdentityProvider } from "@aws-sdk/types";
34
import { TokenProviderError } from "@smithy/property-provider";
45

56
/**
@@ -33,5 +34,8 @@ export const fromEnvSigningName =
3334
throw new TokenProviderError(`Token not present in '${bearerTokenKey}' environment variable`, { logger });
3435
}
3536

36-
return { token: process.env[bearerTokenKey]! };
37+
const token = { token: process.env[bearerTokenKey]! } as AttributedTokenIdentity;
38+
setTokenFeature(token, "BEARER_SERVICE_ENV_VARS", "3");
39+
40+
return token;
3741
};

packages/types/src/feature-ids.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export type AwsSdkFeatures = Partial<{
3232
FLEXIBLE_CHECKSUMS_RES_WHEN_REQUIRED: "c";
3333
DDB_MAPPER: "d";
3434
}> &
35-
AwsSdkCredentialsFeatures;
35+
AwsSdkCredentialsFeatures &
36+
AwsSdkTokenFeatures;
3637

3738
/**
3839
* @internal
@@ -62,3 +63,10 @@ export type AwsSdkCredentialsFeatures = Partial<{
6263
CREDENTIALS_HTTP: "z";
6364
CREDENTIALS_IMDS: "0";
6465
}>;
66+
67+
/**
68+
* @internal
69+
*/
70+
export type AwsSdkTokenFeatures = Partial<{
71+
BEARER_SERVICE_ENV_VARS: "3";
72+
}>;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1+
import type { TokenIdentity } from "@smithy/types";
2+
3+
import type { AwsSdkTokenFeatures } from "../feature-ids";
14
export { TokenIdentity, TokenIdentityProvider } from "@smithy/types";
5+
6+
/**
7+
* @public
8+
*
9+
* TokenIdentity with source attribution metadata.
10+
*/
11+
export type AttributedTokenIdentity = TokenIdentity & {
12+
$source?: AwsSdkTokenFeatures;
13+
};

0 commit comments

Comments
 (0)