lib-task-scheduler
Advanced tools
Comparing version 1.0.38 to 1.0.42
@@ -29,2 +29,3 @@ import * as AWS from 'aws-sdk'; | ||
private awsAttrs(); | ||
private awsAttrsWithTopicWritePermissions(awsAccountId); | ||
private getQueueAttributes(attrNames); | ||
@@ -47,2 +48,3 @@ /** | ||
getOrCreateArn(): Promise<string>; | ||
addSendMessagesPermissions(awsAccountId: string): Promise<any>; | ||
} |
@@ -46,2 +46,23 @@ "use strict"; | ||
} | ||
awsAttrsWithTopicWritePermissions(awsAccountId) { | ||
const attributes = this.awsAttrs(); | ||
attributes['Policy'] = JSON.stringify({ | ||
'Version': '2012-10-17', | ||
'Id': 'SNStoSQS', | ||
'Statement': [ | ||
{ | ||
'Effect': 'Allow', | ||
'Principal': '*', | ||
'Action': 'sqs:SendMessage', | ||
'Resource': `arn:aws:sqs:*:${awsAccountId}:*`, | ||
'Condition': { | ||
'ArnLike': { | ||
'aws:SourceArn': `arn:aws:sns:*:${awsAccountId}:*`, | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
return attributes; | ||
} | ||
getQueueAttributes(attrNames) { | ||
@@ -67,2 +88,4 @@ return __awaiter(this, void 0, void 0, function* () { | ||
this.log.debug(`Setting queue at ${this.queueUrl} to these attributes ${JSON.stringify(desired)}`); | ||
// This does not overwrite values for attributes that are not included here, such as Policy. | ||
// Thus, Policy (permissions) will not be overwritten here | ||
yield this.awsSetQueueAttributes({ | ||
@@ -175,4 +198,14 @@ QueueUrl: this.queueUrl, | ||
} | ||
addSendMessagesPermissions(awsAccountId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.log.debug(`Adding SendMessage permissions to queue ${this.queueUrl} for aws account`); | ||
const attrs = this.awsAttrsWithTopicWritePermissions(awsAccountId); | ||
yield this.awsSetQueueAttributes({ | ||
QueueUrl: this.queueUrl, | ||
Attributes: attrs, | ||
}); | ||
}); | ||
} | ||
} | ||
exports.SQSClient = SQSClient; | ||
//# sourceMappingURL=sqs.js.map |
@@ -7,2 +7,3 @@ /// <reference types="chai" /> | ||
export interface SNSSQSConsumerTaskConfig { | ||
awsAccountId: string; | ||
topicName: string; | ||
@@ -17,2 +18,3 @@ snsClient: SNSClient; | ||
private subscribed; | ||
private readonly awsAccountId; | ||
private readonly topicName; | ||
@@ -19,0 +21,0 @@ private readonly snsClient; |
@@ -20,2 +20,3 @@ "use strict"; | ||
this.subscribed = false; | ||
this.awsAccountId = config.awsAccountId; | ||
this.topicName = config.topicName; | ||
@@ -60,3 +61,5 @@ this.snsClient = config.snsClient; | ||
const queueArn = yield this.sqsClient.getOrCreateArn(); | ||
return yield this.snsClient.subscribeQueueToTopic(this.topicName, queueArn); | ||
const subscriptionArn = yield this.snsClient.subscribeQueueToTopic(this.topicName, queueArn); | ||
yield this.sqsClient.addSendMessagesPermissions(this.awsAccountId); | ||
return subscriptionArn; | ||
}); | ||
@@ -63,0 +66,0 @@ } |
{ | ||
"name": "lib-task-scheduler", | ||
"version": "1.0.38", | ||
"version": "1.0.42", | ||
"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
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
130017
1896