Skip to content

feat(types): update identity types #4189

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

Merged
merged 2 commits into from
Nov 18, 2022
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
@@ -1,11 +1,11 @@
import { GetCredentialsForIdentityCommand } from "@aws-sdk/client-cognito-identity";
import { CredentialsProviderError } from "@aws-sdk/property-provider";
import { Credentials, Provider } from "@aws-sdk/types";
import { AwsCredentialIdentity, Provider } from "@aws-sdk/types";

import { CognitoProviderParameters } from "./CognitoProviderParameters";
import { resolveLogins } from "./resolveLogins";

export interface CognitoIdentityCredentials extends Credentials {
export interface CognitoIdentityCredentials extends AwsCredentialIdentity {
/**
* The Cognito ID returned by the last call to AWS.CognitoIdentity.getOpenIdToken().
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-provider-env/src/fromEnv.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CredentialsProviderError } from "@aws-sdk/property-provider";
import { CredentialProvider } from "@aws-sdk/types";
import { AwsCredentialIdentityProvider } from "@aws-sdk/types";

export const ENV_KEY = "AWS_ACCESS_KEY_ID";
export const ENV_SECRET = "AWS_SECRET_ACCESS_KEY";
Expand All @@ -11,7 +11,7 @@ export const ENV_EXPIRATION = "AWS_CREDENTIAL_EXPIRATION";
* `AWS_ACCESS_KEY_ID` or `AWS_SECRET_ACCESS_KEY` environment variable is not
* set in this process, the provider will return a rejected promise.
*/
export const fromEnv = (): CredentialProvider => async () => {
export const fromEnv = (): AwsCredentialIdentityProvider => async () => {
const accessKeyId: string | undefined = process.env[ENV_KEY];
const secretAccessKey: string | undefined = process.env[ENV_SECRET];
const sessionToken: string | undefined = process.env[ENV_SESSION];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CredentialsProviderError } from "@aws-sdk/property-provider";
import { CredentialProvider } from "@aws-sdk/types";
import { AwsCredentialIdentityProvider } from "@aws-sdk/types";
import { RequestOptions } from "http";
import { parse } from "url";

Expand All @@ -16,7 +16,7 @@ export const ENV_CMDS_AUTH_TOKEN = "AWS_CONTAINER_AUTHORIZATION_TOKEN";
* Creates a credential provider that will source credentials from the ECS
* Container Metadata Service
*/
export const fromContainerMetadata = (init: RemoteProviderInit = {}): CredentialProvider => {
export const fromContainerMetadata = (init: RemoteProviderInit = {}): AwsCredentialIdentityProvider => {
const { timeout, maxRetries } = providerConfigFromInit(init);
return () =>
retry(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CredentialsProviderError } from "@aws-sdk/property-provider";
import { Credentials, Provider } from "@aws-sdk/types";
import { AwsCredentialIdentity, Provider } from "@aws-sdk/types";
import { RequestOptions } from "http";

import { httpRequest } from "./remoteProvider/httpRequest";
Expand Down Expand Up @@ -42,7 +42,7 @@ const getInstanceImdsProvider = (init: RemoteProviderInit) => {
).trim();

return retry(async () => {
let creds: Credentials;
let creds: AwsCredentialIdentity;
try {
creds = await getCredentialsFromProfile(profile, options);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Credentials } from "@aws-sdk/types";
import { AwsCredentialIdentity } from "@aws-sdk/types";

import { fromImdsCredentials, ImdsCredentials, isImdsCredentials } from "./ImdsCredentials";

Expand Down Expand Up @@ -39,7 +39,7 @@ describe("isImdsCredentials", () => {

describe("fromImdsCredentials", () => {
it("should convert IMDS credentials to a credentials object", () => {
const converted: Credentials = fromImdsCredentials(creds);
const converted: AwsCredentialIdentity = fromImdsCredentials(creds);
expect(converted.accessKeyId).toEqual(creds.AccessKeyId);
expect(converted.secretAccessKey).toEqual(creds.SecretAccessKey);
expect(converted.sessionToken).toEqual(creds.Token);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Credentials } from "@aws-sdk/types";
import { AwsCredentialIdentity } from "@aws-sdk/types";

export interface ImdsCredentials {
AccessKeyId: string;
Expand All @@ -15,7 +15,7 @@ export const isImdsCredentials = (arg: any): arg is ImdsCredentials =>
typeof arg.Token === "string" &&
typeof arg.Expiration === "string";

export const fromImdsCredentials = (creds: ImdsCredentials): Credentials => ({
export const fromImdsCredentials = (creds: ImdsCredentials): AwsCredentialIdentity => ({
accessKeyId: creds.AccessKeyId,
secretAccessKey: creds.SecretAccessKey,
sessionToken: creds.Token,
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-provider-imds/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Credentials } from "@aws-sdk/types";
import { AwsCredentialIdentity } from "@aws-sdk/types";

export interface InstanceMetadataCredentials extends Credentials {
export interface InstanceMetadataCredentials extends AwsCredentialIdentity {
readonly originalExpiration?: Date;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Credentials, Logger, Provider } from "@aws-sdk/types";
import { AwsCredentialIdentity, Logger, Provider } from "@aws-sdk/types";

import { InstanceMetadataCredentials } from "../types";
import { getExtendedInstanceMetadataCredentials } from "./getExtendedInstanceMetadataCredentials";
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-provider-ini/src/fromIni.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getProfileName, parseKnownFiles } from "@aws-sdk/shared-ini-file-loader";
import { Credentials } from "@aws-sdk/types";
import { AwsCredentialIdentity } from "@aws-sdk/types";

import { fromIni } from "./fromIni";
import { resolveProfileData } from "./resolveProfileData";
Expand Down Expand Up @@ -51,7 +51,7 @@ describe(fromIni.name, () => {
});

it("returns resolved process creds", async () => {
const expectedCreds: Credentials = {
const expectedCreds: AwsCredentialIdentity = {
accessKeyId: "mockAccessKeyId",
secretAccessKey: "mockSecretAccessKey",
};
Expand Down
8 changes: 4 additions & 4 deletions packages/credential-provider-ini/src/fromIni.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AssumeRoleWithWebIdentityParams } from "@aws-sdk/credential-provider-web-identity";
import { getProfileName, parseKnownFiles, SourceProfileInit } from "@aws-sdk/shared-ini-file-loader";
import { CredentialProvider, Credentials } from "@aws-sdk/types";
import { AwsCredentialIdentity, AwsCredentialIdentityProvider } from "@aws-sdk/types";

import { AssumeRoleParams } from "./resolveAssumeRoleCredentials";
import { resolveProfileData } from "./resolveProfileData";
Expand All @@ -23,7 +23,7 @@ export interface FromIniInit extends SourceProfileInit {
* @param sourceCreds The credentials with which to assume a role.
* @param params
*/
roleAssumer?: (sourceCreds: Credentials, params: AssumeRoleParams) => Promise<Credentials>;
roleAssumer?: (sourceCreds: AwsCredentialIdentity, params: AssumeRoleParams) => Promise<AwsCredentialIdentity>;

/**
* A function that assumes a role with web identity and returns a promise fulfilled with
Expand All @@ -32,15 +32,15 @@ export interface FromIniInit extends SourceProfileInit {
* @param sourceCreds The credentials with which to assume a role.
* @param params
*/
roleAssumerWithWebIdentity?: (params: AssumeRoleWithWebIdentityParams) => Promise<Credentials>;
roleAssumerWithWebIdentity?: (params: AssumeRoleWithWebIdentityParams) => Promise<AwsCredentialIdentity>;
}

/**
* Creates a credential provider that will read from ini files and supports
* role assumption and multi-factor authentication.
*/
export const fromIni =
(init: FromIniInit = {}): CredentialProvider =>
(init: FromIniInit = {}): AwsCredentialIdentityProvider =>
async () => {
const profiles = await parseKnownFiles(init);
return resolveProfileData(getProfileName(init), profiles, init);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fromEnv } from "@aws-sdk/credential-provider-env";
import { fromContainerMetadata, fromInstanceMetadata } from "@aws-sdk/credential-provider-imds";
import { CredentialsProviderError } from "@aws-sdk/property-provider";
import { CredentialProvider } from "@aws-sdk/types";
import { AwsCredentialIdentityProvider } from "@aws-sdk/types";

/**
* Resolve the `credential_source` entry from the profile, and return the
Expand All @@ -10,8 +10,8 @@ import { CredentialProvider } from "@aws-sdk/types";
* fromIni() provider. The source credential needs to be refreshed every time
* fromIni() is called.
*/
export const resolveCredentialSource = (credentialSource: string, profileName: string): CredentialProvider => {
const sourceProvidersMap: Record<string, () => CredentialProvider> = {
export const resolveCredentialSource = (credentialSource: string, profileName: string): AwsCredentialIdentityProvider => {
const sourceProvidersMap: Record<string, () => AwsCredentialIdentityProvider> = {
EcsContainer: fromContainerMetadata,
Ec2InstanceMetadata: fromInstanceMetadata,
Environment: fromEnv,
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-provider-ini/src/resolveProfileData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CredentialsProviderError } from "@aws-sdk/property-provider";
import { Credentials, ParsedIniData } from "@aws-sdk/types";
import { AwsCredentialIdentity, ParsedIniData } from "@aws-sdk/types";

import { FromIniInit } from "./fromIni";
import { isAssumeRoleProfile, resolveAssumeRoleCredentials } from "./resolveAssumeRoleCredentials";
Expand All @@ -12,7 +12,7 @@ export const resolveProfileData = async (
profiles: ParsedIniData,
options: FromIniInit,
visitedProfiles: Record<string, true> = {}
): Promise<Credentials> => {
): Promise<AwsCredentialIdentity> => {
const data = profiles[profileName];

// If this is not the first profile visited, static credentials should be
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fromSSO, isSsoProfile as origIsSsoProfile, validateSsoProfile } from "@aws-sdk/credential-provider-sso";
import { Credentials } from "@aws-sdk/types";
import { AwsCredentialIdentity } from "@aws-sdk/types";

import { isSsoProfile, resolveSsoCredentials } from "./resolveSsoCredentials";

Expand Down Expand Up @@ -79,7 +79,7 @@ describe(resolveSsoCredentials.name, () => {
const mockProfile = getMockOriginalSsoProfile();
const mockValidatedProfile = getMockValidatedSsoProfile();

const mockCreds: Credentials = {
const mockCreds: AwsCredentialIdentity = {
accessKeyId: "mockAccessKeyId",
secretAccessKey: "mockSecretAccessKey",
};
Expand All @@ -104,7 +104,7 @@ describe(resolveSsoCredentials.name, () => {
sso_session: "test-session",
});

const mockCreds: Credentials = {
const mockCreds: AwsCredentialIdentity = {
accessKeyId: "mockAccessKeyId",
secretAccessKey: "mockSecretAccessKey",
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Credentials, Profile } from "@aws-sdk/types";
import { AwsCredentialIdentity, Profile } from "@aws-sdk/types";

export interface StaticCredsProfile extends Profile {
aws_access_key_id: string;
Expand All @@ -13,7 +13,7 @@ export const isStaticCredsProfile = (arg: any): arg is StaticCredsProfile =>
typeof arg.aws_secret_access_key === "string" &&
["undefined", "string"].indexOf(typeof arg.aws_session_token) > -1;

export const resolveStaticCredentials = (profile: StaticCredsProfile): Promise<Credentials> =>
export const resolveStaticCredentials = (profile: StaticCredsProfile): Promise<AwsCredentialIdentity> =>
Promise.resolve({
accessKeyId: profile.aws_access_key_id,
secretAccessKey: profile.aws_secret_access_key,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fromTokenFile } from "@aws-sdk/credential-provider-web-identity";
import { Credentials } from "@aws-sdk/types";
import { AwsCredentialIdentity } from "@aws-sdk/types";

import { isWebIdentityProfile, resolveWebIdentityCredentials } from "./resolveWebIdentityCredentials";

Expand Down Expand Up @@ -42,7 +42,7 @@ describe(isWebIdentityProfile.name, () => {
});

describe(resolveWebIdentityCredentials.name, () => {
const mockCreds: Credentials = {
const mockCreds: AwsCredentialIdentity = {
accessKeyId: "mockAccessKeyId",
secretAccessKey: "mockSecretAccessKey",
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fromTokenFile } from "@aws-sdk/credential-provider-web-identity";
import { Credentials, Profile } from "@aws-sdk/types";
import { AwsCredentialIdentity, Profile } from "@aws-sdk/types";

import { FromIniInit } from "./fromIni";

Expand All @@ -19,7 +19,7 @@ export const isWebIdentityProfile = (arg: any): arg is WebIdentityProfile =>
export const resolveWebIdentityCredentials = async (
profile: WebIdentityProfile,
options: FromIniInit
): Promise<Credentials> =>
): Promise<AwsCredentialIdentity> =>
fromTokenFile({
webIdentityTokenFile: profile.web_identity_token_file,
roleArn: profile.role_arn,
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-provider-node/src/defaultProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fromSSO, FromSSOInit } from "@aws-sdk/credential-provider-sso";
import { fromTokenFile, FromTokenFileInit } from "@aws-sdk/credential-provider-web-identity";
import { chain, CredentialsProviderError, memoize } from "@aws-sdk/property-provider";
import { ENV_PROFILE } from "@aws-sdk/shared-ini-file-loader";
import { Credentials, MemoizedProvider } from "@aws-sdk/types";
import { AwsCredentialIdentity, MemoizedProvider } from "@aws-sdk/types";

import { remoteProvider } from "./remoteProvider";

Expand Down Expand Up @@ -46,7 +46,7 @@ export type DefaultProviderInit = FromIniInit & RemoteProviderInit & FromProcess
* @see {@link fromContainerMetadata} The function used to source credentials from the
* ECS Container Metadata Service
*/
export const defaultProvider = (init: DefaultProviderInit = {}): MemoizedProvider<Credentials> =>
export const defaultProvider = (init: DefaultProviderInit = {}): MemoizedProvider<AwsCredentialIdentity> =>
memoize(
chain(
...(init.profile || process.env[ENV_PROFILE] ? [] : [fromEnv()]),
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-provider-node/src/remoteProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
RemoteProviderInit,
} from "@aws-sdk/credential-provider-imds";
import { CredentialsProviderError } from "@aws-sdk/property-provider";
import { CredentialProvider } from "@aws-sdk/types";
import { AwsCredentialIdentityProvider } from "@aws-sdk/types";

export const ENV_IMDS_DISABLED = "AWS_EC2_METADATA_DISABLED";

export const remoteProvider = (init: RemoteProviderInit): CredentialProvider => {
export const remoteProvider = (init: RemoteProviderInit): AwsCredentialIdentityProvider => {
if (process.env[ENV_CMDS_RELATIVE_URI] || process.env[ENV_CMDS_FULL_URI]) {
return fromContainerMetadata(init);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getProfileName, parseKnownFiles } from "@aws-sdk/shared-ini-file-loader";
import { Credentials } from "@aws-sdk/types";
import { AwsCredentialIdentity } from "@aws-sdk/types";

import { fromProcess } from "./fromProcess";
import { resolveProcessCredentials } from "./resolveProcessCredentials";
Expand Down Expand Up @@ -51,7 +51,7 @@ describe(fromProcess.name, () => {
});

it("returns resolved process creds", async () => {
const expectedCreds: Credentials = {
const expectedCreds: AwsCredentialIdentity = {
accessKeyId: "mockAccessKeyId",
secretAccessKey: "mockSecretAccessKey",
};
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-provider-process/src/fromProcess.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getProfileName, parseKnownFiles, SourceProfileInit } from "@aws-sdk/shared-ini-file-loader";
import { CredentialProvider } from "@aws-sdk/types";
import { AwsCredentialIdentityProvider } from "@aws-sdk/types";

import { resolveProcessCredentials } from "./resolveProcessCredentials";

Expand All @@ -10,7 +10,7 @@ export interface FromProcessInit extends SourceProfileInit {}
* in ini files.
*/
export const fromProcess =
(init: FromProcessInit = {}): CredentialProvider =>
(init: FromProcessInit = {}): AwsCredentialIdentityProvider =>
async () => {
const profiles = await parseKnownFiles(init);
return resolveProcessCredentials(getProfileName(init), profiles);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Credentials } from "@aws-sdk/types";
import { AwsCredentialIdentity } from "@aws-sdk/types";

import { getValidatedProcessCredentials } from "./getValidatedProcessCredentials";
import { ProcessCredentials } from "./ProcessCredentials";
Expand Down Expand Up @@ -47,7 +47,7 @@ describe(getValidatedProcessCredentials.name, () => {
});

describe("returns validated Process credentials", () => {
const getValidatedCredentials = (data: ProcessCredentials): Credentials => ({
const getValidatedCredentials = (data: ProcessCredentials): AwsCredentialIdentity => ({
accessKeyId: data.AccessKeyId,
secretAccessKey: data.SecretAccessKey,
...(data.SessionToken && { sessionToken: data.SessionToken }),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Credentials } from "@aws-sdk/types";
import { AwsCredentialIdentity } from "@aws-sdk/types";

import { ProcessCredentials } from "./ProcessCredentials";

export const getValidatedProcessCredentials = (profileName: string, data: ProcessCredentials): Credentials => {
export const getValidatedProcessCredentials = (profileName: string, data: ProcessCredentials): AwsCredentialIdentity => {
if (data.Version !== 1) {
throw Error(`Profile ${profileName} credential_process did not return Version 1.`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CredentialsProviderError } from "@aws-sdk/property-provider";
import { Credentials } from "@aws-sdk/types";
import { AwsCredentialIdentity } from "@aws-sdk/types";
import { promisify } from "util";

import { getValidatedProcessCredentials } from "./getValidatedProcessCredentials";
Expand Down Expand Up @@ -103,7 +103,7 @@ describe(resolveProcessCredentials.name, () => {
});

it("returns data from getValidatedProcessCredentials", async () => {
const expectedCreds: Credentials = {
const expectedCreds: AwsCredentialIdentity = {
accessKeyId: "mockAccessKeyId",
secretAccessKey: "mockSecretAccessKey",
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CredentialsProviderError } from "@aws-sdk/property-provider";
import { Credentials, ParsedIniData } from "@aws-sdk/types";
import { AwsCredentialIdentity, ParsedIniData } from "@aws-sdk/types";
import { exec } from "child_process";
import { promisify } from "util";

import { getValidatedProcessCredentials } from "./getValidatedProcessCredentials";
import { ProcessCredentials } from "./ProcessCredentials";

export const resolveProcessCredentials = async (profileName: string, profiles: ParsedIniData): Promise<Credentials> => {
export const resolveProcessCredentials = async (profileName: string, profiles: ParsedIniData): Promise<AwsCredentialIdentity> => {
const profile = profiles[profileName];

if (profiles[profileName]) {
Expand Down
Loading