/
duostack
executable file
·929 lines (706 loc) · 32.6 KB
/
duostack
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
#!/usr/bin/env ruby
#############################################################################
# #
# Duostack Command Line Client #
# #
# Copyright © 2011 Duostack, Inc. <http://duostack.com/>. #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
#############################################################################
require 'cgi'
$dir = File.dirname(File.expand_path(__FILE__))
$client = File.basename(__FILE__)
module Duostack
class Client
VERSION = '0.2.0'
DEPENDENCIES_LAST_MODIFIED = 1297154481
USER_AGENT = "duostack-#{VERSION}"
DEFAULTS = {
:credentials_location => '~/.duostack',
:remote_name => 'duostack'
}
FLAGS = [ # app and remote get special handling
'confirm',
'long',
'skip-dependency-checks'
]
COMMANDS = {
:default => 'help', # command used when no other command is given
:general => %w(version help), # general commands, can always be run
:user => [ # commands requiring credentials (first-time setup)
'create',
'list',
'sync'
],
:app => [ # commands requiring an app to be specified (either by git inference or flag)
'logs',
'restart',
'ps',
'destroy',
'console',
'rake',
'config',
'env',
'access',
'domains'
],
:compound => [ # mult-part commands that expect subsequent arguments, must validate extra args on their own
'help',
'create',
'rake',
'config',
'env',
'access',
'domains'
]
}
def initialize(args=[], client='duostack')
@args = args
@client = client
end
def run
@creds_file = get_flag_arg('creds') || DEFAULTS[:credentials_location]
@remote = get_flag_arg('remote') || DEFAULTS[:remote_name]
# get app from args if we can, otherwise it will be extracted from git remotes during require_app
@app_name = get_flag_arg('app')
@flags = parse_flags
@command = @args.shift || COMMANDS[:default]
# we consider this run to be confirmed if the app name has been specified in the args and the --confirm flag is passed
@confirmed = @app_name && @flags.include?('confirm')
# make sure everything is in order
check_dependencies unless @flags.include?('skip-dependency-checks')
validate_args # checks for extraneous args and valid command
require_app if COMMANDS[:app].include?(@command) # checks that user is set and app can be ID'd
require_user if COMMANDS[:user].include?(@command) # checks user credentials
# everything checks out; time to rock and roll
send(@command)
end
# argument processing methods
#########################################################################
# extracts and validates any argument starting with '--', indicating a flag
def parse_flags
# extract flags
flags = @args.collect do |arg|
arg[2..-1] if arg[0..1] == '--'
end.compact
# remove flags from args
@args.delete_if { |arg| arg[0..1] == '--' }
return flags
end
# ensures that the command and all extracted flags are what we expect, warns if they aren't
def validate_args
invalid = []
invalid += [@command] - COMMANDS.values.flatten # validate command
invalid += @flags - FLAGS # validate flags
# unless command is compound (expecting further args), any remaining args must be invalid
invalid += @args unless COMMANDS[:compound].include?(@command)
if invalid.any?
exit_with("unrecognized argument: '#{invalid.first}', run '#{@client} help' for usage")
end
end
def get_next_args(qty=0, message="missing required argument(s), run '#{@client} help'")
next_args = @args.slice!(0, qty)
# make sure we got as many args as the caller wanted
exit_with message unless next_args.length == qty
# de-arrayify if only one
next_args = next_args.first if next_args.length == 1
return next_args
end
# used to read flags followed by an argument (e.g. --app)
# returns the arg following the flag of "name" or nil
def get_flag_arg(flag)
if flag_index = @args.index("--#{flag}")
# slice out flag args so we don't re-use them later, returning second element
# will be nil if no arg is passed after --flag; that's okay
@args.slice!(flag_index, 2)[1]
end
end
# validation methods
#########################################################################
def check_dependencies
filename = File.expand_path(@creds_file)
return if File.exist?(filename) && File.mtime(filename).to_i > DEPENDENCIES_LAST_MODIFIED
# ruby
if `which ruby`.empty? # how are we even here?
exit_with "missing dependency, please install Ruby 1.8.6 or later"
end
# ruby >= 1.8.6
if `ruby -v`.split[1].to_f < 1.8
exit_with "missing dependency, please install Ruby 1.8.6 or later"
end
# git (any)
if `which git`.empty?
exit_with "missing dependency, please install Git"
end
# curl
if `which curl`.empty?
exit_with "missing dependency, please install curl (http://curl.haxx.se/download.html)"
end
# curl SSL
# handled inside api_host method
# touch .duostack so we know when deps were last checked (but don't create it if it doesn't exist)
require 'fileutils'
FileUtils.touch(filename) if File.exist?(filename)
end
# ensures the app can be identified from inspecting the git repo or command line args
def require_app
require_user # all app commands require a user
@app_name ||= app_name_from_git_remotes
unless @app_name
exit_with "run this command from a Duostack app folder or pass an app name with the --app argument"
end
return @app_name
end
# ensures user credentials are cached
def require_user
@credentials ||= `cat #{@creds_file} 2>/dev/null`.chomp
if @credentials.empty?
ssh_key = require_ssh_key # all user commands require an SSH key
puts "First-time Duostack client setup"
print "Email: "
username = $stdin.gets.chomp
password = `bash -c 'read -sp "Password: " passwd; echo $passwd'`.chomp
puts '' # clears the line after
username = CGI::escape(username)
password = CGI::escape(password)
ssh_key = CGI::escape(ssh_key)
api_token = api_get('get_token', "api_username=#{username}&api_password=#{password}&ssh_key=#{ssh_key}", 5)
`echo 'api_username=#{username}&api_token=#{api_token}' > #{@creds_file}`
`chmod 600 #{@creds_file}`
@credentials = `cat #{@creds_file} 2>/dev/null`.chomp
if @credentials.empty? || @credentials.length < 32 # at least the length of the token
exit_with "error saving credentials file, please contact support@duostack.com"
end
puts "Completed initial setup... waiting for sync..."
sleep 4 # TODO: Do a sync check here in the future, 4 secs is safe for now
puts ""
end
return @credentials
end
def require_ssh_key
@ssh_key ||= `cat #{ssh_key_location}`.chomp
unless @ssh_key
exit_with "an SSH key is required to run this command, please generate an SSH key and try again (http://docs.duostack.com/command-line-client#setup)"
end
return @ssh_key
end
def require_confirmation
# NOTE: @confirmed is set above in 'run' so we can be assured the app_name came from the --app flag
# if assessed confirmation here, the app could have been extracted from the git repo
unless @confirmed
exit_with "command requires confirmation, run again with '--confirm --app #{@app_name}'"
end
end
# utility methods
#########################################################################
def process_crud_command(opts)
# get action
action = @args.shift || 'list' # list is the default
action = 'list' if action == 'ls' # normalize shorthand for list
action = 'remove' if action == 'rm' # normalize shorthand for remove
# extract important things from opts, otherwise merge defaults
resource = opts[:resource]
resources = "#{resource}s" # may eventually need a better pluralizer
# default settings for opts. priority is:
# 1. hash under each action (e.g. opts[:actions][:list][:param])
# 2. general opts (e.g. opts[:param])
# 3. generic defaults specified here (e.g. `resources`, the pluralized resource name)
defaults = {
:error_message => opts[:error_message] || "<#{resource}>",
:param => opts[:param] || resources,
:additional_params => opts[:additonal_params] || nil,
:args_processor => opts[:args_processor] || lambda { |args| args }
}
# actions can be either a hash (containing action-specific options) or an array (accept the defaults)
if opts[:actions].respond_to?(:keys)
valid_actions = opts[:actions].keys.map { |x| x.to_s }
opts = defaults.merge(opts[:actions][action.to_sym])
else
valid_actions = opts[:actions]
opts = defaults.merge(opts)
end
# ensure action is valid
unless valid_actions.include?(action)
exit_with "invalid argument for '#{@command}', try #{sentencize(valid_actions)}"
end
# ensure we have an argument for add/remove actions which require it
if %w(add remove).include?(action)
# gather up and compose remaining args for add/remove operations
argument = opts[:args_processor].call(@args).join(' ')
@args.clear # clean up, since we processed every remaining arg
# warn and exit unless we have an argument to pass
if argument.empty?
exit_with "'#{@command} #{action}' requires an argument, try '#{@command} #{action} #{opts[:error_message]}'"
end
# clean up argument
argument = CGI::escape(argument)
end
# finally, process action
case action
when 'list'
print api_get("list_#{resources}", opts[:additional_params])
when 'add'
puts api_get("add_#{resource}", ["#{opts[:param]}=#{argument}", opts[:additional_params]].compact.join('&'))
when 'remove'
puts api_get("remove_#{resource}", ["#{opts[:param]}=#{argument}", opts[:additional_params]].compact.join('&'))
when 'clear'
require_confirmation
puts api_get("clear_#{resources}", opts[:additional_params])
end
end
# attempts to get the app name out of git remotes
# if --remote is specified, it will use that assuming it's valid
# if not, it will look for any remote name that references duostack.net
def app_name_from_git_remotes
remotes = `git remote -v 2>/dev/null`.split("\n")
remotes.reject! { |line| line.split.last == '(fetch)' } # filter out fetch remotes (careful, does not exist in older git versions)
# find url of remote of specified name
valid_remotes = remotes.reject do |line|
line.split.first != @remote
end
remote_url = valid_remotes.first.split[1] unless valid_remotes.empty?
# correct url will be in the form "git@duostack.net:appname.git"
# if remote of specified name is a duostack remote, set app_name
if !remote_url.to_s.empty? && remote_url[0..16] == "git@duostack.net:" && remote_url[-4..-1] == ".git"
app_name = remote_url[17..-5]
else # the specified remote isn't for duostack; look for another (take first match)
remotes.each do |line|
result = line.scan(/git@duostack\.net:(\w+)\.git/)
if result.length > 0 && result[0].length > 0
app_name = result[0][0]
remote_name = line.split.first
warn_with "remote '#{@remote}' does not refer to Duostack, using remote '#{remote_name}' instead"
break
end
end
end
return app_name ||= nil
end
def ssh_key_location
if `file ~/.ssh/id_rsa.pub`[/text|key/]
'~/.ssh/id_rsa.pub'
elsif `file ~/.ssh/id_dsa.pub`[/text|key/]
'~/.ssh/id_dsa.pub'
elsif `file ~/.ssh/identity.pub`[/text|key/]
'~/.ssh/identity.pub'
else
nil
end
end
def api_host
@api_host ||= begin
host = "https://duostack.duostack.net"
if !`curl -V`[/SSL/]
warn_with "WARNING! curl SSL support is missing, using insecure plaintext mode"
host = "http://duostack.duostack.net"
end
if local = ENV['DSLOCAL']
debug "internal development mode"
local ||= "http://localhost:3000"
host = local
end
host
end
end
def api_get(endpoint, params=nil, timeout=20)
url = "#{api_host}/api/#{endpoint}?#{@credentials}"
url += "&app_name=#{@app_name}" if @app_name
url += "&#{params}" if params
curl_get(url, timeout)
end
def curl_get(url, timeout=nil)
command = "curl -s#{'v' if ENV['DSDEBUG']} -A '#{USER_AGENT}' -w '\n%{http_code}' '#{url}'" # use w flag to append http status code
command += " -m #{timeout}" if timeout
raw = `#{command}`
debug command
debug raw
# break apart the raw result and extract the HTTP status code, reassemble
parts = raw.split("\n")
status = parts.pop.to_i
result = parts.join("\n")
# if the code is 422, we should have a displayable error message, so display directly
if status == 422
exit_with result
end
case (status / 100) # just get the class of status, e.g. any 4xx code will become 4
when 2 # success, return result sans status code
return result
when 1, 3, 4, 5 # the server is doing something dumb (500 error, redirect, 404s)
exit_with "Duostack API error, please try again or contact support@duostack.com"
else
exit_with "could not connect to Duostack API"
end
end
def sentencize(array, conjunction='or')
# http://stackoverflow.com/questions/2038787/join-array-contents-into-an-english-list
case array.length
when 0, 1
array.first.to_s
when 2
"#{array.first} #{conjunction} #{array.last}"
else
"#{array[0..-2].join(', ')}, #{conjunction} #{array.last}"
end
end
def debug(message)
puts message if ENV['DSDEBUG']
end
def warn_with(message='error')
warn "#{@client}: #{message}"
end
def exit_with(message=nil, code=false)
warn_with message
exit code
end
# command methods
#########################################################################
def version
puts VERSION
end
def help
if content = Help.read_section(@args.shift)
puts content
else
exit_with "unrecognized help section, try '#{@client} help'"
end
end
def sync
# empty method, just makes sure credentials are set
end
def list
puts api_get('list_apps')
end
def create
# ensure new app name passed, clean up
name = get_next_args(1, "app name is required, try '#{@client} create <appname>'")
name = CGI::escape(name.downcase)
# ensure git repo
if `git status 2>&1`[/Not a git/]
exit_with "current directory is not a Git repository, run 'git init' first"
end
# make sure we're not going to step on an existing git remote
if `git remote`.chomp.split("\n").include?(@remote)
exit_with "there is already a Git remote named '#{@remote}', please remove it or pass a \ndifferent name with the --remote argument"
end
# create, add remote
puts api_get('create_app', "app_name=#{name}")
`git remote add #{@remote} git@duostack.net:#{name}.git 2>/dev/null`
puts "Git remote added, to push: 'git push #{@remote} master'"
end
def logs
puts api_get('get_logs')
end
def restart
puts api_get('restart')
end
def ps
puts api_get('get_instances')
end
def destroy
require_confirmation
# pull out remote name before we destroy
remote = `git remote show duostack 2>/dev/null`
# destroy!
puts api_get("delete_app")
# attempt to remove duostack git remote
# only if "duostack" remote actually references this app's remote
if !remote.empty? and remote.scan("git@duostack.net:#{@app_name}.git").length > 0
`git remote rm duostack 2>/dev/null`
end
end
def console
# TODO: just use ruby expect lib
# first check for expect dependency
if `which expect`.empty?
exit_with "missing dependency, please install Expect (http://expect.sourceforge.net/)"
end
exec("#{$dir}/.duostack-console-expect #{@app_name}")
end
def rake
# get command(s), if they exist (all remaining args), clean up
command = @args.join(' ')
command = CGI::escape(command)
puts api_get('run_rake', "command=#{command}", 60)
end
def config
name, value = @args.slice!(0,2)
name = CGI::escape(name) if name
value = CGI::escape(value) if value
if name # name provided, get/set config
if value # value provided, set config
puts api_get('option_set', "name=#{name}&val=#{value}")
else # no value provided, get config
puts api_get('option_get', "name=#{name}")
end
else # no name provided, get list
puts api_get('option_list')
end
end
def env
process_crud_command({
:resource => 'env',
:actions => {
:list => {
:additional_params => "truncate=#{!@flags.include?('long')}"
},
:add => {
:error_message => '<name>=<value>',
:param => 'input',
:args_processor => lambda { |args|
# recompose strings and quote values because ruby strips out quotation marks in the args.
args.collect do |arg|
if arg.include?('=')
result = arg.split('=',2)
%Q(#{result[0]}="#{result[1].gsub('"', '\"')}")
else
arg
end
end
}
},
:remove => {
:error_message => '<name>',
:param => 'name'
},
:clear => {}
}
})
end
def access
process_crud_command({
:resource => 'collab',
:param => 'emails',
:error_message => '<email>',
:actions => %w(list add)
})
end
def domains
process_crud_command({
:resource => 'domain',
:actions => %w(list add remove)
})
end
module Help
# available help sections. first will be used as the default, so unshift 'help' into first position.
SECTIONS = (COMMANDS[:general] + COMMANDS[:user] + COMMANDS[:app]).unshift('help')
class << self
def read_section(section)
# use default if not set
section ||= SECTIONS.first
# validate section exists
return false unless SECTIONS.include?(section)
self.send(section).gsub(/\n\s{12}/, "\n") # strips leading spaces so we can keep these indented
end
def help
<<-EOF
Usage: #{$client} <command> [<args>] [--app <appname>] [--remote <remotename>]
App commands must be either run from an app folder (a Git repository with a
Duostack remote) or have the app specified with the "--app <appname>" flag. If
both are present, the "--app" flag takes precedence.
You can also use the "--remote" flag to set the app based on a specific Git
remote name. This is common when you run two Duostack Apps (e.g. staging and
production) from the same folder. This flag can also be used when running
"create" to have the client set up a custom remote name (default is "duostack").
The most common commands are listed below. For additional information on any of
them, run: #{$client} help <command>
General Commands:
help [<command>] Show this help, or detailed help on <command>
create <appname> Initialize a Git repository as a Duostack App
list Show all apps associated with your account
version Show version of this Duostack client
App Commands:
logs Retrieve server logs
restart Restart instances
ps List instances with current status
destroy Destroy Duostack App and associated data
config [<name> [<setting>]] Show or set configuration options
env [<operation>] Manage environment variables
access [<operation>] Manage app collaborator access
domains [<operation>] Manage custom domains
App Commands - Ruby:
console Connect to IRB/Rails console
rake [<command>] Run a Rake command
EOF
end
def create
<<-EOF
Usage:
#{$client} create <appname>
#{$client} create <appname> --remote <remotename>
Example:
#{$client} create myappname
#{$client} create myappname --remote staging
Arguments:
<appname> A name for your app (restrictions apply, see below)
<remotename> An optional name for the created Git remote
Creates a new Duostack App from the current directory with the given name.
The current directory must be initialized as a Git repository (run 'git init').
Upon running 'create', the app will be created on Duostack and a Git remote with
the name 'duostack' will be added to the local repository, which you can push to
to deploy your app: git push duostack master. If a custom remote name is
specified with the '--remote' flag, that will be used instead.
The app name must be 4-16 characters long, alphanumeric, and must not start with
a number. The use of hyphens, underscores, or any other special characters is
not supported.
EOF
end
def list
<<-EOF
Usage: #{$client} list
Shows a list of the apps associated with your Duostack account.
EOF
end
def version
<<-EOF
Usage: #{$client} version
Displays the client's version number.
EOF
end
def logs
<<-EOF
Usage: #{$client} logs
Retreives aggregate logs from all of the app's instances.
EOF
end
def restart
<<-EOF
Usage: #{$client} restart
Restarts all of the app's instances. Useful for recovering from errors or
forcing a purge of the HTTP cache for your app
(see: http://docs.duostack.com/http-caching).
This will also cause the app to pick up any changes to its configuration options
or environment variables made with the 'config' or 'env' commands.
Apps on Duostack are automatically restarted after each Git push deploy.
EOF
end
def ps
<<-EOF
Usage: #{$client} ps
Retreives a listing of all of the app's instances with status information
(uptime) for each.
EOF
end
def destroy
<<-EOF
Usage: #{$client} destroy [--confirm]
Destroys the app and all associated data. Can not be undone; use with caution.
Requires confirmation.
EOF
end
def config
<<-EOF
Usage:
#{$client} config lists all configs and current settings
#{$client} config <name> shows valid settings for a config
#{$client} config <name> <setting> sets a setting for a config
Examples:
#{$client} config lists all configs and current settings
#{$client} config stack shows valid settigns for "stack"
#{$client} config stack ruby-mri-1.9.2 sets "stack" to "ruby-mri-1.9.2"
Lists, shows, and sets app config options.
List Configs: Shows a list of all available config option names with their
current settings.
Show Config: Shows a list of the valid settings for the config option <name>.
<name> must be one of the available options shown in the list of configs. The
currently selected value is denoted with an asterisk next to it.
Set Config: Allows setting of config options. Sets config <name> to <setting>.
<setting> must be one of the valid settings shown for this config.
EOF
end
def env
<<-EOF
Usage:
#{$client} env [--long] lists all env vars
#{$client} env add <name>=<value> adds env var <name> with <value>
#{$client} env remove <name> removes env var <name>
#{$client} env clear [--confirm] clears all env vars
Examples:
#{$client} env --long lists all env vars
#{$client} env add API_KEY=AbO5m5fbrt adds var API_KEY with value AbO5m5fbrt
#{$client} env remove API_KEY removes env var API_KEY
#{$client} env clear --confirm clears env vars
Lists, adds, removes, and clears app environment variables.
List: Lists environment variables currently set on the app. If none are set,
output will be blank. List output is abbreviated by default for readability. If
you need to see the full values of your environment variables, use the --long
flag with this command.
Add: Add one or more environment variables to the app. Add multiple by
supplying additional <name>=<value> pairs separated by spaces. You may need to
quote any complex values (with spaces or special characters) that may confuse
the client or your shell.
Remove: Removes one or more environment variables from the app. Remove multiple
by supplying additional variable <name> arguments separated by spaces.
Clear: Clears all environment variables from the app. Requires confirmation.
EOF
end
def access
<<-EOF
Usage:
#{$client} access lists app collaborators
#{$client} access add <email> grants access for <email>
Examples:
#{$client} access lists app collaborators
#{$client} access add name@example.com grants access for name@example.com
Lists and adds app collaborator access for users (identified by emails).
List: Lists collaborator emails who currently have access to the app. If none
are set, output will be blank.
Add: Add one or more collaborators (by email address) to the app. Add multiple
by supplying additional <email> arguments separated by spaces.
EOF
end
def domains
<<-EOF
Usage:
#{$client} domains lists all custom domains
#{$client} domains add <domain> adds <domain> as a custom domain
#{$client} domains remove <domain> removes custom domain <domain>
Examples:
#{$client} domains lists all env vars
#{$client} domains add app.example.com adds app.example.com to app
#{$client} domains remove app.example.com removes app.example.com from app
Lists, adds, and removes custom domains
(http://docs.duostack.com/custom-domains).
List: Lists custom domains currently set on the app. If none are set, output
will be blank.
Add: Add one or more custom domains to the app. Add multiple by supplying
additional <domain> arguments separated by spaces.
Remove: Removes one or more custom domains from the app. Remove multiple by
supplying additional <domain> arguments separated by spaces.
EOF
end
def console
<<-EOF
Usage: #{$client} console
Launches an interactive IRB/console session with your app. You can use this to
make any action you would normally make in your app's console.
Applicable only to Ruby applications.
EOF
end
def rake
<<-EOF
Usage: #{$client} rake [<command>]
Runs rake (with an optional <command> argument) on your app. After the task has
run, the output will be displayed. Tasks running longer than 60 seconds will not
have their full output displayed.
Passing of environment variables if your rake task requires them is supported
(e.g. rake db:seed MODEL=Posts).
Applicable only to Ruby applications.
EOF
end
end
end
end
end
Duostack::Client.new(ARGV.dup, $client).run