Skip to content

Commit

Permalink
chore: statically import credential-provider-node in clients used fro…
Browse files Browse the repository at this point in the history
…m credentials (#6027)
  • Loading branch information
trivikr authored Apr 26, 2024
1 parent 0d54a05 commit 5ce5600
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 155 deletions.
4 changes: 1 addition & 3 deletions clients/client-sso-oidc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@aws-crypto/sha256-browser": "3.0.0",
"@aws-crypto/sha256-js": "3.0.0",
"@aws-sdk/core": "*",
"@aws-sdk/credential-provider-node": "*",
"@aws-sdk/middleware-host-header": "*",
"@aws-sdk/middleware-logger": "*",
"@aws-sdk/middleware-recursion-detection": "*",
Expand Down Expand Up @@ -84,9 +85,6 @@
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0",
"peerDependencies": {
"@aws-sdk/credential-provider-node": "*"
},
"browser": {
"./dist-es/runtimeConfig": "./dist-es/runtimeConfig.browser"
},
Expand Down
8 changes: 0 additions & 8 deletions clients/client-sso-oidc/src/credentialDefaultProvider.ts

This file was deleted.

2 changes: 1 addition & 1 deletion clients/client-sso-oidc/src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// @ts-ignore: package.json will be imported from dist folders
import packageInfo from "../package.json"; // eslint-disable-line

import { defaultProvider as credentialDefaultProvider } from "./credentialDefaultProvider";
import { emitWarningIfUnsupportedVersion as awsCheckVersion } from "@aws-sdk/core";
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,
Expand Down
4 changes: 1 addition & 3 deletions clients/client-sts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@aws-crypto/sha256-browser": "3.0.0",
"@aws-crypto/sha256-js": "3.0.0",
"@aws-sdk/core": "*",
"@aws-sdk/credential-provider-node": "*",
"@aws-sdk/middleware-host-header": "*",
"@aws-sdk/middleware-logger": "*",
"@aws-sdk/middleware-recursion-detection": "*",
Expand Down Expand Up @@ -86,9 +87,6 @@
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0",
"peerDependencies": {
"@aws-sdk/credential-provider-node": "*"
},
"browser": {
"./dist-es/runtimeConfig": "./dist-es/runtimeConfig.browser"
},
Expand Down
8 changes: 0 additions & 8 deletions clients/client-sts/src/credentialDefaultProvider.ts

This file was deleted.

2 changes: 1 addition & 1 deletion clients/client-sts/src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// @ts-ignore: package.json will be imported from dist folders
import packageInfo from "../package.json"; // eslint-disable-line

import { defaultProvider as credentialDefaultProvider } from "./credentialDefaultProvider";
import { AwsSdkSigV4Signer, emitWarningIfUnsupportedVersion as awsCheckVersion } from "@aws-sdk/core";
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.OptionalAuthTrait;
import software.amazon.smithy.typescript.codegen.CodegenUtils;
import software.amazon.smithy.typescript.codegen.LanguageTarget;
Expand Down Expand Up @@ -208,19 +207,11 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
case NODE:
return MapUtils.of(
"credentialDefaultProvider", writer -> {
if (isCredentialService(service)) {
writer
.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE_PEER)
.addRelativeImport("defaultProvider", "credentialDefaultProvider",
Paths.get(".", CodegenUtils.SOURCE_FOLDER, "credentialDefaultProvider"))
.write("credentialDefaultProvider");
} else {
writer
.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE)
.addImport("defaultProvider", "credentialDefaultProvider",
AwsDependency.CREDENTIAL_PROVIDER_NODE)
.write("credentialDefaultProvider");
}
writer
.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE)
.addImport("defaultProvider", "credentialDefaultProvider",
AwsDependency.CREDENTIAL_PROVIDER_NODE)
.write("credentialDefaultProvider");
}
);
default:
Expand All @@ -239,22 +230,6 @@ public void customize(TypeScriptCodegenContext codegenContext) {
writerFactory.accept(Paths.get(CodegenUtils.SOURCE_FOLDER, "index.ts").toString(), writer -> {
writeAdditionalExports(settings, model, writer);
});

if (isCredentialService(settings.getService(model))) {
writerFactory.accept(CodegenUtils.SOURCE_FOLDER + "/credentialDefaultProvider.ts", writer -> {
writer
.write("""
/**
* @internal
*/
export const defaultProvider = ((input: any) => {
// @ts-ignore
return () => import("@aws-sdk/credential-provider-node")
.then(({ defaultProvider }) => defaultProvider(input)());
}) as any;
""");
});
}
}

private void writeAdditionalFiles(
Expand Down Expand Up @@ -343,14 +318,4 @@ private static boolean areAllOptionalAuthOperations(Model model, ServiceShape se
}
return true;
}

