diff --git a/src/commands/borealis-pg/integrations/register.test.ts b/src/commands/borealis-pg/integrations/register.test.ts index 98720c0..35685e8 100644 --- a/src/commands/borealis-pg/integrations/register.test.ts +++ b/src/commands/borealis-pg/integrations/register.test.ts @@ -13,8 +13,11 @@ const fakeHerokuAuthToken = 'my-fake-heroku-auth-token' const fakeHerokuAuthId = 'my-fake-heroku-auth' const fakeIntegrationName = 'integration1' -const fakeSshPublicKey = - 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK5PkBlx+xU/skHZwhR/PPMCKAbQYhgiHlntFkhhC9Q0' +const fakeSshPublicKeyPieces = [ + 'ssh-ed25519', + 'AAAAC3NzaC1lZDI1NTE5AAAAIK5PkBlx+xU/skHZwhR/PPMCKAbQYhgiHlntFkhhC9Q0', +] +const fakeSshPublicKey = fakeSshPublicKeyPieces.join(' ') const fakeDbHost = 'my-fake-db-host' const fakeDbPort = 33_333 @@ -145,6 +148,42 @@ describe('data integration registration command', () => { `SSH Server Public Host Key: ${fakePublicSshHostKey}`) }) + defaultTestContext + .nock( + borealisPgApiBaseUrl, + {reqheaders: {authorization: `Bearer ${fakeHerokuAuthToken}`}}, + api => api + .post( + `/heroku/resources/${fakeAddonName}/data-integrations`, + { + integrationName: fakeIntegrationName, + sshPublicKey: fakeSshPublicKey, + enableWriteAccess: false, + }) + .reply(201, expectedResponseContent)) + .command([ + 'borealis-pg:integrations:register', + '--app', + fakeHerokuAppName, + '--name', + fakeIntegrationName, + ...fakeSshPublicKeyPieces, // Note that the SSH public key is split across two separate args + ]) + .it('registers a data integration with an unquoted SSH public key', ctx => { + expect(ctx.stderr).to.endWith( + `Registering data integration with add-on ${fakeAddonName}... done\n`) + expect(ctx.stdout).to.containIgnoreSpaces(`Database Host: ${fakeDbHost}`) + expect(ctx.stdout).to.containIgnoreSpaces(`Database Port: ${fakeDbPort}`) + expect(ctx.stdout).to.containIgnoreSpaces(`Database Name: ${fakeDbName}`) + expect(ctx.stdout).to.containIgnoreSpaces(`Database Username: ${fakeDbUsername}`) + expect(ctx.stdout).to.containIgnoreSpaces(`Database Password: ${fakeDbPassword}`) + expect(ctx.stdout).to.containIgnoreSpaces(`SSH Host: ${fakeSshHost}`) + expect(ctx.stdout).to.containIgnoreSpaces(`SSH Port: ${fakeSshPort}`) + expect(ctx.stdout).to.containIgnoreSpaces(`SSH Username: ${fakeSshUsername}`) + expect(ctx.stdout).to.containIgnoreSpaces( + `SSH Server Public Host Key: ${fakePublicSshHostKey}`) + }) + defaultTestContext .nock( borealisPgApiBaseUrl, diff --git a/src/commands/borealis-pg/integrations/register.ts b/src/commands/borealis-pg/integrations/register.ts index 249b91f..05a35d3 100644 --- a/src/commands/borealis-pg/integrations/register.ts +++ b/src/commands/borealis-pg/integrations/register.ts @@ -18,7 +18,6 @@ import {createHerokuAuth, fetchAddonAttachmentInfo, removeHerokuAuth} from '../. const keyColour = consoleColours.dataFieldName const valueColour = consoleColours.dataFieldValue -const sshPublicKeyCliArgName = 'SSH_PUBLIC_KEY' const dataIntegrationOptionName = 'name' export default class RegisterDataIntegrationsCommand extends Command { @@ -47,13 +46,15 @@ validate the identity of the SSH server if the data integration service supports it.` static examples = [ - `$ heroku borealis-pg:integrations:register --${appOptionName} sushi --${dataIntegrationOptionName} my_integration1 'ssh-ed25519 SSHPUBLICKEY1==='`, - `$ heroku borealis-pg:integrations:register --${writeAccessOptionName} --${appOptionName} sushi --${dataIntegrationOptionName} my_integration2 'ssh-rsa SSHPUBLICKEY2==='`, + `$ heroku borealis-pg:integrations:register --${appOptionName} sushi --${dataIntegrationOptionName} my_integration1 ssh-ed25519 SSHPUBLICKEY1===`, + `$ heroku borealis-pg:integrations:register --${writeAccessOptionName} --${appOptionName} sushi --${dataIntegrationOptionName} my_integration2 ssh-rsa SSHPUBLICKEY2===`, ] + static strict = false // Receive command argument(s) as an argv array + static args = [ { - name: sshPublicKeyCliArgName, + name: 'SSH_PUBLIC_KEY', description: 'an SSH public key to authorize for access', required: true, }, @@ -71,10 +72,13 @@ supports it.` } async run() { - const {args, flags} = await this.parse(RegisterDataIntegrationsCommand) - const sshPublicKey = args[sshPublicKeyCliArgName] + const {argv, flags} = await this.parse(RegisterDataIntegrationsCommand) + + const sshPublicKey = argv.join(' ') + const integrationName = flags[dataIntegrationOptionName] const enableWriteAccess = flags[writeAccessOptionName] + const authorization = await createHerokuAuth(this.heroku) const attachmentInfo = await fetchAddonAttachmentInfo(this.heroku, flags.addon, flags.app, this.error)