Skip to content

Commit

Permalink
feat(clients): profile setting for clients
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Dec 12, 2024
1 parent a3a39be commit e62b3a6
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 28 deletions.
13 changes: 13 additions & 0 deletions clients/client-s3/src/S3Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,19 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
*/
region?: string | __Provider<string>;

/**
* Setting a client profile is similar to setting a value for the
* AWS_PROFILE environment variable. Setting a profile on a client
* in code only affects the single client instance, unlike AWS_PROFILE.
*
* When set, and only for environments where a profile configuration
* file exists, values configurable by this file will be retrieved
* with the specified profile. Conflicting code configuration and
* environment variables will still have higher priority.
*
*/
profile?: string;

/**
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
* @internal
Expand Down
1 change: 0 additions & 1 deletion clients/client-s3/src/models/models_0.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// smithy-typescript generated code
import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client";

import { StreamingBlobTypes } from "@smithy/types";

import { S3ServiceException as __BaseException } from "./S3ServiceException";
Expand Down
2 changes: 0 additions & 2 deletions clients/client-s3/src/models/models_1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// smithy-typescript generated code
import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client";

import { StreamingBlobTypes } from "@smithy/types";

import {
Expand Down Expand Up @@ -40,7 +39,6 @@ import {
Tag,
TransitionDefaultMinimumObjectSize,
} from "./models_0";

import { S3ServiceException as __BaseException } from "./S3ServiceException";

/**
Expand Down
38 changes: 24 additions & 14 deletions clients/client-s3/src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const getRuntimeConfig = (config: S3ClientConfig) => {
const defaultConfigProvider = () => defaultsMode().then(loadConfigsForDefaultMode);
const clientSharedValues = getSharedRuntimeConfig(config);
awsCheckVersion(process.version);
const profileConfig = { profile: config?.profile };
return {
...clientSharedValues,
...config,
Expand All @@ -52,30 +53,39 @@ export const getRuntimeConfig = (config: S3ClientConfig) => {
config?.defaultUserAgentProvider ??
createDefaultUserAgentProvider({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
disableS3ExpressSessionAuth:
config?.disableS3ExpressSessionAuth ?? loadNodeConfig(NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS),
config?.disableS3ExpressSessionAuth ??
loadNodeConfig(NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS, profileConfig),
eventStreamSerdeProvider: config?.eventStreamSerdeProvider ?? eventStreamSerdeProvider,
maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS, config),
md5: config?.md5 ?? Hash.bind(null, "md5"),
region: config?.region ?? loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
region:
config?.region ??
loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, { ...NODE_REGION_CONFIG_FILE_OPTIONS, ...profileConfig }),
requestChecksumCalculation:
config?.requestChecksumCalculation ?? loadNodeConfig(NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS),
config?.requestChecksumCalculation ??
loadNodeConfig(NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, profileConfig),
requestHandler: RequestHandler.create(config?.requestHandler ?? defaultConfigProvider),
responseChecksumValidation:
config?.responseChecksumValidation ?? loadNodeConfig(NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS),
config?.responseChecksumValidation ??
loadNodeConfig(NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, profileConfig),
retryMode:
config?.retryMode ??
loadNodeConfig({
...NODE_RETRY_MODE_CONFIG_OPTIONS,
default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE,
}),
loadNodeConfig(
{
...NODE_RETRY_MODE_CONFIG_OPTIONS,
default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE,
},
config
),
sha1: config?.sha1 ?? Hash.bind(null, "sha1"),
sha256: config?.sha256 ?? Hash.bind(null, "sha256"),
sigv4aSigningRegionSet: config?.sigv4aSigningRegionSet ?? loadNodeConfig(NODE_SIGV4A_CONFIG_OPTIONS),
sigv4aSigningRegionSet: config?.sigv4aSigningRegionSet ?? loadNodeConfig(NODE_SIGV4A_CONFIG_OPTIONS, profileConfig),
streamCollector: config?.streamCollector ?? streamCollector,
streamHasher: config?.streamHasher ?? streamHasher,
useArnRegion: config?.useArnRegion ?? loadNodeConfig(NODE_USE_ARN_REGION_CONFIG_OPTIONS),
useDualstackEndpoint: config?.useDualstackEndpoint ?? loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS),
useFipsEndpoint: config?.useFipsEndpoint ?? loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS),
userAgentAppId: config?.userAgentAppId ?? loadNodeConfig(NODE_APP_ID_CONFIG_OPTIONS),
useArnRegion: config?.useArnRegion ?? loadNodeConfig(NODE_USE_ARN_REGION_CONFIG_OPTIONS, profileConfig),
useDualstackEndpoint:
config?.useDualstackEndpoint ?? loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS, profileConfig),
useFipsEndpoint: config?.useFipsEndpoint ?? loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, profileConfig),
userAgentAppId: config?.userAgentAppId ?? loadNodeConfig(NODE_APP_ID_CONFIG_OPTIONS, profileConfig),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
null, AwsDependency.AWS_SDK_CORE,
"/account-id-endpoint");
writer.write(
"loadNodeConfig(NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS)");
"loadNodeConfig(NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS, profileConfig)");
});
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ public void addConfigInterfaceFields(
? "The AWS region to which this client will send requests"
: "The AWS region to use as signing region for AWS Auth")
.write("region?: string | __Provider<string>;\n");


writer.writeDocs(
"""
Setting a client profile is similar to setting a value for the
AWS_PROFILE environment variable. Setting a profile on a client
in code only affects the single client instance, unlike AWS_PROFILE.
When set, and only for environments where a profile configuration
file exists, values configurable by this file will be retrieved
with the specified profile. Conflicting code configuration and
environment variables will still have higher priority.
""")
.write("profile?: string;\n");
}
}

Expand Down Expand Up @@ -145,6 +159,7 @@ public void prepareCustomizations(
writer.addDependency(AwsDependency.AWS_SDK_CORE);
writer.addImport("emitWarningIfUnsupportedVersion", "awsCheckVersion", AwsDependency.AWS_SDK_CORE);
writer.write("awsCheckVersion(process.version);");
writer.write("const profileConfig = { profile: config?.profile };");
}
}

Expand Down Expand Up @@ -173,7 +188,7 @@ private Map<String, Consumer<TypeScriptWriter>> getDefaultConfig(
writer.addImport("NODE_REGION_CONFIG_FILE_OPTIONS", "NODE_REGION_CONFIG_FILE_OPTIONS",
TypeScriptDependency.CONFIG_RESOLVER);
writer.write(
"loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS)");
"loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, {...NODE_REGION_CONFIG_FILE_OPTIONS, ...profileConfig})");
});
default:
return Collections.emptyMap();
Expand Down Expand Up @@ -216,7 +231,7 @@ private Map<String, Consumer<TypeScriptWriter>> getEndpointConfigWriters(
writer.addImport("NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS",
"NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS",
TypeScriptDependency.CONFIG_RESOLVER);
writer.write("loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS)");
writer.write("loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS, profileConfig)");
},
"useFipsEndpoint", writer -> {
writer.addDependency(TypeScriptDependency.NODE_CONFIG_PROVIDER);
Expand All @@ -226,7 +241,7 @@ private Map<String, Consumer<TypeScriptWriter>> getEndpointConfigWriters(
writer.addImport("NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS",
"NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS",
TypeScriptDependency.CONFIG_RESOLVER);
writer.write("loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS)");
writer.write("loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, profileConfig)");
}
);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
writer.addImport("NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS",
"NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS",
AwsDependency.MIDDLEWARE_ENDPOINT_DISCOVERY);
writer.write("loadNodeConfig(NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS)");
writer.write("loadNodeConfig(NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS, profileConfig)");
}
);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
TypeScriptDependency.NODE_CONFIG_PROVIDER);
writer.addImport("NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS", null,
AwsDependency.FLEXIBLE_CHECKSUMS_MIDDLEWARE);
writer.write("loadNodeConfig(NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS)");
writer.write("loadNodeConfig(NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, profileConfig)");
},
"responseChecksumValidation", writer -> {
writer.addDependency(TypeScriptDependency.NODE_CONFIG_PROVIDER);
writer.addImport("loadConfig", "loadNodeConfig",
TypeScriptDependency.NODE_CONFIG_PROVIDER);
writer.addImport("NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS", null,
AwsDependency.FLEXIBLE_CHECKSUMS_MIDDLEWARE);
writer.write("loadNodeConfig(NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS)");
writer.write("loadNodeConfig(NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, profileConfig)");
}
);
case BROWSER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
.addDependency(AwsDependency.BUCKET_ENDPOINT_MIDDLEWARE)
.addImport("NODE_USE_ARN_REGION_CONFIG_OPTIONS", "NODE_USE_ARN_REGION_CONFIG_OPTIONS",
AwsDependency.BUCKET_ENDPOINT_MIDDLEWARE)
.write("loadNodeConfig(NODE_USE_ARN_REGION_CONFIG_OPTIONS)");
.write("loadNodeConfig(NODE_USE_ARN_REGION_CONFIG_OPTIONS, profileConfig)");
},
"disableS3ExpressSessionAuth", writer -> {
writer.addDependency(TypeScriptDependency.NODE_CONFIG_PROVIDER)
Expand All @@ -268,7 +268,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
"NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS",
AwsDependency.S3_MIDDLEWARE
)
.write("loadNodeConfig(NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS)");
.write("loadNodeConfig(NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS, profileConfig)");
}
);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
writer.addDependency(AwsDependency.AWS_SDK_UTIL_USER_AGENT_NODE);
writer.addImport("NODE_APP_ID_CONFIG_OPTIONS", "NODE_APP_ID_CONFIG_OPTIONS",
AwsDependency.AWS_SDK_UTIL_USER_AGENT_NODE);
writer.write("loadNodeConfig(NODE_APP_ID_CONFIG_OPTIONS)");
writer.write("loadNodeConfig(NODE_APP_ID_CONFIG_OPTIONS, profileConfig)");
}
);
case BROWSER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
null,
AwsDependency.AWS_SDK_CORE
);
writer.write("loadNodeConfig(NODE_SIGV4A_CONFIG_OPTIONS)");
writer.write("loadNodeConfig(NODE_SIGV4A_CONFIG_OPTIONS, profileConfig)");
}
);
}
Expand Down

0 comments on commit e62b3a6

Please sign in to comment.