Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import {Command, flags} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import waitForDomain from '../../lib/wait-for-domain'
export default class DomainsWait extends Command {
static description = 'wait for domain to be active for an app'
static flags = {
help: flags.help({char: 'h'}),
app: flags.app({required: true}),
remote: flags.remote()
}
static args = [{name: 'hostname', required: true}]
async run() {
const {args, flags} = this.parse(DomainsWait)
let domains
if (args.hostname) {
let {body: domain} = await this.heroku.get(`/apps/${flags.app}/domains/${args.hostname}`)
domains = [domain]
} else {
let {body: apiDomains} = await this.heroku.get>(`/apps/${flags.app}/domains`)
domains = apiDomains.filter(domain => domain.status === 'pending')
import waitForDomain from '../../lib/wait-for-domain'
interface DomainCreatePayload {
hostname: string
sni_endpoint?: string
}
const MULTIPLE_SNI_ENDPOINT_FLAG = 'allow-multiple-sni-endpoints'
export default class DomainsAdd extends Command {
static description = 'add a domain to an app'
static examples = ['heroku domains:add www.example.com']
static flags = {
help: flags.help({char: 'h'}),
app: flags.app({required: true}),
cert: flags.string({description: 'the name of the SSL cert you want to use for this domain', char: 'c'}),
json: flags.boolean({description: 'output in json format', char: 'j'}),
remote: flags.remote(),
wait: flags.boolean()
}
static args = [{name: 'hostname', required: true}]
createDomain = async (appName: string, payload: DomainCreatePayload): Promise => {
cli.action.start(`Adding ${color.green(payload.hostname)} to ${color.app(appName)}`)
try {
const response = await this.heroku.post(`/apps/${appName}/domains`, {
headers: {Accept: 'application/vnd.heroku+json; version=3.allow_multiple_sni_endpoints'},
body: payload
})
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import * as formatRelative from 'date-fns/formatRelative'
export default class AuthToken extends Command {
static description = `outputs current CLI authentication token.
By default, the CLI auth token is only valid for 1 year. To generate a long-lived token, use heroku authorizations:create`
static flags = {
help: flags.help({char: 'h'}),
}
async run() {
this.parse(AuthToken)
if (!this.heroku.auth) this.error('not logged in')
try {
const {body: tokens} = await this.heroku.get('/oauth/authorizations', {retryAuth: false})
const token = tokens.find((t: any) => t.access_token && t.access_token.token === this.heroku.auth)
if (token && token.access_token.expires_in) {
const d = new Date()
d.setSeconds(d.getSeconds() + token.access_token.expires_in)
this.warn(`token will expire ${formatRelative(d, new Date())}\nUse ${color.cmd('heroku authorizations:create')} to generate a long-term token`)
}
} catch (err) {
this.warn(err)
}
import {color} from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import cli from 'cli-ux'
export default class DomainsClear extends Command {
static description = 'remove all domains from an app'
static examples = ['heroku domains:clear']
static flags = {
help: flags.help({char: 'h'}),
app: flags.app({required: true}),
remote: flags.remote()
}
async run() {
const {flags} = this.parse(DomainsClear)
cli.action.start(`Removing all domains from ${color.app(flags.app)}`)
let {body: domains} = await this.heroku.get>(`/apps/${flags.app}/domains`)
domains = domains.filter((d: Heroku.Domain) => d.kind === 'custom')
for (const domain of domains) {
await this.heroku.delete(`/apps/${flags.app}/domains/${domain.hostname}`)
}
cli.action.stop()
}
}
import {color} from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import cli from 'cli-ux'
export default class DomainsRemove extends Command {
static description = 'remove a domain from an app'
static examples = ['heroku domains:remove www.example.com']
static flags = {
help: flags.help({char: 'h'}),
app: flags.app({required: true}),
remote: flags.remote(),
}
static args = [{name: 'hostname', required: true}]
async run() {
const {args, flags} = this.parse(DomainsRemove)
cli.action.start(`Removing ${color.green(args.hostname)} from ${color.app(flags.app)}`)
await this.heroku.delete(`/apps/${flags.app}/domains/${args.hostname}`)
cli.action.stop()
}
}
import {Command, flags} from '@heroku-cli/command'
import * as Heroku from '@heroku-cli/schema'
import cli from 'cli-ux'
export default class DomainsInfo extends Command {
static description = 'show detailed information for a domain on an app'
static examples = [
'$ heroku domains:info www.example.com',
]
static flags = {
help: flags.help({char: 'h'}),
app: flags.app({required: true}),
remote: flags.remote()
}
static args = [{name: 'hostname', required: true}]
async run() {
const {args, flags} = this.parse(DomainsInfo)
const {body: res} = await this.heroku.get(`/apps/${flags.app}/domains/${args.hostname}`)
let domain = {
...res,
app: res.app && res.app.name
}
cli.styledObject(domain)
}
}
export default class DomainsIndex extends Command {
static description = 'list domains for an app'
static examples = [
`$ heroku domains
=== example Heroku Domain
example.herokuapp.com
=== example Custom Domains
Domain Name DNS Record Type DNS Target
www.example.com CNAME www.example.herokudns.com
`, "$ heroku domains --filter 'Domain Name=www.example.com'"]
static flags = {
help: flags.help({char: 'h'}),
app: flags.app({required: true}),
remote: flags.remote(),
json: flags.boolean({description: 'output in json format', char: 'j'}),
...cli.table.flags({except: 'no-truncate'})
}
async run() {
const {flags} = this.parse(DomainsIndex)
const {body: domains} = await this.heroku.get>(`/apps/${flags.app}/domains`)
const herokuDomain = domains.find(domain => domain.kind === 'heroku')
const customDomains = domains.filter(domain => domain.kind === 'custom')
if (flags.json) {
cli.styledJSON(domains)
} else {
cli.styledHeader(`${flags.app} Heroku Domain`)