Skip to content

Commit

Permalink
Fix for command 'ps -x' (sudo) for app in a Private Space (#3051)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbosio authored Oct 23, 2024
1 parent 7fe2ee3 commit eeef085
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 16 deletions.
16 changes: 8 additions & 8 deletions packages/cli/src/commands/ps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ function printExtended(dynos: DynoExtended[]) {
ID: {get: (dyno: DynoExtended) => dyno.id},
Process: {get: (dyno: DynoExtended) => dyno.name},
State: {get: (dyno: DynoExtended) => `${dyno.state} ${ago(new Date(dyno.updated_at))}`},
Region: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.region : ''},
'Execution Plane': {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.execution_plane : ''},
Fleet: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.fleet : ''},
Instance: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.instance : ''},
IP: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.ip : ''},
Port: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.port.toString() : ''},
AZ: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.az : ''},
Region: {get: (dyno: DynoExtended) => dyno.extended?.region ? dyno.extended.region : ''},
'Execution Plane': {get: (dyno: DynoExtended) => dyno.extended?.execution_plane ? dyno.extended.execution_plane : ''},
Fleet: {get: (dyno: DynoExtended) => dyno.extended?.fleet ? dyno.extended.fleet : ''},
Instance: {get: (dyno: DynoExtended) => dyno.extended?.instance ? dyno.extended.instance : ''},
IP: {get: (dyno: DynoExtended) => dyno.extended?.ip ? dyno.extended.ip : ''},
Port: {get: (dyno: DynoExtended) => dyno.extended?.port ? dyno.extended.port.toString() : ''},
AZ: {get: (dyno: DynoExtended) => dyno.extended?.az ? dyno.extended.az : ''},
Release: {get: (dyno: DynoExtended) => dyno.release.version},
Command: {get: (dyno: DynoExtended) => truncate(dyno.command)},
Route: {get: (dyno: DynoExtended) => dyno.extended ? dyno.extended.route : ''},
Route: {get: (dyno: DynoExtended) => dyno.extended?.route ? dyno.extended.route : ''},
Size: {get: (dyno: DynoExtended) => dyno.size},
},
{
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/lib/types/dyno_extended.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ export interface DynoExtended extends Required<Dyno> {
* Extended information.
*/
extended?: {
az: string,
execution_plane: string,
fleet: string,
instance: string,
ip: string,
port: number,
region: string,
route: string,
az: string | null,
execution_plane: string | null,
fleet: string | null,
instance: string | null,
ip: string | null,
port: number | null,
region: string | null,
route: string | null,
}
}
64 changes: 64 additions & 0 deletions packages/cli/test/unit/commands/ps/index.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,70 @@ describe('ps', function () {
expect(stderr.output).to.equal('')
})

it('shows extended info for Private Space app', async function () {
const api = nock('https://api.heroku.com')
.get('/account')
.reply(200, {id: '1234'})
.get('/apps/myapp')
.reply(200, {name: 'myapp'})
.get('/apps/myapp/dynos?extended=true')
.reply(200, [{
id: '100',
command: 'npm start',
size: 'Eco',
name: 'web.1',
type: 'web',
updated_at: hourAgo,
state: 'up',
release: {id: '10', version: '40'},
extended: {
az: null,
execution_plane: null,
fleet: null,
instance: 'instance',
ip: '10.0.0.1',
port: null,
region: 'us',
route: null,
},
}, {
id: '101',
command: 'bash',
size: 'Eco',
name: 'run.1',
type: 'run',
updated_at: hourAgo,
state: 'up',
release: {id: '10', version: '40'},
extended: {
az: null,
execution_plane: null,
fleet: null,
instance: 'instance',
ip: '10.0.0.1',
port: null,
region: 'us',
route: null,
},
}])

await runCommand(Cmd, [
'--app',
'myapp',
'--extended',
])

api.done()

expect(heredoc(stdout.output)).to.equal(heredoc`
Id Process State Region Execution plane Fleet Instance Ip Port Az Release Command Route Size
─── ─────── ─────────────────────────────────────── ────── ─────────────── ───── ──────── ──────── ──── ── ─────── ───────── ───── ────
101 run.1 up ${hourAgoStr} (~ 1h ago) us instance 10.0.0.1 40 bash Eco
100 web.1 up ${hourAgoStr} (~ 1h ago) us instance 10.0.0.1 40 npm start Eco
`)
expect(stderr.output).to.equal('')
})

it('shows shield dynos in extended info if app is in a shielded private space', async function () {
const api = nock('https://api.heroku.com')
.get('/account')
Expand Down

0 comments on commit eeef085

Please sign in to comment.