silvermine / dynamodb-table-sync

MIT License
45 stars 15 forks source link

Add support for cross account syncing #3

Closed jthomerson closed 7 years ago

jthomerson commented 7 years ago

@onebytegone note that this branch also contains the commits in it from #2. You can review just the last commit in this PR, or wait until #2 is merged. I realized this is one more feature I wanted to get into 1.0.0.

jthomerson commented 7 years ago

Back to you @onebytegone. Here are the changes:

jrthomer@work:~/git-clones/dynamodb-table-sync$ git diff 7c1359a..000073f
diff --git a/src/Synchronizer.js b/src/Synchronizer.js
index eec00ee..f1d9b67 100644
--- a/src/Synchronizer.js
+++ b/src/Synchronizer.js
@@ -425,8 +425,8 @@ module.exports = Class.extend({
     */
    _compareTableDescriptions: function() {
       var def = Q.defer(),
-          describeMaster = this._describeTable(undefined, this._master),
-          describeSlaves = Q.all(_.map(this._slaves, this._describeTable.bind(this, this._opts.slaveCredentials)));
+          describeMaster = this._describeTable(this._master),
+          describeSlaves = Q.all(_.map(this._slaves, _.partial(this._describeTable.bind(this), _, this._opts.slaveCredentials)));

       function logDescription(title, tableDef, tableDesc) {
          console.log('%s table %s', title, tableDef.id);
@@ -479,7 +479,7 @@ module.exports = Class.extend({
       return def.promise;
    },

-   _describeTable: function(creds, tableDef) {
+   _describeTable: function(tableDef, creds) {
       var dyn = new AWS.DynamoDB({ region: tableDef.region, credentials: creds || AWS.config.credentials });

       return Q.ninvoke(dyn, 'describeTable', { TableName: tableDef.name })
diff --git a/src/cli.js b/src/cli.js
index 53797fb..46e0163 100755
--- a/src/cli.js
+++ b/src/cli.js
@@ -138,7 +138,7 @@ function setupRoleRelatedCredentials(argPrefix, msg, masterCreds) {
    // See jthomerson comments on https://github.com/aws/aws-sdk-js/issues/1064
    // And subsequently: https://github.com/aws/aws-sdk-js/issues/1664
    startupPromise = startupPromise.then(function() {
-      Q.ninvoke(creds, 'refresh');
+      return Q.ninvoke(creds, 'refresh');
    });

    return creds;
onebytegone commented 7 years ago

👍 looks good