-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathindex.ts
53 lines (45 loc) · 1.76 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {Command, flags} from '@heroku-cli/command'
import {Args, ux} from '@oclif/core'
import * as Heroku from '@heroku-cli/schema'
import heredoc from 'tsheredoc'
export default class Index extends Command {
static topic = 'spaces'
static hiddenAliases = ['trusted-ips']
static description = heredoc(`
list trusted IP ranges for a space
Trusted IP ranges are only available on Private Spaces.
The space name is a required parameter. Newly created spaces will have 0.0.0.0/0 set by default
allowing all traffic to applications in the space. More than one CIDR block can be provided at
a time to the commands listed below. For example 1.2.3.4/20 and 5.6.7.8/20 can be added with:
`)
static flags = {
space: flags.string({char: 's', description: 'space to get inbound rules from'}),
json: flags.boolean({description: 'output in json format'}),
}
static args = {
space: Args.string({hidden: true}),
}
public async run(): Promise<void> {
const {flags, args} = await this.parse(Index)
const space = flags.space || args.space
if (!space) {
throw new Error('Space name required.\nUSAGE: heroku trusted-ips my-space')
}
const {body: rules} = await this.heroku.get<Required<Heroku.InboundRuleset>>(`/spaces/${space}/inbound-ruleset`)
if (flags.json) {
ux.log(JSON.stringify(rules, null, 2))
} else {
this.displayRules(space, rules)
}
}
private displayRules(space: string, ruleset: Required<Heroku.InboundRuleset>) {
if (ruleset.rules.length > 0) {
ux.styledHeader('Trusted IP Ranges')
for (const rule of ruleset.rules) {
ux.log(rule.source)
}
} else {
ux.styledHeader(`${space} has no trusted IP ranges. All inbound web requests to dynos are blocked.`)
}
}
}