Skip to content

Commit

Permalink
Merge pull request #125 from aehrt55/feature/support-service-account
Browse files Browse the repository at this point in the history
feat: support aws web identity token file
  • Loading branch information
Uriah-Wu authored Oct 7, 2021
2 parents f1558db + a142818 commit 72eb400
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
7 changes: 7 additions & 0 deletions __mocks__/Credentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Credentials {
constructor() {
return {}
}
}

module.exports = Credentials
7 changes: 7 additions & 0 deletions __mocks__/TokenFileWebIdentityCredentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class TokenFileWebIdentityCredentials {
constructor() {
return {}
}
}

module.exports = TokenFileWebIdentityCredentials
4 changes: 4 additions & 0 deletions __mocks__/aws-sdk.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const SQS = require('./SQS.js')
const Credentials = require('./Credentials')
const TokenFileWebIdentityCredentials = require('./TokenFileWebIdentityCredentials')

const AWS = jest.genMockFromModule()

AWS.SQS = SQS
AWS.Credentials = Credentials
AWS.TokenFileWebIdentityCredentials = TokenFileWebIdentityCredentials

module.exports = AWS
23 changes: 19 additions & 4 deletions lib/plugins/sqsMessageQueue/lib/SQSMessageQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* @description the services for connecting rabbit message queue
*/
const fs = require('fs')
const _ = require('lodash')
const Promise = require('bluebird')

Expand All @@ -23,17 +24,31 @@ class SQSMessageQueue {
}
}

get credentials() {
if (this.awsCredentials) {
return awsCredentials;
}
const { Credentials, TokenFileWebIdentityCredentials } = this.aws
const { accessKeyId, secretAccessKey } = this.config
this.awsCredentials = accessKeyId
? new Credentials({
accessKeyId,
secretAccessKey,
})
: new TokenFileWebIdentityCredentials()
return this.awsCredentials
}

get sqs() {
if (!this.singleSqs) {
if (!this.config) return null

const { accessKeyId, secretAccessKey, apiVersion, region } = this.config
const { apiVersion, region } = this.config

this.singleSqs = new this.aws.SQS({
accessKeyId,
secretAccessKey,
apiVersion,
region
region,
credentials: this.credentials,
})
}

Expand Down

0 comments on commit 72eb400

Please sign in to comment.