/**
* Some services with circular dependencies to credential providers.
*/
private boolean isCredentialService(ServiceShape service) {
return List.of(
ShapeId.from("com.amazonaws.ssooidc#AWSSSOOIDCService"),
ShapeId.from("com.amazonaws.sts#AWSSecurityTokenServiceV20110615")
).stream().anyMatch(service.getId()::equals);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public enum AwsDependency implements Dependency {
MIDDLEWARE_SIGNING(NORMAL_DEPENDENCY, "@aws-sdk/middleware-signing"),
MIDDLEWARE_TOKEN(NORMAL_DEPENDENCY, "@aws-sdk/middleware-token"),
CREDENTIAL_PROVIDER_NODE(NORMAL_DEPENDENCY, "@aws-sdk/credential-provider-node"),
CREDENTIAL_PROVIDER_NODE_PEER(PEER_DEPENDENCY, "@aws-sdk/credential-provider-node"),
ACCEPT_HEADER(NORMAL_DEPENDENCY, "@aws-sdk/middleware-sdk-api-gateway"),
S3_MIDDLEWARE(NORMAL_DEPENDENCY, "@aws-sdk/middleware-sdk-s3"),
ADD_EXPECT_CONTINUE(NORMAL_DEPENDENCY, "@aws-sdk/middleware-expect-continue"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
return MapUtils.of(
"credentialDefaultProvider", writer -> {
writer
.addRelativeImport("defaultProvider", "credentialDefaultProvider",
Paths.get(".", CodegenUtils.SOURCE_FOLDER, "credentialDefaultProvider"))
.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE_PEER)
.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE)
.addImport("defaultProvider", "credentialDefaultProvider",
AwsDependency.CREDENTIAL_PROVIDER_NODE)
.write("credentialDefaultProvider");
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
import static software.amazon.smithy.aws.typescript.codegen.AwsTraitsUtils.isAwsService;
import static software.amazon.smithy.aws.typescript.codegen.AwsTraitsUtils.isSigV4Service;

import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import software.amazon.smithy.aws.traits.auth.SigV4Trait;
import software.amazon.smithy.aws.typescript.codegen.AwsDependency;
Expand All @@ -23,11 +21,8 @@
import software.amazon.smithy.model.knowledge.TopDownIndex;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.OptionalAuthTrait;
import software.amazon.smithy.typescript.codegen.CodegenUtils;
import software.amazon.smithy.typescript.codegen.LanguageTarget;
import software.amazon.smithy.typescript.codegen.TypeScriptCodegenContext;
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
Expand Down Expand Up @@ -113,27 +108,15 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
}
case NODE:
if (isAwsService(service)) {
if (isCredentialService(service)) {
return MapUtils.of(
"credentialDefaultProvider", writer -> {
writer
.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE_PEER)
.addRelativeImport("defaultProvider", "credentialDefaultProvider",
Paths.get(".", CodegenUtils.SOURCE_FOLDER, "credentialDefaultProvider"))
.write("credentialDefaultProvider");
}
);
} else {
return MapUtils.of(
"credentialDefaultProvider", writer -> {
writer
.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE)
.addImport("defaultProvider", "credentialDefaultProvider",
AwsDependency.CREDENTIAL_PROVIDER_NODE)
.write("credentialDefaultProvider");
}
);
}
return MapUtils.of(
"credentialDefaultProvider", writer -> {
writer
.addDependency(AwsDependency.CREDENTIAL_PROVIDER_NODE)
.addImport("defaultProvider", "credentialDefaultProvider",
AwsDependency.CREDENTIAL_PROVIDER_NODE)
.write("credentialDefaultProvider");
}
);
}
default:
return Collections.emptyMap();
Expand Down Expand Up @@ -197,31 +180,6 @@ public void customizeSupportedHttpAuthSchemes(
}
}

@Override
public void customize(TypeScriptCodegenContext codegenContext) {
TypeScriptSettings settings = codegenContext.settings();
Model model = codegenContext.model();

if (isCredentialService(settings.getService(model))) {
BiConsumer<String, Consumer<TypeScriptWriter>> writerFactory =
codegenContext.writerDelegator()::useFileWriter;

writerFactory.accept(CodegenUtils.SOURCE_FOLDER + "/credentialDefaultProvider.ts", writer -> {
writer
.write("""
/**
* @internal
*/
export const defaultProvider = ((input: any) => {
// @ts-ignore
return () => import("@aws-sdk/credential-provider-node")
.then(({ defaultProvider }) => defaultProvider(input)());
}) as any;
""");
});
}
}

private boolean areAllOptionalAuthOperations(Model model, ServiceShape service) {
TopDownIndex topDownIndex = TopDownIndex.of(model);
Set<OperationShape> operations = topDownIndex.getContainedOperations(service);
Expand All @@ -232,14 +190,4 @@ private boolean areAllOptionalAuthOperations(Model model, ServiceShape service)
}
return true;
}

