• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

silvermine / dynamodb-table-sync / 9819479197

06 Jul 2024 01:03PM UTC coverage: 0.0%. Remained the same
9819479197

Pull #26

github

web-flow
Merge 7ef89f21c into 80edaf9a1
Pull Request #26: feat: Add support for synchronizing to a local slave instance

0 of 132 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 18 new or added lines in 2 files covered. (0.0%)

157 existing lines in 2 files now uncovered.

0 of 287 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/cli.js
1
#!/usr/bin/env node
2
'use strict';
3

4
var _ = require('underscore'),
×
5
    Q = require('q'),
×
6
    AWS = require('aws-sdk'),
×
7
    minimist = require('minimist'),
×
8
    Synchronizer = require('./Synchronizer'),
×
9
    startupPromise = Q.when(),
×
10
    argvOpts, argv, argsFailed, options;
11

12
argvOpts = {
×
13
   string: [
14
      'master',
15
      'slaves',
16
      'ignore-atts',
17
      'starting-key',
18
      'profile',
19
      'role-arn',
20
      'mfa-serial',
21
      'mfa-token',
22
      'slave-profile',
23
      'slave-role-arn',
24
      'slave-mfa-serial',
25
      'slave-mfa-token',
26
   ],
27
   'boolean': [ 'write-missing', 'write-differing', 'scan-for-extra', 'delete-extra', 'verbose' ],
28
   'default': {
29
      'verbose': false,
30
      'write-missing': false,
31
      'write-differing': false,
32
      'scan-for-extra': false,
33
      'delete-extra': false,
34
   },
35
   alias: {
36
      master: 'm',
37
      slaves: [ 's', 'slave' ],
38
      verbose: 'v',
39
      'ignore-atts': [ 'ignore', 'ignore-att' ],
40
   },
41
};
42

UNCOV
43
argv = minimist(process.argv.slice(2), argvOpts);
×
44

45
function mapTableName(type, name) {
UNCOV
46
   var parts = name.split(':');
×
47

UNCOV
48
   if (parts.length !== 2) {
×
49
      console.log('Your table name must be supplied in two parts: "<region>:<table-name>"');
×
50
      console.log('This %s table does not meet that requirement:', type, name);
×
51
      argsFailed = true;
×
52
   }
53

UNCOV
54
   return { region: parts[0], name: parts[1] };
×
55
}
56

UNCOV
57
if (_.isEmpty(argv.master)) {
×
58
   console.log('Must supply a master table: --master <region>:<table>');
×
59
   argsFailed = true;
×
60
} else if (_.isArray(argv.master)) {
×
61
   console.log('Can only supply one master table. You supplied:', argv.master);
×
62
   argsFailed = true;
×
63
} else {
UNCOV
64
   argv.master = mapTableName('master', argv.master);
×
65
}
66

UNCOV
67
if (_.isEmpty(argv.slaves)) {
×
68
   console.log('Must supply one or more slave tables: --slave <region>:<table>');
×
69
   console.log('Or: --slave <region>:<table> --slave <region>:<table>');
×
70
   argsFailed = true;
×
71
} else if (!_.isArray(argv.slaves)) {
×
72
   argv.slaves = [ argv.slaves ];
×
73
}
74

UNCOV
75
if (_.isEmpty(argv['ignore-atts'])) {
×
76
   argv['ignore-atts'] = [];
×
77
} else if (!_.isArray(argv['ignore-atts'])) {
×
78
   argv['ignore-atts'] = [ argv['ignore-atts'] ];
×
79
}
80

UNCOV
81
argv.slaves = _.map(argv.slaves, mapTableName.bind(null, 'slave'));
×
82

UNCOV
83
if (_.isEmpty(argv['starting-key'])) {
×
84
   argv['starting-key'] = undefined;
×
85
} else {
UNCOV
86
   if (argv.parallel) {
×
87
      console.log('ERROR: --starting-key can not be used when using --parallel');
×
88
      console.log('because each segment would need its own starting key.');
×
89
      argsFailed = true;
×
90
   }
91

UNCOV
92
   argv['starting-key'] = JSON.parse(argv['starting-key']);
×
93
}
94

