Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/lib/Provisioning/ResourceTagging/Driver/DynamoDBDriver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Created by CCristi on 2/2/17.
*/

'use strict';

import {AbstractDriver} from './AbstractDriver';
import Core from 'deep-core';

export class DynamoDBDriver extends AbstractDriver {
/**
* @param {Object[]} args
*/
constructor(...args) {
super(...args);

this._dynamoDB = this.provisioning.dynamoDB;
}

/**
* @param {Function} callback
*/
tag(callback) {
let tagsPayload = this.tagsPayload;

let tagPromises = this.tablesArns.map(tableArn => {
let payload = {
ResourceArn: tableArn,
Tags: tagsPayload,
};

return this._dynamoDB.tagResource(payload).promise().then(() => {
console.debug(`"${tableArn}" has been successfully tagged`);
}).catch(e => {
console.warn(`Error on tagging "${tableArn}": ${e}`);
});
});

Promise.all(tagPromises)
.then(responses => callback(null, responses))
.catch(e => callback(e, null));
}

/**
* @returns {String[]}
*/
get tablesArns() {
let config = this.property.config;
let tablesObj = this.provisioning.config[Core.AWS.Service.DYNAMO_DB].tablesNames;
let tableArns = [];

for (let modelName in tablesObj) {
if (tablesObj.hasOwnProperty(modelName)) {
tableArns.push(
`arn:aws:${Core.AWS.Service.DYNAMO_DB}:${config.aws.region}:` +
`${config.awsAccountId}:table/${tablesObj[modelName]}`
);
}
}

return tableArns;
}
}
4 changes: 3 additions & 1 deletion src/lib/Provisioning/ResourceTagging/Tagging.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {WaitFor} from '../../Helpers/WaitFor';
import {S3Driver} from './Driver/S3Driver';
import {ESDriver} from './Driver/ESDriver';
import {CloudFrontDriver} from './Driver/CloudFrontDriver';
import {DynamoDBDriver} from './Driver/DynamoDBDriver';

export class Tagging {
/**
Expand All @@ -28,8 +29,9 @@ export class Tagging {
let s3Driver = new S3Driver(property, applicationName);
let esDriver = new ESDriver(property, applicationName);
let cloudFrontDriver = new CloudFrontDriver(property, applicationName);
let dynamoDbDriver = new DynamoDBDriver(property, applicationName);

return new Tagging(s3Driver, esDriver, cloudFrontDriver);
return new Tagging(s3Driver, esDriver, cloudFrontDriver, dynamoDbDriver);
}

/**
Expand Down