Skip to content

Commit

Permalink
Adjust AWSConfig constructor's to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
oleiade committed Apr 25, 2022
1 parent 0e1ecec commit 37b30c7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/internal/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,36 @@ export class AWSConfig {
* @throws {InvalidArgumentException}
*/
constructor(region: string, accessKeyID: string, secretAccessKey: string) {
if (typeof region !== 'string' || region === '') {
if (region === '') {
throw new InvalidAWSConfigError(
'invalid AWS region; reason: should be a non empty string'
)
}

if (typeof accessKeyID !== 'string' || accessKeyID === '') {
if (accessKeyID === '') {
throw new InvalidAWSConfigError(
'invalid AWS access key ID; reason: should be a non empty string'
)
}

if (typeof secretAccessKey !== 'string' || secretAccessKey === '') {
if (accessKeyID.length < 16 || accessKeyID.length > 128) {
throw new InvalidAWSConfigError(
`invalid AWS access key ID; reason: size should be between 16 and 128 characters, got ${accessKeyID.length}`
)
}

if (secretAccessKey === '') {
throw new InvalidAWSConfigError(
'invalid AWS secret access key; reason: should be a non empty string'
)
}

if (secretAccessKey.length < 16 || secretAccessKey.length > 128) {
throw new InvalidAWSConfigError(
`invalid AWS secret access key; reason: size should be between 16 and 128 characters, got ${secretAccessKey.length}`
)
}

this.region = region
this.accessKeyID = accessKeyID
this.secretAccessKey = secretAccessKey
Expand Down

0 comments on commit 37b30c7

Please sign in to comment.