Skip to content

Commit

Permalink
Merge pull request #107 from OldSneerJaw/ssh-key-argv
Browse files Browse the repository at this point in the history
Concatenate data integration registration arguments
  • Loading branch information
OldSneerJaw authored Jan 26, 2023
2 parents 9a3a80b + 8fdc355 commit 3baeba2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
43 changes: 41 additions & 2 deletions src/commands/borealis-pg/integrations/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 10 additions & 6 deletions src/commands/borealis-pg/integrations/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
Expand All @@ -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)
Expand Down

0 comments on commit 3baeba2

Please sign in to comment.