Skip to content

Commit

Permalink
fix: address feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Apr 15, 2021
1 parent 02b8f57 commit d408cb0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/credential-provider-ini/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,8 @@ credential_source = ${credentialSource}
});
return expect(async () => await provider()).rejects.toMatchObject({
message:
`Unsupported credential source in profile default. Got ${someProvider}, expect EcsContainer or ` +
`Ec2InstanceMetadata or Environment`,
`Unsupported credential source in profile default. Got ${someProvider}, expected EcsContainer or ` +
`Ec2InstanceMetadata or Environment.`,
});
});

Expand Down
18 changes: 6 additions & 12 deletions packages/credential-provider-ini/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,19 @@ interface AssumeRoleWithProviderProfile extends Profile {
credential_source: string;
}

const isAssumeRoleWithSourceProfile = (arg: any): arg is AssumeRoleWithSourceProfile =>
const isAssumeRoleProfile = (arg: any) =>
Boolean(arg) &&
typeof arg === "object" &&
typeof arg.role_arn === "string" &&
typeof arg.source_profile === "string" &&
typeof arg.credential_source === "undefined" &&
["undefined", "string"].indexOf(typeof arg.role_session_name) > -1 &&
["undefined", "string"].indexOf(typeof arg.external_id) > -1 &&
["undefined", "string"].indexOf(typeof arg.mfa_serial) > -1;

const isAssumeRoleWithSourceProfile = (arg: any): arg is AssumeRoleWithSourceProfile =>
isAssumeRoleProfile(arg) && typeof arg.source_profile === "string" && typeof arg.credential_source === "undefined";

const isAssumeRoleWithProviderProfile = (arg: any): arg is AssumeRoleWithProviderProfile =>
Boolean(arg) &&
typeof arg === "object" &&
typeof arg.role_arn === "string" &&
typeof arg.credential_source === "string" &&
typeof arg.source_profile === "undefined" &&
["undefined", "string"].indexOf(typeof arg.role_session_name) > -1 &&
["undefined", "string"].indexOf(typeof arg.external_id) > -1 &&
["undefined", "string"].indexOf(typeof arg.mfa_serial) > -1;
isAssumeRoleProfile(arg) && typeof arg.credential_source === "string" && typeof arg.source_profile === "undefined";

/**
* Creates a credential provider that will read from ini files and supports
Expand Down Expand Up @@ -282,7 +276,7 @@ const resolveCredentialSource = (credentialSource: string, profileName: string):
} else {
throw new ProviderError(
`Unsupported credential source in profile ${profileName}. Got ${credentialSource}, ` +
`expect EcsContainer or Ec2InstanceMetadata or Environment`
`expected EcsContainer or Ec2InstanceMetadata or Environment.`
);
}
};
Expand Down

0 comments on commit d408cb0

Please sign in to comment.