Skip to content

Commit

Permalink
fix(codegen): use AWS SDK default credentials as sigv4 default creden…
Browse files Browse the repository at this point in the history
…tials (#6431)
  • Loading branch information
kuhe authored Sep 6, 2024
1 parent d1cdb6e commit 39532e4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
"credentialDefaultProvider", w ->
w.write("((_: unknown) => () => Promise.reject(new Error(\"Credential is missing\")))")
);
} else {
return MapUtils.of(
"credentials", w ->
w.write("(() => () => Promise.reject(new Error(\"Credentials are missing\")))")
);
}
case NODE:
if (isAwsService(service)) {
Expand Down Expand Up @@ -133,6 +138,18 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
);
}
return map;
} else {
// isSigV4Service and !isAwsService are implied here.
return MapUtils.of(
"credentials", writer -> {
writer
.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE)
.addImport("defaultProvider", "credentialDefaultProvider",
AwsDependency.CREDENTIAL_PROVIDER_NODE)
.write("credentialDefaultProvider()");
AwsCredentialProviderUtils.addAwsCredentialProviderDependencies(service, writer);
}
);
}
default:
return Collections.emptyMap();
Expand Down
8 changes: 8 additions & 0 deletions private/aws-util-test/src/clients/Weather.integ.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ describe(Weather.name, () => {

expect.hasAssertions();
});

it("should be assigned a default credentials object for sigv4 auth", async () => {
const client = new Weather({
endpoint: "https://localhost",
});

expect(client.config.credentials).toBeDefined();
});
});
3 changes: 3 additions & 0 deletions private/weather/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
"dependencies": {
"@aws-crypto/sha256-browser": "5.2.0",
"@aws-crypto/sha256-js": "5.2.0",
"@aws-sdk/client-sso-oidc": "*",
"@aws-sdk/client-sts": "*",
"@aws-sdk/core": "*",
"@aws-sdk/credential-provider-node": "*",
"@aws-sdk/middleware-host-header": "*",
"@aws-sdk/middleware-logger": "*",
"@aws-sdk/middleware-recursion-detection": "*",
Expand Down
1 change: 1 addition & 0 deletions private/weather/src/runtimeConfig.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const getRuntimeConfig = (config: WeatherClientConfig) => {
runtime: "browser",
defaultsMode,
bodyLengthChecker: config?.bodyLengthChecker ?? calculateBodyLength,
credentials: config?.credentials ?? (() => () => Promise.reject(new Error("Credentials are missing"))),
defaultUserAgentProvider:
config?.defaultUserAgentProvider ?? defaultUserAgent({ clientVersion: packageInfo.version }),
maxAttempts: config?.maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
Expand Down
2 changes: 2 additions & 0 deletions private/weather/src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// @ts-ignore: package.json will be imported from dist folders
import packageInfo from "../package.json"; // eslint-disable-line

import { defaultProvider as credentialDefaultProvider } from "@aws-sdk/credential-provider-node";
import { defaultUserAgent } from "@aws-sdk/util-user-agent-node";
import { NODE_REGION_CONFIG_FILE_OPTIONS, NODE_REGION_CONFIG_OPTIONS } from "@smithy/config-resolver";
import { Hash } from "@smithy/hash-node";
Expand Down Expand Up @@ -30,6 +31,7 @@ export const getRuntimeConfig = (config: WeatherClientConfig) => {
runtime: "node",
defaultsMode,
bodyLengthChecker: config?.bodyLengthChecker ?? calculateBodyLength,
credentials: config?.credentials ?? credentialDefaultProvider(),
defaultUserAgentProvider:
config?.defaultUserAgentProvider ?? defaultUserAgent({ clientVersion: packageInfo.version }),
maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
Expand Down

0 comments on commit 39532e4

Please sign in to comment.