/**
* Some services with circular dependencies to credential providers.
*/
private boolean isCredentialService(ServiceShape service) {
return List.of(
ShapeId.from("com.amazonaws.ssooidc#AWSSSOOIDCService"),
ShapeId.from("com.amazonaws.sts#AWSSecurityTokenServiceV20110615")
).stream().anyMatch(service.getId()::equals);
}
}
4 changes: 3 additions & 1 deletion packages/credential-provider-ini/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk/client-sts": "*",
"@aws-sdk/credential-provider-env": "*",
"@aws-sdk/credential-provider-process": "*",
"@aws-sdk/credential-provider-sso": "*",
Expand All @@ -44,6 +43,9 @@
"rimraf": "3.0.2",
"typescript": "~4.9.5"
},
"peerDependencies": {
"@aws-sdk/client-sts": "*"
},
"types": "./dist-types/index.d.ts",
"engines": {
"node": ">=14.0.0"
Expand Down
8 changes: 6 additions & 2 deletions packages/credential-provider-ini/src/fromIni.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { CredentialProviderOptions } from "@aws-sdk/types";
import { getProfileName, parseKnownFiles, SourceProfileInit } from "@smithy/shared-ini-file-loader";
import type { AwsCredentialIdentity, AwsCredentialIdentityProvider, Pluggable } from "@smithy/types";

import type { STSClientConfig } from "./loadSts";
import { AssumeRoleParams } from "./resolveAssumeRoleCredentials";
import { resolveProfileData } from "./resolveProfileData";

Expand Down Expand Up @@ -39,7 +38,12 @@ export interface FromIniInit extends SourceProfileInit, CredentialProviderOption
*/
roleAssumerWithWebIdentity?: (params: AssumeRoleWithWebIdentityParams) => Promise<AwsCredentialIdentity>;

clientConfig?: STSClientConfig;
/**
* STSClientConfig to be used for creating STS Client for assuming role.
* @internal
*/
clientConfig?: any;

clientPlugins?: Pluggable<any, any>[];
}

Expand Down
5 changes: 0 additions & 5 deletions packages/credential-provider-ini/src/loadSts.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export const resolveAssumeRoleCredentials = async (
const data = profiles[profileName];

if (!options.roleAssumer) {
const { getDefaultRoleAssumer } = await import("./loadSts");
// @ts-ignore Cannot find module '@aws-sdk/client-sts'
const { getDefaultRoleAssumer } = await import("@aws-sdk/client-sts");
options.roleAssumer = getDefaultRoleAssumer(
{
...options.clientConfig,
Expand Down
4 changes: 3 additions & 1 deletion packages/credential-provider-web-identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
},
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk/client-sts": "*",
"@aws-sdk/types": "*",
"@smithy/property-provider": "^2.2.0",
"@smithy/types": "^2.12.0",
Expand All @@ -46,6 +45,9 @@
"rimraf": "3.0.2",
"typescript": "~4.9.5"
},
"peerDependencies": {
"@aws-sdk/client-sts": "*"
},
"types": "./dist-types/index.d.ts",
"engines": {
"node": ">=14.0.0"
Expand Down
8 changes: 4 additions & 4 deletions packages/credential-provider-web-identity/src/fromWebToken.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { CredentialProviderOptions } from "@aws-sdk/types";
import type { AwsCredentialIdentity, AwsCredentialIdentityProvider, Pluggable } from "@smithy/types";

import type { STSClientConfig } from "./loadSts";

/**
* @public
*/
Expand Down Expand Up @@ -138,9 +136,10 @@ export interface FromWebTokenInit
roleAssumerWithWebIdentity?: (params: AssumeRoleWithWebIdentityParams) => Promise<AwsCredentialIdentity>;

/**
* STSClientConfig to be used for creating STS Client for assuming role.
* @internal
*/
clientConfig?: STSClientConfig;
clientConfig?: any;

/**
* @internal
Expand All @@ -160,7 +159,8 @@ export const fromWebToken =
let { roleAssumerWithWebIdentity } = init;

if (!roleAssumerWithWebIdentity) {
const { getDefaultRoleAssumerWithWebIdentity } = await import("./loadSts");
// @ts-ignore Cannot find module '@aws-sdk/client-sts'
const { getDefaultRoleAssumerWithWebIdentity } = await import("@aws-sdk/client-sts");
roleAssumerWithWebIdentity = getDefaultRoleAssumerWithWebIdentity(
{
...init.clientConfig,
Expand Down
5 changes: 0 additions & 5 deletions packages/credential-provider-web-identity/src/loadSts.ts

This file was deleted.

Loading

0 comments on commit 5ce5600

Please sign in to comment.