UNCOV
95
if (argsFailed) {
×
96
   process.exit(1); // eslint-disable-line no-process-exit
×
97
}
98

UNCOV
99
options = {
×
100
   verbose: argv.verbose,
101
   writeMissing: argv['write-missing'],
102
   writeDiffering: argv['write-differing'],
103
   deleteExtra: argv['delete-extra'],
104
   scanForExtra: argv['scan-for-extra'],
105
   ignoreAtts: argv['ignore-atts'],
106
   startingKey: argv['starting-key'],
107
};
108

UNCOV
109
if (_.isNumber(argv['scan-limit'])) {
×
110
   options.scanLimit = parseInt(argv['scan-limit'], 10);
×
111
}
112

UNCOV
113
options.batchReadLimit = _.isNumber(argv['batch-read-limit']) ? parseInt(argv['batch-read-limit'], 10) : 50;
×
114

UNCOV
115
options.maxRetries = _.isNumber(argv['max-retries']) ? parseInt(argv['max-retries'], 10) : 10;
×
116

UNCOV
117
options.retryDelayBase = _.isNumber(argv['retry-delay-base']) ? parseInt(argv['retry-delay-base'], 10) : 50;
×
118

UNCOV
119
if (_.isNumber(argv.parallel)) {
×
120
   options.parallel = parseInt(argv.parallel, 10);
×
121
}
122

123
function setupRoleRelatedCredentials(argPrefix, msg, masterCreds) {
UNCOV
124
   var params = { RoleArn: argv[argPrefix + 'role-arn'] },
×
125
       creds = masterCreds;
×
126

UNCOV
127
   if (_.isEmpty(params.RoleArn)) {
×
128
      return creds;
×
129
   }
130

UNCOV
131
   if (_.isEmpty(argv[argPrefix + 'mfa-serial'])) {
×
132
      console.log('Assuming role %s %s', params.RoleArn, msg);
×
133
   } else {
UNCOV
134
      params.SerialNumber = argv[argPrefix + 'mfa-serial'];
×
135
      params.TokenCode = argv[argPrefix + 'mfa-token'];
×
136
      console.log('Assuming role %s with MFA %s (%s) %s', params.RoleArn, params.SerialNumber, params.TokenCode, msg);
×
137
   }
138

UNCOV
139
   creds = new AWS.TemporaryCredentials(params, masterCreds);
×
140

141
   // See jthomerson comments on https://github.com/aws/aws-sdk-js/issues/1064
142
   // And subsequently: https://github.com/aws/aws-sdk-js/issues/1664
UNCOV
143
   startupPromise = startupPromise.then(function() {
×
144
      return Q.ninvoke(creds, 'refresh');
×
145
   });
146

UNCOV
147
   return creds;
×
148
}
149

150
// Set up master table (SDK default) credentials
UNCOV
151
if (!_.isEmpty(argv.profile)) {
×
152
   console.log('Setting AWS credentials provider to use profile %s', argv.profile);
×
153
   AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: argv.profile });
×
154
}
155

UNCOV
156
AWS.config.credentials = setupRoleRelatedCredentials('', 'for master', AWS.config.credentials);
×
157

UNCOV
158
if (!_.isEmpty(argv['slave-profile'])) {
×
NEW
159
   if (argv['slave-profile'].indexOf('localhost') > -1) {
×
NEW
160
      console.log('Using localhost endpoint.');
×
NEW
161
      options.localhostTarget = argv['slave-profile'];
×
162
   } else {
NEW
UNCOV
163
      console.log('Setting AWS credentials provider to use profile %s for slaves', argv['slave-profile']);
×
NEW
164
      options.slaveCredentials = new AWS.SharedIniFileCredentials({ profile: argv['slave-profile'] });
×
165
   }
166
}
167

UNCOV
168
options.slaveCredentials = setupRoleRelatedCredentials('slave-', 'for slaves', options.slaveCredentials || AWS.config.credentials);
×
169

170
startupPromise
×
171
   .then(function() {
172
      return new Synchronizer(argv.master, argv.slaves, options).run();
×
173
   })
174
   .done();
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc