This repository was archived by the owner on Apr 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattach.ts
More file actions
80 lines (76 loc) · 3.07 KB
/
Copy pathattach.ts
File metadata and controls
80 lines (76 loc) · 3.07 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {flags} from '@oclif/command'
import cli from 'cli-ux'
import {APIClientService} from '../../share/api/api.service'
import {AbstractCommand} from '../../share/abstract.command'
export default class Attach extends AbstractCommand {
static description = 'Domain attach command'
static examples = [
'Simple usage',
'$ shifter attach --username USERNAME --password PASSWORD --site-id xxx-YOUR-SITE-ID-xxxx --domain test.example.com',
'\n Use own CDN (Netlify or own CloudFront etc...)',
'$ shifter attach --username USERNAME --password PASSWORD --site-id xxx-YOUR-SITE-ID-xxxx --domain test.example.com --no-shifter-cdn',
]
static flags = {
version: flags.version({char: 'v'}),
help: flags.help({char: 'h'}),
development: flags.boolean({
description: 'Work as development mode (Only for Shifter developer team)',
default: false,
}),
verbose: flags.boolean({
description: 'Show verbose',
default: false,
}),
username: flags.string({
char: 'U',
description: 'Shifter username',
}),
password: flags.string({
hidden: true,
char: 'P',
description: 'Shifter password',
}),
domain: flags.string({
char: 'D',
description: 'Target domain name (eg. www.example.com)',
}),
'site-id': flags.string({
char: 'S',
description: 'Shifter site id',
}),
'no-shifter-cdn': flags.boolean({
description: 'If you using another CDN like Netlify or own CloudFront etc... Please set the flag.',
default: false,
}),
}
async run() {
const {flags} = this.parse(Attach)
const siteId = flags['site-id'] || await cli.prompt('Site id')
const domain = flags.domain || await cli.prompt('Target domain')
const development = flags.development === true
const noShifterCDN = flags['no-shifter-cdn'] === true
if (development) this.log('Work as development mode')
try {
const clientWithAuth = await this.setupApiClient(flags.username, flags.password, flags.verbose, development)
const site = await clientWithAuth.get(`/latest/sites/${siteId}`)
if (!site || site.project_id !== siteId) throw new Error(`No such site ${siteId}`)
const domainObj = await clientWithAuth.get(`/latest/sites/${siteId}/domains/${domain}`)
if (!domainObj) throw new Error(`No such domain ${domain}`)
if (domainObj.status !== 'ISSUED') throw new Error('The domain has not been veritied. Please wait for a while and try again.')
await clientWithAuth.post(`/latest/sites/${siteId}/domains/${domain}/attach`, {
use_shifter_domain: !noShifterCDN,
})
this.log('Domain has been assigned')
} catch (error) {
if (APIClientService.isAxiosError(error) && error.response) {
const response = error.response
// eslint-disable-next-line no-console
if (development) console.log(response)
this.error(`${response.status} - ${response.statusText}\n${response.data.message}`)
}
// eslint-disable-next-line no-console
if (development) console.log(error)
this.error(error)
}
}
}