-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommand-claim.coffee
54 lines (40 loc) · 1.6 KB
/
command-claim.coffee
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
BaseCommand = require './base-command'
_ = require 'lodash'
open = require 'open'
path = require 'path'
commander = require 'commander'
DEFAULT_HOST = 'app.octoblu.com'
DEFAULT_PORT = 443
class ClaimDevice extends BaseCommand
parseOptions: =>
commander
.usage '[options] <path/to/meshblu.json>'
.option '-s, --server <host[:port]>', 'Octoblu host'
.option '-g, --gateblu', 'Claim Gateblu (Mac OS X only)'
.parse process.argv
@filename = _.first commander.args
@filename ?= "meshblu.json" unless commander.gateblu?
@filename ?= path.resolve "#{process.env.HOME}/Library/Application Support/GatebluService/meshblu.json" if commander.gateblu?
@parseConfig()
parseConfig: =>
super
_.extend @config, @parseOctobluServer()
parseOctobluServer: =>
unless commander.server?
return {octobluServer: DEFAULT_HOST, octobluPort: DEFAULT_PORT}
serverConfig = commander.server.split(':')
{octobluServer: serverConfig[0], octobluPort: serverConfig[1]}
run: =>
@parseOptions()
meshbluHttp = @getMeshbluHttp()
{uuid, octobluServer, octobluPort} = @config
meshbluHttp.generateAndStoreToken uuid, (error, body) =>
return @die error if error?
newToken = body.token
path = "/node-wizard/claim/#{uuid}/#{newToken}"
if _.includes ["443", 443], octobluPort
return open "https://#{octobluServer}#{path}"
if _.includes ["80", 80], octobluPort
return open "http://#{octobluServer}#{path}"
open "http://#{octobluServer}:#{octobluPort}#{path}"
(new ClaimDevice()).run()