lib-task-scheduler
Advanced tools
Comparing version 4.0.129 to 5.0.133
@@ -19,4 +19,5 @@ import * as AWS from 'aws-sdk'; | ||
export declare class SQSClient { | ||
private config; | ||
private log; | ||
private readonly config; | ||
private readonly log; | ||
private readonly sqsClient; | ||
private queueName; | ||
@@ -54,3 +55,4 @@ private queueUrl; | ||
getOrCreateArn(): Promise<string>; | ||
addSendMessagesPermissions(awsAccountId: string): Promise<any>; | ||
private getCallerAwsAccountId(); | ||
addSendMessagesPermissions(): Promise<any>; | ||
} |
@@ -20,3 +20,3 @@ "use strict"; | ||
this.queueName = `${config.namePrefix}-${queueName}`; | ||
const sqsClient = new AWS.SQS({ | ||
this.sqsClient = new AWS.SQS({ | ||
apiVersion: '2012-11-05', | ||
@@ -26,12 +26,12 @@ credentials: aws_helpers_1.buildAWSCredentials(awsConfig), | ||
}); | ||
const context = { context: sqsClient }; | ||
this.awsGetQueueAttributes = bPromise.promisify(sqsClient.getQueueAttributes, context); | ||
this.awsSetQueueAttributes = bPromise.promisify(sqsClient.setQueueAttributes, context); | ||
this.awsChangeMessageVisibility = bPromise.promisify(sqsClient.changeMessageVisibility, context); | ||
this.awsListQueues = bPromise.promisify(sqsClient.listQueues, context); | ||
this.awsCreateQueue = bPromise.promisify(sqsClient.createQueue, context); | ||
this.awsReceiveMessage = bPromise.promisify(sqsClient.receiveMessage, context); | ||
this.awsSendMessage = bPromise.promisify(sqsClient.sendMessage, context); | ||
this.awsDeleteMessage = bPromise.promisify(sqsClient.deleteMessage, context); | ||
this.awsDeleteQueue = bPromise.promisify(sqsClient.deleteQueue, context); | ||
const context = { context: this.sqsClient }; | ||
this.awsGetQueueAttributes = bPromise.promisify(this.sqsClient.getQueueAttributes, context); | ||
this.awsSetQueueAttributes = bPromise.promisify(this.sqsClient.setQueueAttributes, context); | ||
this.awsChangeMessageVisibility = bPromise.promisify(this.sqsClient.changeMessageVisibility, context); | ||
this.awsListQueues = bPromise.promisify(this.sqsClient.listQueues, context); | ||
this.awsCreateQueue = bPromise.promisify(this.sqsClient.createQueue, context); | ||
this.awsReceiveMessage = bPromise.promisify(this.sqsClient.receiveMessage, context); | ||
this.awsSendMessage = bPromise.promisify(this.sqsClient.sendMessage, context); | ||
this.awsDeleteMessage = bPromise.promisify(this.sqsClient.deleteMessage, context); | ||
this.awsDeleteQueue = bPromise.promisify(this.sqsClient.deleteQueue, context); | ||
this.log = log || new logger_1.NoopLogger(); | ||
@@ -227,5 +227,17 @@ } | ||
} | ||
addSendMessagesPermissions(awsAccountId) { | ||
getCallerAwsAccountId() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const stsClient = new AWS.STS({ | ||
// ensure we're using the exact credentials as the SQS client object. | ||
credentials: this.sqsClient.config.credentials, | ||
region: this.config.region, | ||
}); | ||
const callerIdentity = yield stsClient.getCallerIdentity().promise(); | ||
return callerIdentity.Account; | ||
}); | ||
} | ||
addSendMessagesPermissions() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.log.debug(`Adding SendMessage permissions to queue ${this.queueUrl} for aws account`); | ||
const awsAccountId = yield this.getCallerAwsAccountId(); | ||
const attrs = this.awsAttrsWithTopicWritePermissions(awsAccountId); | ||
@@ -232,0 +244,0 @@ yield this.awsSetQueueAttributes({ |
@@ -6,3 +6,2 @@ import { AwsCredentialsConfig, AwsAssumedRoleCredentialsConfig } from './clients/aws'; | ||
export interface SNSSQSSubscriberConfig { | ||
awsAccountId: string; | ||
awsCredentials?: AwsCredentialsConfig | AwsAssumedRoleCredentialsConfig; | ||
@@ -20,3 +19,2 @@ topicName: string | string[]; | ||
private subscribed; | ||
private readonly awsAccountId; | ||
private readonly topicNames; | ||
@@ -23,0 +21,0 @@ private readonly snsClient; |
@@ -20,3 +20,2 @@ "use strict"; | ||
this.subscribed = false; | ||
this.awsAccountId = config.awsAccountId; | ||
this.topicNames = _.castArray(config.topicName); | ||
@@ -69,3 +68,3 @@ this.snsClient = config.snsClient; | ||
const subscriptionArns = yield Promise.all(this.topicNames.map(topicName => (this.snsClient.subscribeQueueToTopic(topicName, queueArn)))); | ||
yield this.sqsClient.addSendMessagesPermissions(this.awsAccountId); | ||
yield this.sqsClient.addSendMessagesPermissions(); | ||
return subscriptionArns; | ||
@@ -72,0 +71,0 @@ }); |
@@ -24,3 +24,2 @@ "use strict"; | ||
config = { | ||
awsAccountId: '123456', | ||
topicName: 'Topic1', | ||
@@ -27,0 +26,0 @@ snsClient: { |
{ | ||
"name": "lib-task-scheduler", | ||
"version": "4.0.129", | ||
"version": "5.0.133", | ||
"description": "A lightweight, modular task scheduler.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/convoyinc/lib-task-scheduler", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172454
2486