@govuk-pay/cli 0.0.47 → 0.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -18,6 +18,7 @@ services:
|
|
|
18
18
|
retries: 5
|
|
19
19
|
volumes:
|
|
20
20
|
- {{../defaultServiceConfigsPath}}/postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
|
|
21
|
+
- {{name}}:/var/lib/postgresql/data
|
|
21
22
|
ports:
|
|
22
23
|
- "{{port}}:5432"
|
|
23
24
|
networks:
|
|
@@ -277,3 +278,8 @@ networks:
|
|
|
277
278
|
driver: default
|
|
278
279
|
config:
|
|
279
280
|
- subnet: 172.18.0.0/24
|
|
281
|
+
|
|
282
|
+
volumes:
|
|
283
|
+
{{#each dbServices}}
|
|
284
|
+
{{name}}:
|
|
285
|
+
{{/each}}
|
package/src/commands/tunnel.js
CHANGED
|
@@ -35,6 +35,10 @@ const builder = (yargs) => {
|
|
|
35
35
|
}).positional('application', {
|
|
36
36
|
describe: 'The application to connect to',
|
|
37
37
|
choices: constants_js_1.APPLICATIONS
|
|
38
|
+
}).option('database', {
|
|
39
|
+
type: 'string',
|
|
40
|
+
alias: 'd',
|
|
41
|
+
describe: 'The DBInstanceIdentifier of the database to connect to. Useful when there are multiple databases for an application.'
|
|
38
42
|
});
|
|
39
43
|
};
|
|
40
44
|
exports.builder = builder;
|
|
@@ -89,7 +93,7 @@ async function tunnelHandler(argv) {
|
|
|
89
93
|
try {
|
|
90
94
|
printWarningToUser();
|
|
91
95
|
const dbAccessType = await readInputForReadOrWriteDBAccess();
|
|
92
|
-
const database = await getDatabaseDetails(environment, application);
|
|
96
|
+
const database = await getDatabaseDetails(environment, application, argv.database);
|
|
93
97
|
bastionTask = await startBastion(environment, maximumDuration);
|
|
94
98
|
console.log(`${FORMAT.bel}${FORMAT.yellow}The bastion service will terminate in ${maximumDuration} minutes.${FORMAT.reset}`);
|
|
95
99
|
const warnTimeout = setTimeout(() => {
|
|
@@ -299,22 +303,24 @@ async function stopBastion(task, environment) {
|
|
|
299
303
|
}
|
|
300
304
|
console.log('Stopping Bastion');
|
|
301
305
|
}
|
|
302
|
-
async function getDatabaseDetails(environment, application) {
|
|
306
|
+
async function getDatabaseDetails(environment, application, dBInstanceIdentifier) {
|
|
303
307
|
const describeDbCommand = new client_rds_1.DescribeDBInstancesCommand({});
|
|
304
308
|
const describeDbCommandResponse = await rds.send(describeDbCommand);
|
|
305
309
|
if (describeDbCommandResponse.DBInstances == null || describeDbCommandResponse.DBInstances.length < 1) {
|
|
306
310
|
throw new Error(`Failed to find the database for ${application} in ${environment}`);
|
|
307
311
|
}
|
|
308
|
-
|
|
312
|
+
let appDatabases = describeDbCommandResponse.DBInstances
|
|
309
313
|
.filter(s => s.DBInstanceIdentifier?.startsWith(`${environment}-${application}`));
|
|
314
|
+
if (dBInstanceIdentifier !== null && dBInstanceIdentifier !== undefined) {
|
|
315
|
+
console.log(`Using provided database instance identifier: ${dBInstanceIdentifier}`);
|
|
316
|
+
appDatabases = appDatabases.filter(s => s.DBInstanceIdentifier === dBInstanceIdentifier);
|
|
317
|
+
}
|
|
310
318
|
if (appDatabases.length === 0) {
|
|
311
319
|
throw new Error(`Failed to find the database for ${application} in ${environment}`);
|
|
312
320
|
}
|
|
313
321
|
else if (appDatabases.length > 1) {
|
|
314
|
-
// TODO: Allow an argument to specify the exact database name. Print out how
|
|
315
|
-
// to re-run the describeDbCommand specifying the required database.
|
|
316
322
|
const databaseNames = appDatabases.map(d => d.DBInstanceIdentifier).join(':');
|
|
317
|
-
throw new Error(`There are multiple matching databases: ${databaseNames}
|
|
323
|
+
throw new Error(`There are multiple matching databases: ${databaseNames}. Re-run with the --database option to select the correct one.`);
|
|
318
324
|
}
|
|
319
325
|
else {
|
|
320
326
|
return appDatabases[0];
|