From cd7014b293cf1d561ef7c16d79d67b73fa7f4c1c Mon Sep 17 00:00:00 2001 From: Dan Goodman Date: Thu, 14 Oct 2021 10:46:39 -0400 Subject: [PATCH] Add random droplet id, region and size flag options --- lib/commands/instance/init.ts | 10 +++++++--- npm-shrinkwrap.json | 13 +++++++++---- package.json | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/commands/instance/init.ts b/lib/commands/instance/init.ts index e3348cf0..8587768d 100644 --- a/lib/commands/instance/init.ts +++ b/lib/commands/instance/init.ts @@ -26,11 +26,14 @@ import * as fs from 'fs' import * as fetch from 'isomorphic-fetch' import * as cf from '../../utils/common-flags'; import { flags } from '@oclif/command'; +import { nanoid } from 'nanoid/non-secure'; interface FlagsDef { help: void; v13: boolean; apiKey?: string; + region?: string; + size?: string; } export default class InstanceInitCmd extends Command { @@ -133,14 +136,15 @@ export default class InstanceInitCmd extends Command { responseBody = await res.json() const sshKeyID = responseBody.ssh_keys[0].id + const randomDropletID = nanoid() console.log('Creating droplet...') res = await fetch('https://api.digitalocean.com/v2/droplets', { method: 'POST', body: JSON.stringify({ - name: 'test-doprnifouieru', - region: 'nyc1', - size: 's-2vcpu-4gb', + name: randomDropletID, + region: options.region || 'nyc1', + size: options.size || 's-2vcpu-4gb', image: imageID, ssh_keys: [sshKeyID], user_data: JSON.stringify(configFile), diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index e5de0bb6..58564780 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -12151,6 +12151,12 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true }, + "nanoid": { + "version": "3.1.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.20.tgz", + "integrity": "sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==", + "dev": true + }, "p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -12434,10 +12440,9 @@ "integrity": "sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==" }, "nanoid": { - "version": "3.1.20", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.20.tgz", - "integrity": "sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==", - "dev": true + "version": "3.1.30", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.30.tgz", + "integrity": "sha512-zJpuPDwOv8D2zq2WRoMe1HsfZthVewpel9CAvTfc/2mBD1uUT/agc5f7GHGWXlYkFvi1mVxe4IjvP2HNrop7nQ==" }, "nanomatch": { "version": "1.2.13", diff --git a/package.json b/package.json index e6089bf8..36c76882 100644 --- a/package.json +++ b/package.json @@ -253,6 +253,7 @@ "minimatch": "^3.0.4", "moment": "^2.27.0", "moment-duration-format": "^2.3.2", + "nanoid": "^3.1.30", "ndjson": "^2.0.0", "net-keepalive": "^3.0.0", "node-cleanup": "^2.1.2",