Skip to content

Commit

Permalink
Updating dependencies and removing duplicated warnings in authorizati…
Browse files Browse the repository at this point in the history
…on commands
  • Loading branch information
sbosio committed Aug 19, 2024
1 parent 3a6fd6f commit 9433993
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 57 deletions.
5 changes: 2 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
"bugs": "https://github.com/heroku/cli/issues",
"dependencies": {
"@heroku-cli/color": "2.0.1",
"@heroku-cli/command": "^11.2.2",
"@heroku-cli/command": "^11.3.0",
"@heroku-cli/notifications": "^1.2.4",
"@heroku-cli/plugin-ps": "^8.1.7",
"@heroku-cli/plugin-ps-exec": "^2.4.0",
"@heroku-cli/schema": "^1.0.25",
"@heroku/buildpack-registry": "^1.0.1",
Expand Down Expand Up @@ -46,7 +45,7 @@
"execa": "5.1.1",
"filesize": "^10.1.2",
"foreman": "^3.0.1",
"fs-extra": "7.0.1",
"fs-extra": "^9.1",
"github-url-to-object": "^4.0.4",
"glob": "^10.3.10",
"got": "^11.8.6",
Expand Down
8 changes: 1 addition & 7 deletions packages/cli/src/commands/authorizations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class AuthorizationsCreate extends Command {

ux.action.start('Creating OAuth Authorization')

const {body: auth, headers} = await this.heroku.post<Heroku.OAuthAuthorization>('/oauth/authorizations', {
const {body: auth} = await this.heroku.post<Heroku.OAuthAuthorization>('/oauth/authorizations', {
body: {
description: flags.description,
scope: flags.scope ? flags.scope.split(',') : undefined,
Expand All @@ -35,12 +35,6 @@ export default class AuthorizationsCreate extends Command {

ux.action.stop()

const apiWarnings = headers['warning-message'] as string || ''

if (apiWarnings) {
ux.warn(apiWarnings)
}

if (flags.short) {
ux.log(auth.access_token && auth.access_token.token)
} else if (flags.json) {
Expand Down
8 changes: 1 addition & 7 deletions packages/cli/src/commands/authorizations/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ export default class AuthorizationsInfo extends Command {
async run() {
const {args, flags} = await this.parse(AuthorizationsInfo)

const {body: authentication, headers} = await this.heroku.get<Heroku.OAuthAuthorization>(
const {body: authentication} = await this.heroku.get<Heroku.OAuthAuthorization>(
`/oauth/authorizations/${args.id}`,
)

const apiWarnings = headers['warning-message'] as string || ''

if (apiWarnings) {
ux.warn(apiWarnings)
}

if (flags.json) {
ux.styledJSON(authentication)
} else {
Expand Down
10 changes: 1 addition & 9 deletions packages/cli/src/commands/authorizations/revoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,9 @@ export default class AuthorizationsRevoke extends Command {
const {args} = await this.parse(AuthorizationsRevoke)

ux.action.start('Revoking OAuth Authorization')

const {body: auth, headers} = await this.heroku.delete<Heroku.OAuthAuthorization>(
const {body: auth} = await this.heroku.delete<Heroku.OAuthAuthorization>(
`/oauth/authorizations/${encodeURIComponent(args.id)}`,
)

const apiWarnings = headers['warning-message'] as string || ''

if (apiWarnings) {
ux.warn(apiWarnings)
}

ux.action.stop(`done, revoked authorization from ${color.cyan(auth.description)}`)
}
}
10 changes: 1 addition & 9 deletions packages/cli/src/commands/authorizations/rotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ export default class AuthorizationsRotate extends Command {
const {args} = await this.parse(AuthorizationsRotate)

ux.action.start('Rotating OAuth Authorization')

const {body: authorization, headers} = await this.heroku.post<Heroku.OAuthAuthorization>(
const {body: authorization} = await this.heroku.post<Heroku.OAuthAuthorization>(
`/oauth/authorizations/${encodeURIComponent(args.id)}/actions/regenerate-tokens`,
)

const apiWarnings = headers['warning-message'] as string || ''

if (apiWarnings) {
ux.warn(apiWarnings)
}

ux.action.stop()

display(authorization)
Expand Down
8 changes: 1 addition & 7 deletions packages/cli/src/commands/authorizations/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class AuthorizationsUpdate extends Command {
}
}

const {body: authentication, headers} = await this.heroku.patch<Heroku.OAuthAuthorization>(
const {body: authentication} = await this.heroku.patch<Heroku.OAuthAuthorization>(
`/oauth/authorizations/${args.id}`,
{
body: {
Expand All @@ -40,12 +40,6 @@ export default class AuthorizationsUpdate extends Command {
},
)

const apiWarnings = headers['warning-message'] as string || ''

if (apiWarnings) {
ux.warn(apiWarnings)
}

ux.action.stop()

display(authentication)
Expand Down
15 changes: 0 additions & 15 deletions packages/cli/test/unit/commands/authorizations/create.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,4 @@ describe('authorizations:create', function () {
expect(json.scope).to.contain('global')
})
})

context('API warning headers', function () {
test
.stderr()
.stdout()
.nock('https://api.heroku.com:443', api => {
api
.post('/oauth/authorizations', {description: 'awesome'})
.reply(201, {scope: ['global'], access_token: {token: 'secrettoken'}}, {'warning-message': 'this is an API warning message example'})
})
.command(['authorizations:create', '--description', 'awesome'])
.it('outputs API warning message', ctx => {
expect(ctx.stderr).contains('this is an API warning message example')
})
})
})

0 comments on commit 9433993

Please sign in to comment.