Skip to content

Commit

Permalink
feat(credential-providers): rename types
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Dec 13, 2024
1 parent 8c3671a commit 90d7122
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AwsIdentityProperties, CredentialProviderOptions, RegionalIdentityProvider } from "@aws-sdk/types";
import type { AwsIdentityProperties, CredentialProviderOptions, RuntimeConfigIdentityProvider } from "@aws-sdk/types";
import { CredentialsProviderError } from "@smithy/property-provider";
import type { AwsCredentialIdentity, Logger } from "@smithy/types";

Expand All @@ -18,7 +18,7 @@ export interface CognitoIdentityCredentials extends AwsCredentialIdentity {
/**
* @internal
*/
export type CognitoIdentityCredentialProvider = RegionalIdentityProvider<CognitoIdentityCredentials>;
export type CognitoIdentityCredentialProvider = RuntimeConfigIdentityProvider<CognitoIdentityCredentials>;

/**
* @internal
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-provider-ini/src/fromIni.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AssumeRoleWithWebIdentityParams } from "@aws-sdk/credential-provider-web-identity";
import type { CredentialProviderOptions } from "@aws-sdk/types";
import type { RegionalAwsCredentialIdentityProvider } from "@aws-sdk/types";
import type { RuntimeConfigAwsCredentialIdentityProvider } from "@aws-sdk/types";
import { getProfileName, parseKnownFiles, SourceProfileInit } from "@smithy/shared-ini-file-loader";
import type { AwsCredentialIdentity, Pluggable } from "@smithy/types";

Expand Down Expand Up @@ -56,7 +56,7 @@ export interface FromIniInit extends SourceProfileInit, CredentialProviderOption
* role assumption and multi-factor authentication.
*/
export const fromIni =
(_init: FromIniInit = {}): RegionalAwsCredentialIdentityProvider =>
(_init: FromIniInit = {}): RuntimeConfigAwsCredentialIdentityProvider =>
async ({ callerClientConfig } = {}) => {
const init: FromIniInit = {
..._init,
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-provider-web-identity/src/fromWebToken.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
AwsIdentityProperties,
CredentialProviderOptions,
RegionalAwsCredentialIdentityProvider,
RuntimeConfigAwsCredentialIdentityProvider,
} from "@aws-sdk/types";
import type { AwsCredentialIdentity, Pluggable } from "@smithy/types";

Expand Down Expand Up @@ -155,7 +155,7 @@ export interface FromWebTokenInit
* @internal
*/
export const fromWebToken =
(init: FromWebTokenInit): RegionalAwsCredentialIdentityProvider =>
(init: FromWebTokenInit): RuntimeConfigAwsCredentialIdentityProvider =>
async (awsIdentityProperties?: AwsIdentityProperties) => {
init.logger?.debug("@aws-sdk/credential-provider-web-identity - fromWebToken");
const { roleArn, roleSessionName, webIdentityToken, providerId, policyArns, policy, durationSeconds } = init;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RegionalAwsCredentialIdentityProvider } from "@aws-sdk/types";
import { RuntimeConfigAwsCredentialIdentityProvider } from "@aws-sdk/types";
import { ProviderError } from "@smithy/property-provider";
import { AwsCredentialIdentity, AwsCredentialIdentityProvider } from "@smithy/types";
import { describe, expect, test as it } from "vitest";
Expand Down Expand Up @@ -82,7 +82,7 @@ describe(createCredentialChain.name, () => {
});

it("is compatible with contextual-region-aware credential providers", async () => {
const provider: RegionalAwsCredentialIdentityProvider = async ({ callerClientConfig } = {}) => {
const provider: RuntimeConfigAwsCredentialIdentityProvider = async ({ callerClientConfig } = {}) => {
return {
accessKeyId: "",
secretAccessKey: "",
Expand Down
10 changes: 5 additions & 5 deletions packages/credential-providers/src/createCredentialChain.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
AwsIdentityProperties,
RegionalAwsCredentialIdentityProvider,
RegionalIdentityProvider,
RuntimeConfigAwsCredentialIdentityProvider,
RuntimeConfigIdentityProvider,
} from "@aws-sdk/types";
import { ProviderError } from "@smithy/property-provider";
import type { AwsCredentialIdentityProvider } from "@smithy/types";
Expand Down Expand Up @@ -57,8 +57,8 @@ type Mutable<Type> = {
* providers in sequence until one succeeds or all fail.
*/
export const createCredentialChain = (
...credentialProviders: RegionalAwsCredentialIdentityProvider[]
): RegionalAwsCredentialIdentityProvider & CustomCredentialChainOptions => {
...credentialProviders: RuntimeConfigAwsCredentialIdentityProvider[]
): RuntimeConfigAwsCredentialIdentityProvider & CustomCredentialChainOptions => {
let expireAfter = -1;
const baseFunction = async (awsIdentityProperties?: AwsIdentityProperties) => {
const credentials = await propertyProviderChain(...credentialProviders)(awsIdentityProperties);
Expand All @@ -85,7 +85,7 @@ export const createCredentialChain = (
* @internal
*/
export const propertyProviderChain =
<T>(...providers: Array<RegionalIdentityProvider<T>>): RegionalIdentityProvider<T> =>
<T>(...providers: Array<RuntimeConfigIdentityProvider<T>>): RuntimeConfigIdentityProvider<T> =>
async (awsIdentityProperties?: AwsIdentityProperties) => {
if (providers.length === 0) {
throw new ProviderError("No providers in chain");
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-providers/src/fromIni.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fromIni as _fromIni, FromIniInit } from "@aws-sdk/credential-provider-ini";
import type { RegionalAwsCredentialIdentityProvider } from "@aws-sdk/types";
import type { RuntimeConfigAwsCredentialIdentityProvider } from "@aws-sdk/types";

/**
* Creates a credential provider function that reads from a shared credentials file at `~/.aws/credentials` and a
Expand Down Expand Up @@ -40,7 +40,7 @@ import type { RegionalAwsCredentialIdentityProvider } from "@aws-sdk/types";
* });
* ```
*/
export const fromIni = (init: FromIniInit = {}): RegionalAwsCredentialIdentityProvider =>
export const fromIni = (init: FromIniInit = {}): RuntimeConfigAwsCredentialIdentityProvider =>
_fromIni({
...init,
});
8 changes: 4 additions & 4 deletions packages/middleware-signing/src/awsAuthConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AwsCredentialIdentityProvider, RegionalAwsCredentialIdentityProvider } from "@aws-sdk/types";
import type { AwsCredentialIdentityProvider, RuntimeConfigAwsCredentialIdentityProvider } from "@aws-sdk/types";
import { memoize } from "@smithy/property-provider";
import { SignatureV4, SignatureV4CryptoInit, SignatureV4Init } from "@smithy/signature-v4";
import {
Expand Down Expand Up @@ -293,7 +293,7 @@ export const resolveSigV4AuthConfig = <T>(
* @deprecated only used in legacy auth.
*/
const normalizeCredentialProvider = (
credentials: AwsCredentialIdentity | Provider<AwsCredentialIdentity> | RegionalAwsCredentialIdentityProvider
credentials: AwsCredentialIdentity | Provider<AwsCredentialIdentity> | RuntimeConfigAwsCredentialIdentityProvider
): MemoizedProvider<AwsCredentialIdentity> => {
if (typeof credentials === "function") {
return memoize(
Expand All @@ -315,7 +315,7 @@ const normalizeCredentialProvider = (
* a binding to the config itself.
*/
const createConfigBoundCredentialProvider = (input: {
credentials?: AwsCredentialIdentity | AwsCredentialIdentityProvider | RegionalAwsCredentialIdentityProvider;
credentials?: AwsCredentialIdentity | AwsCredentialIdentityProvider | RuntimeConfigAwsCredentialIdentityProvider;
credentialDefaultProvider: PreviouslyResolved["credentialDefaultProvider"];
region: PreviouslyResolved["region"];
}): AwsCredentialIdentityProvider => {
Expand All @@ -327,7 +327,7 @@ const createConfigBoundCredentialProvider = (input: {
})
);
const normalizedCreds = async () =>
(normalizedCredentialsProvider as RegionalAwsCredentialIdentityProvider)({
(normalizedCredentialsProvider as RuntimeConfigAwsCredentialIdentityProvider)({
callerClientConfig: {
region: normalizeProvider(input.region),
},
Expand Down
4 changes: 2 additions & 2 deletions packages/token-providers/src/fromSso.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
AwsIdentityProperties,
CredentialProviderOptions,
RegionalIdentityProvider,
RuntimeConfigIdentityProvider,
TokenIdentity,
} from "@aws-sdk/types";
import { TokenProviderError } from "@smithy/property-provider";
Expand Down Expand Up @@ -36,7 +36,7 @@ export interface FromSsoInit extends SourceProfileInit, CredentialProviderOption
* Creates a token provider that will read from SSO token cache or ssoOidc.createToken() call.
*/
export const fromSso =
(_init: FromSsoInit = {}): RegionalIdentityProvider<TokenIdentity> =>
(_init: FromSsoInit = {}): RuntimeConfigIdentityProvider<TokenIdentity> =>
async (awsIdentityProperties?: AwsIdentityProperties) => {
const init: FromSsoInit = {
..._init,
Expand Down
14 changes: 8 additions & 6 deletions packages/types/src/identity/AwsCredentialIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ export interface AwsIdentityProperties {
* @public
*
* Variation of {@link IdentityProvider} which accepts a contextual
* client configuration that includes an AWS region.
* client configuration that includes an AWS region and potentially other
* configurable fields.
*
* Used to link a credential provider to a client region if it is being called
* Used to link a credential provider to a client if it is being called
* in the context of a client.
*/
export type RegionalIdentityProvider<T> = (awsIdentityProperties?: AwsIdentityProperties) => Promise<T>;
export type RuntimeConfigIdentityProvider<T> = (awsIdentityProperties?: AwsIdentityProperties) => Promise<T>;

/**
* @public
*
* Variation of {@link AwsCredentialIdentityProvider} which accepts a contextual
* client configuration that includes an AWS region.
* client configuration that includes an AWS region and potentially other
* configurable fields.
*
* Used to link a credential provider to a client region if it is being called
* Used to link a credential provider to a client if it is being called
* in the context of a client.
*/
export type RegionalAwsCredentialIdentityProvider = RegionalIdentityProvider<AwsCredentialIdentity>;
export type RuntimeConfigAwsCredentialIdentityProvider = RuntimeConfigIdentityProvider<AwsCredentialIdentity>;

/**
* @public
Expand Down

0 comments on commit 90d7122

Please sign in to comment.