Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pg-v5): credentials adding capabilities for numbered essential plans #2513

Merged
merged 12 commits into from
Oct 24, 2023
4 changes: 4 additions & 0 deletions packages/pg-v5/commands/credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ async function run(context, heroku) {
let attachments = []
let credentials = []

if (util.essentialNumPlan(addon)) {
throw new Error('You can’t perform this operation on Essential-tier databases.')
}

function presentCredential(cred) {
let credAttachments = []
if (cred !== 'default') {
Expand Down
3 changes: 2 additions & 1 deletion packages/pg-v5/commands/credentials/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ async function run(context, heroku) {
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be good to change the messaging for numbered essentials around destroying the default credential. Right now it says default credential cant be destroyed, but perhaps it should be "You can’t perform this operation on Essential-tier databases."?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. do you mind adding that in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has any of this language been checked with CX?


let db = await fetcher.addon(app, args.database)

brittanyrjones marked this conversation as resolved.
Show resolved Hide resolved
if (util.essentialPlan(db)) {
brittanyrjones marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Essential-tier databases support only one default credential.')
throw new Error('You can’t perform this operation on Essential-tier databases.')
}

let attachments = await heroku.get(`/addons/${db.name}/addon-attachments`)
Expand Down
4 changes: 2 additions & 2 deletions packages/pg-v5/commands/credentials/rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ async function run(context, heroku) {
throw new Error('cannot pass both --all and --name')
}

if (util.essentialPlan(db) && cred !== 'default') {
throw new Error('Essential-tier databases support only one default credential.')
if ((util.essentialNumPlan(db)) || (util.legacyEssentialPlan(db) && cred !== 'default')) {
throw new Error('You can’t perform this operation on Essential-tier databases.')
}

if (all && flags.force) {
Expand Down
4 changes: 2 additions & 2 deletions packages/pg-v5/commands/credentials/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ async function run(context, heroku) {

let db = await fetcher.addon(app, args.database)
let cred = flags.name || 'default'
if (util.essentialPlan(db) && cred !== 'default') {
throw new Error('Essential-tier databases support only one default credential.')
if ((util.essentialNumPlan(db)) || (util.legacyEssentialPlan(db) && cred !== 'default')) {
throw new Error('You can’t perform this operation on Essential-tier databases.')
}

let credInfo = await heroku.get(`/postgres/v0/databases/${db.name}/credentials/${encodeURIComponent(cred)}`,
Expand Down
21 changes: 21 additions & 0 deletions packages/pg-v5/test/unit/commands/credentials.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ describe('pg:credentials', () => {
api.done()
})

it('throws an error when the db is numbered essential plan', () => {
const essentialAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:essential-0'},
}

const fetcher = () => {
return {
database: () => db,
addon: () => essentialAddon,
}
}

const cmd = proxyquire('../../../commands/credentials', {
'../lib/fetcher': fetcher,
})

const err = 'You can’t perform this operation on Essential-tier databases.'
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

it('shows the correct credentials', () => {
let credentials = [
{uuid: 'aaaa',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,28 @@ Please define the new grants for the credential within Postgres: heroku pg:psql
.then(() => expect(cli.stderr).to.equal('Creating credential credname... done\n'))
})

it('throws an error when the db is essential plan', () => {
it('throws an error when the db is numbered essential plan', () => {
const essentialAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:essential-0'},
}

const fetcher = () => {
return {
database: () => db,
addon: () => essentialAddon,
}
}

const cmd = proxyquire('../../../../commands/credentials/create', {
'../../lib/fetcher': fetcher,
})

const err = 'You can’t perform this operation on Essential-tier databases.'
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

it('throws an error when the db is starter plan', () => {
const hobbyAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:hobby-dev'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,28 @@ Database objects owned by credname will be assigned to the default credential.
'../../lib/fetcher': fetcher,
})

const err = 'Essential-tier databases support only one default credential.'
const err = 'You can’t perform this operation on Essential-tier databases.'
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

it('throws an error when the db is numbered essential plan', () => {
const essentialAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:essential-0'},
}

const fetcher = () => {
return {
database: () => db,
addon: () => essentialAddon,
}
}

const cmd = proxyquire('../../../../commands/credentials/destroy', {
'../../lib/fetcher': fetcher,
})

const err = 'You can’t perform this operation on Essential-tier databases.'
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,28 @@ describe('pg:credentials:rotate', () => {
'../../lib/fetcher': fetcher,
})

const err = 'Essential-tier databases support only one default credential.'
const err = 'You can’t perform this operation on Essential-tier databases.'
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

it('throws an error when the db is numbered essential plan', () => {
const essentialAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:essential-0'},
}

const fetcher = () => {
return {
database: () => db,
addon: () => essentialAddon,
}
}

const cmd = proxyquire('../../../../commands/credentials/rotate', {
'../../lib/fetcher': fetcher,
})

const err = 'You can’t perform this operation on Essential-tier databases.'
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

Expand Down
23 changes: 22 additions & 1 deletion packages/pg-v5/test/unit/commands/credentials/url.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,28 @@ Connection URL:
'../../lib/fetcher': fetcher,
})

const err = 'Essential-tier databases support only one default credential.'
const err = 'You can’t perform this operation on Essential-tier databases.'
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

it('throws an error when the db is numbered essential plan', () => {
const essentialAddon = {
name: 'postgres-1',
plan: {name: 'heroku-postgresql:essential-0'},
}

const fetcher = () => {
return {
database: () => db,
addon: () => essentialAddon,
}
}

const cmd = proxyquire('../../../../commands/credentials/url', {
'../../lib/fetcher': fetcher,
})

const err = 'You can’t perform this operation on Essential-tier databases.'
return expect(cmd.run({app: 'myapp', args: {}, flags: {name: 'jeff'}})).to.be.rejectedWith(Error, err)
})

Expand Down