Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codegen): use AWS SDK default credentials as sigv4 default credentials #6431

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not up to speed, but what's the difference between configuring credentials here v/s credentialDefaultProvider? It seems more consistent to configure credentialDefaultProvider here. And that's what it was before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

credentialDefaultProvider was deprecated by ID&Auth SRA. It is a field that is only generated when the AwsSdkCustomizeSigV4Auth plugin is activated by the isAwsService and isSigV4Service conditionals in conjunction, and relies on data from the (AWS) service trait.

That plugin contains the config resolver that processes the credentialDefaultProvider field along with a few other AWS customizations. Rather than bringing all of that in, I'm using a default value for the credentials field, which is functionally very similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

credentialDefaultProvider seems to be a quirk from legacy dev. Even in legacyAuth, it was simply assigned onto the credentials field if the credentials field was empty during config resolution.

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
Loading