pbox 1.17.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/COPYRIGHT +1 -0
  3. data/LICENSE +11 -0
  4. data/README.md +40 -0
  5. data/Rakefile +6 -0
  6. data/autocomplete/pbox_bash +1639 -0
  7. data/bin/pbox +37 -0
  8. data/conf/protonbox.conf +8 -0
  9. data/features/assets/deploy.tar.gz +0 -0
  10. data/features/core_feature.rb +178 -0
  11. data/features/deployments_feature.rb +127 -0
  12. data/features/domains_feature.rb +49 -0
  13. data/features/keys_feature.rb +37 -0
  14. data/features/members_feature.rb +166 -0
  15. data/lib/rhc/auth/basic.rb +64 -0
  16. data/lib/rhc/auth/token.rb +102 -0
  17. data/lib/rhc/auth/token_store.rb +53 -0
  18. data/lib/rhc/auth.rb +5 -0
  19. data/lib/rhc/autocomplete.rb +66 -0
  20. data/lib/rhc/autocomplete_templates/bash.erb +39 -0
  21. data/lib/rhc/cartridge_helpers.rb +118 -0
  22. data/lib/rhc/cli.rb +40 -0
  23. data/lib/rhc/command_runner.rb +186 -0
  24. data/lib/rhc/commands/account.rb +25 -0
  25. data/lib/rhc/commands/alias.rb +124 -0
  26. data/lib/rhc/commands/app.rb +701 -0
  27. data/lib/rhc/commands/apps.rb +20 -0
  28. data/lib/rhc/commands/authorization.rb +96 -0
  29. data/lib/rhc/commands/base.rb +174 -0
  30. data/lib/rhc/commands/cartridge.rb +326 -0
  31. data/lib/rhc/commands/deployment.rb +82 -0
  32. data/lib/rhc/commands/domain.rb +167 -0
  33. data/lib/rhc/commands/env.rb +142 -0
  34. data/lib/rhc/commands/git_clone.rb +29 -0
  35. data/lib/rhc/commands/logout.rb +51 -0
  36. data/lib/rhc/commands/member.rb +148 -0
  37. data/lib/rhc/commands/port_forward.rb +197 -0
  38. data/lib/rhc/commands/server.rb +40 -0
  39. data/lib/rhc/commands/setup.rb +60 -0
  40. data/lib/rhc/commands/snapshot.rb +137 -0
  41. data/lib/rhc/commands/ssh.rb +51 -0
  42. data/lib/rhc/commands/sshkey.rb +97 -0
  43. data/lib/rhc/commands/tail.rb +47 -0
  44. data/lib/rhc/commands/threaddump.rb +14 -0
  45. data/lib/rhc/commands.rb +396 -0
  46. data/lib/rhc/config.rb +320 -0
  47. data/lib/rhc/context_helper.rb +121 -0
  48. data/lib/rhc/core_ext.rb +202 -0
  49. data/lib/rhc/coverage_helper.rb +33 -0
  50. data/lib/rhc/deployment_helpers.rb +88 -0
  51. data/lib/rhc/exceptions.rb +232 -0
  52. data/lib/rhc/git_helpers.rb +91 -0
  53. data/lib/rhc/help_formatter.rb +55 -0
  54. data/lib/rhc/helpers.rb +477 -0
  55. data/lib/rhc/highline_extensions.rb +479 -0
  56. data/lib/rhc/json.rb +51 -0
  57. data/lib/rhc/output_helpers.rb +260 -0
  58. data/lib/rhc/rest/activation.rb +11 -0
  59. data/lib/rhc/rest/alias.rb +42 -0
  60. data/lib/rhc/rest/api.rb +87 -0
  61. data/lib/rhc/rest/application.rb +332 -0
  62. data/lib/rhc/rest/attributes.rb +36 -0
  63. data/lib/rhc/rest/authorization.rb +8 -0
  64. data/lib/rhc/rest/base.rb +79 -0
  65. data/lib/rhc/rest/cartridge.rb +154 -0
  66. data/lib/rhc/rest/client.rb +650 -0
  67. data/lib/rhc/rest/deployment.rb +18 -0
  68. data/lib/rhc/rest/domain.rb +98 -0
  69. data/lib/rhc/rest/environment_variable.rb +15 -0
  70. data/lib/rhc/rest/gear_group.rb +16 -0
  71. data/lib/rhc/rest/httpclient.rb +145 -0
  72. data/lib/rhc/rest/key.rb +44 -0
  73. data/lib/rhc/rest/membership.rb +105 -0
  74. data/lib/rhc/rest/mock.rb +1024 -0
  75. data/lib/rhc/rest/user.rb +32 -0
  76. data/lib/rhc/rest.rb +148 -0
  77. data/lib/rhc/ssh_helpers.rb +378 -0
  78. data/lib/rhc/tar_gz.rb +51 -0
  79. data/lib/rhc/usage_templates/command_help.erb +51 -0
  80. data/lib/rhc/usage_templates/command_syntax_help.erb +11 -0
  81. data/lib/rhc/usage_templates/help.erb +35 -0
  82. data/lib/rhc/usage_templates/missing_help.erb +1 -0
  83. data/lib/rhc/usage_templates/options_help.erb +12 -0
  84. data/lib/rhc/vendor/okjson.rb +600 -0
  85. data/lib/rhc/vendor/parseconfig.rb +178 -0
  86. data/lib/rhc/vendor/sshkey.rb +253 -0
  87. data/lib/rhc/vendor/zliby.rb +628 -0
  88. data/lib/rhc/version.rb +5 -0
  89. data/lib/rhc/wizard.rb +633 -0
  90. data/lib/rhc.rb +34 -0
  91. data/spec/coverage_helper.rb +89 -0
  92. data/spec/direct_execution_helper.rb +338 -0
  93. data/spec/keys/example.pem +23 -0
  94. data/spec/keys/example_private.pem +27 -0
  95. data/spec/keys/server.pem +19 -0
  96. data/spec/rest_spec_helper.rb +31 -0
  97. data/spec/rhc/assets/cert.crt +22 -0
  98. data/spec/rhc/assets/cert_key_rsa +27 -0
  99. data/spec/rhc/assets/empty.txt +0 -0
  100. data/spec/rhc/assets/env_vars.txt +7 -0
  101. data/spec/rhc/assets/env_vars_2.txt +1 -0
  102. data/spec/rhc/assets/foo.txt +1 -0
  103. data/spec/rhc/assets/targz_corrupted.tar.gz +1 -0
  104. data/spec/rhc/assets/targz_sample.tar.gz +0 -0
  105. data/spec/rhc/auth_spec.rb +442 -0
  106. data/spec/rhc/cli_spec.rb +188 -0
  107. data/spec/rhc/command_spec.rb +435 -0
  108. data/spec/rhc/commands/account_spec.rb +42 -0
  109. data/spec/rhc/commands/alias_spec.rb +333 -0
  110. data/spec/rhc/commands/app_spec.rb +754 -0
  111. data/spec/rhc/commands/apps_spec.rb +39 -0
  112. data/spec/rhc/commands/authorization_spec.rb +145 -0
  113. data/spec/rhc/commands/cartridge_spec.rb +641 -0
  114. data/spec/rhc/commands/deployment_spec.rb +286 -0
  115. data/spec/rhc/commands/domain_spec.rb +383 -0
  116. data/spec/rhc/commands/env_spec.rb +493 -0
  117. data/spec/rhc/commands/git_clone_spec.rb +80 -0
  118. data/spec/rhc/commands/logout_spec.rb +86 -0
  119. data/spec/rhc/commands/member_spec.rb +228 -0
  120. data/spec/rhc/commands/port_forward_spec.rb +217 -0
  121. data/spec/rhc/commands/server_spec.rb +69 -0
  122. data/spec/rhc/commands/setup_spec.rb +118 -0
  123. data/spec/rhc/commands/snapshot_spec.rb +179 -0
  124. data/spec/rhc/commands/ssh_spec.rb +163 -0
  125. data/spec/rhc/commands/sshkey_spec.rb +188 -0
  126. data/spec/rhc/commands/tail_spec.rb +81 -0
  127. data/spec/rhc/commands/threaddump_spec.rb +84 -0
  128. data/spec/rhc/config_spec.rb +407 -0
  129. data/spec/rhc/helpers_spec.rb +524 -0
  130. data/spec/rhc/highline_extensions_spec.rb +314 -0
  131. data/spec/rhc/json_spec.rb +30 -0
  132. data/spec/rhc/rest_application_spec.rb +248 -0
  133. data/spec/rhc/rest_client_spec.rb +752 -0
  134. data/spec/rhc/rest_spec.rb +740 -0
  135. data/spec/rhc/targz_spec.rb +55 -0
  136. data/spec/rhc/wizard_spec.rb +756 -0
  137. data/spec/spec_helper.rb +575 -0
  138. data/spec/wizard_spec_helper.rb +330 -0
  139. metadata +435 -0
@@ -0,0 +1,82 @@
1
+ require 'rhc/commands/base'
2
+ require 'rhc/deployment_helpers'
3
+
4
+ module RHC::Commands
5
+ class Deployment < Base
6
+ include RHC::DeploymentHelpers
7
+
8
+ summary "Commands for deploying and managing deployments of an application"
9
+ description <<-DESC
10
+ By default ProtonBox applications prepare, distribute, and activate deployments
11
+ on every git push. Alternatively, a user may choose to disable automatic
12
+ deployments and use this 'pbox deployment' set of commands to fully control the
13
+ deployment lifecycle. Use these commands to deploy manually from a git reference
14
+ or from a binary file, list and display deployments and also activate existing
15
+ deployments. Check also 'pbox configure-app' to configure your application to
16
+ deploy manually.
17
+
18
+ DESC
19
+ syntax "<action>"
20
+ default_action :help
21
+
22
+ summary "List the existing deployments of an application"
23
+ description <<-DESC
24
+ List all existing deployments of a given application. Check the 'pbox configure-app'
25
+ command to configure how many deployments are preserved in history.
26
+
27
+ DESC
28
+ syntax "<application>"
29
+ takes_application :argument => true
30
+ alias_action :"deployments", :root_command => true
31
+ def list(app)
32
+ rest_app = find_app
33
+ deployment_activations = rest_app.deployment_activations
34
+
35
+ raise RHC::DeploymentNotFoundException, "No deployments found for application #{app}." if !deployment_activations.present?
36
+
37
+ pager
38
+
39
+ display_deployment_list(deployment_activations)
40
+ 0
41
+ end
42
+
43
+ summary "Show details of the given deployment"
44
+ syntax "<deployment_id> --app NAME [--namespace NAME]"
45
+ description <<-DESC
46
+ Display details of the given deployment id.
47
+
48
+ DESC
49
+ takes_application
50
+ argument :id, "The deployment ID to show", ["--id ID"], :optional => false
51
+ def show(id)
52
+ rest_app = find_app
53
+ item = rest_app.deployment_activations.reverse_each.detect{|item| item[:deployment].id == id}
54
+
55
+ raise RHC::DeploymentNotFoundException, "Deployment ID '#{id}' not found for application #{rest_app.name}." if !item.present?
56
+
57
+ display_deployment(item)
58
+ paragraph { say "Use 'pbox show-app #{rest_app.name} --configuration' to check your deployment configurations." }
59
+ 0
60
+ end
61
+
62
+ summary "Activate an existing deployment"
63
+ description <<-DESC
64
+ Switch between existing deployments. This command allows you to rollback from one
65
+ deployment to a previous one or activate subsequent deployments. Check the 'pbox
66
+ configure-app' command to configure how many deployments are preserved in history.
67
+
68
+ DESC
69
+ syntax "<deployment_id> --app NAME [--namespace NAME]"
70
+ takes_application
71
+ argument :id, "The deployment ID to activate on the application", ["--id ID"], :optional => false
72
+ def activate(id)
73
+ rest_app = find_app
74
+
75
+ raise RHC::DeploymentsNotSupportedException.new if !rest_app.supports? "DEPLOY"
76
+
77
+ activate_deployment(rest_app, id)
78
+ 0
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,167 @@
1
+ require 'rhc/commands/base'
2
+
3
+ module RHC::Commands
4
+ class Domain < Base
5
+ summary "Add or rename the container for your apps"
6
+ syntax "<action>"
7
+ description <<-DESC
8
+ All ProtonBox applications must belong to a domain. The name of the domain
9
+ will be used as part of the public URL for an application.
10
+
11
+ For example, when creating a domain with the name "test", any applications
12
+ created in that domain will have the public URL:
13
+
14
+ http://<appname>-test.protonbox.me
15
+
16
+ Each account may have access to one or more domains shared by others. Depending
17
+ on your plan or configuration, you may be able to create more than one domain.
18
+
19
+ To create your first domain, run 'pbox setup' or 'pbox create-domain'.
20
+ DESC
21
+ default_action :help
22
+
23
+ summary "Create a new container for applications."
24
+ syntax "<namespace>"
25
+ description <<-DESC
26
+ A domain is a container for your applications. Each account may have one
27
+ or more domains (depending on plan), and you may collaborate on applications
28
+ by adding members to your domain.
29
+
30
+ The name of the domain is called its "namespace", and becomes part of the
31
+ application public URLs. For example, when creating a domain with the name "test",
32
+ all applications in that domain will have the public URL:
33
+
34
+ http://<appname>-test.protonbox.me
35
+
36
+ The domain owner may limit the gear sizes available to applications by using the
37
+ '--allowed-gear-sizes' option. If '--no-allowed-gear-sizes' is set, no applications
38
+ can be created in the domain. Older servers may not support this option.
39
+ DESC
40
+ option ['--[no-]allowed-gear-sizes [SIZES]'], 'A comma-delimited list of the gear sizes that will be allowed in this domain.', :optional => true
41
+ argument :namespace, "New domain name (letters and numbers, max 16 chars)", ["-n", "--namespace NAME"]
42
+ def create(namespace)
43
+ say "Creating domain '#{namespace}' ... "
44
+ rest_client.add_domain(namespace, :allowed_gear_sizes => check_allowed_gear_sizes)
45
+ success "done"
46
+
47
+ info "You may now create an application using the 'pbox create-app' command"
48
+
49
+ 0
50
+ end
51
+
52
+ summary "Rename a domain (will change application urls)"
53
+ syntax "<old name> <new name>"
54
+ argument :old_namespace, "Existing domain name", []
55
+ argument :new_namespace, "New domain name (letters and numbers, max 16 chars)", ["-n", "--namespace NAME"]
56
+ alias_action :update, :deprecated => true
57
+ def rename(old_namespace, new_namespace)
58
+ domain = rest_client.find_domain(old_namespace)
59
+
60
+ say "Renaming domain '#{domain.name}' to '#{new_namespace}' ... "
61
+ domain.rename(new_namespace)
62
+ success "done"
63
+
64
+ info "Applications in this domain will use the new name in their URL."
65
+
66
+ 0
67
+ end
68
+
69
+ summary "Change one or more configuration settings on the domain"
70
+ syntax "<namespace>"
71
+ option ['--[no-]allowed-gear-sizes [SIZES]'], 'A comma-delimited list of the gear sizes that will be allowed in this domain.', :optional => true
72
+ takes_domain :argument => true
73
+ def configure(_)
74
+ domain = find_domain
75
+ payload = {}
76
+ payload[:allowed_gear_sizes] = check_allowed_gear_sizes unless options.allowed_gear_sizes.nil?
77
+
78
+ if payload.present?
79
+ say "Updating domain configuration ... "
80
+ domain.configure(payload)
81
+ success "done"
82
+ end
83
+
84
+ paragraph do
85
+ say format_table("Domain #{domain.name} configuration", get_properties(domain, :allowed_gear_sizes), :delete => true)
86
+ end
87
+
88
+ 0
89
+ end
90
+
91
+ summary "Display a domain and its applications"
92
+ takes_domain :argument => true
93
+ def show(_)
94
+ domain = find_domain
95
+
96
+ warn "In order to deploy applications, you must create a domain with 'pbox setup' or 'pbox create-domain'." and return 1 unless domain
97
+
98
+ applications = domain.applications(:include => :cartridges)
99
+ display_domain(domain, applications)
100
+
101
+ if applications.present?
102
+ success "You have #{pluralize(applications.length, 'application')} in your domain."
103
+ else
104
+ success "The domain #{domain.name} exists but has no applications. You can use 'pbox create-app' to create a new application."
105
+ end
106
+
107
+ 0
108
+ end
109
+
110
+ summary "Display all domains you have access to"
111
+ option ['--mine'], "Display only domains you own"
112
+ option ['--ids'], "Display the unique id of the domain (not supported by all servers)"
113
+ alias_action :domains, :root_command => true
114
+ def list
115
+ domains = rest_client.send(options.mine ? :owned_domains : :domains)
116
+
117
+ warn "In order to deploy applications, you must create a domain with 'pbox setup' or 'pbox create-domain'." and return 1 unless domains.present?
118
+
119
+ domains.each do |d|
120
+ display_domain(d, nil, options.ids)
121
+ end
122
+
123
+ success "You have access to #{pluralize(domains.length, 'domain')}."
124
+
125
+ 0
126
+ end
127
+
128
+ summary "Delete a domain"
129
+ syntax "<namespace>"
130
+ takes_domain :argument => true
131
+ def delete(_)
132
+ domain = find_domain
133
+
134
+ say "Deleting domain '#{domain.name}' ... "
135
+ domain.destroy
136
+ success "deleted"
137
+
138
+ 0
139
+ end
140
+
141
+ summary "Leave a domain (remove your membership)"
142
+ syntax "<namespace>"
143
+ argument :namespace, "Name of the domain", ["-n", "--namespace NAME"]
144
+ def leave(namespace)
145
+ domain = rest_client.find_domain(namespace)
146
+
147
+ say "Leaving domain ... "
148
+ domain.leave
149
+ success "done"
150
+
151
+ 0
152
+ end
153
+
154
+ protected
155
+ def check_allowed_gear_sizes
156
+ sizes = options.allowed_gear_sizes
157
+ raise OptionParser::InvalidOption, "The server does not support --allowed-gear-sizes" unless sizes.nil? || rest_client.api.has_param?(:add_domain, 'allowed_gear_sizes')
158
+ if sizes.is_a? String
159
+ sizes.split(',').map(&:strip).map(&:presence)
160
+ elsif sizes == false
161
+ []
162
+ elsif sizes
163
+ raise OptionParser::InvalidOption, "Provide a comma delimited list of valid gear sizes to --allowed-gear-sizes"
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,142 @@
1
+ require 'rhc/commands/base'
2
+
3
+ module RHC::Commands
4
+ class Env < Base
5
+ summary "Manages user-defined environment variables set on a given application"
6
+ syntax "<action>"
7
+ description <<-DESC
8
+ Manages the user-defined environment variables set on a given
9
+ application. To see a list of all environment variables use the command
10
+ 'pbox list-env <application>'. Note that some predefined
11
+ cartridge-level environment variables can also be overriden,
12
+ but most variables provided by gears are read-only.
13
+
14
+ Type 'pbox set-env --help' for more details.
15
+
16
+ DESC
17
+ default_action :help
18
+ alias_action :"app env", :root_command => true
19
+
20
+ summary "Set one or more environment variable(s) to your application"
21
+ description <<-DESC
22
+ Set one or more environment variable(s) to your application.
23
+ Operands of the form 'VARIABLE=VALUE' set the environment
24
+ variable VARIABLE to value VALUE. Example:
25
+
26
+ pbox set-env VARIABLE1=VALUE1 VARIABLE2=VALUE2 -a myapp
27
+
28
+ Environment variables can also be set from a file containing one
29
+ or more VARIABLE=VALUE pairs (one per line). Example:
30
+
31
+ pbox set-env /path/to/file -a myapp
32
+
33
+ VALUE may be empty, in that case 'VARIABLE='. Setting a
34
+ variable to an empty value is different from unsetting it.
35
+
36
+ Some default cartridge-level variables can be overriden, but
37
+ variables provided by gears are read-only.
38
+
39
+ DESC
40
+ syntax "<VARIABLE=VALUE> [... <VARIABLE=VALUE>] [--namespace NAME] [--app NAME]"
41
+ argument :env, "Environment variable name and value pair separated by an equal (=) sign, e.g. VARIABLE=VALUE", ["-e", "--env VARIABLE=VALUE"], :optional => false, :type => :list
42
+ takes_application
43
+ option ["--confirm"], "Pass to confirm setting the environment variable(s)"
44
+ alias_action :add
45
+ def set(env)
46
+ rest_app = find_app
47
+
48
+ with_file = env.index {|item| File.file? item}
49
+
50
+ env_vars = []
51
+ env.each {|item| env_vars.concat(collect_env_vars(item))}
52
+ raise RHC::EnvironmentVariableNotProvidedException.new(
53
+ (with_file ?
54
+ "Environment variable(s) not found in the provided file(s).\n" :
55
+ "Environment variable(s) not provided.\n") <<
56
+ "Please provide at least one environment variable using the syntax VARIABLE=VALUE. VARIABLE can only contain letters, digits and underscore ('_') and can't begin with a digit.") if env_vars.empty?
57
+
58
+ if with_file
59
+ env_vars.each {|item| default_display_env_var(item.name, item.value)}
60
+ confirm_action "Do you want to set these environment variables on '#{rest_app.name}?"
61
+ end
62
+
63
+ say 'Setting environment variable(s) ... '
64
+ rest_app.set_environment_variables(env_vars)
65
+ success 'done'
66
+
67
+ 0
68
+ end
69
+
70
+ summary "Remove one or more environment variable(s) currently set to your application"
71
+ description <<-DESC
72
+ Remove one or more environment variable(s) currently set to your
73
+ application. Setting a variable to an empty value is
74
+ different from unsetting it. When unsetting a default cartridge-
75
+ level variable previously overriden, the variable will be set
76
+ back to its default value.
77
+
78
+ DESC
79
+ syntax "<VARIABLE> [... <VARIABLE>] [--namespace NAME] [--app NAME]"
80
+ argument :env, "Name of the environment variable(s), e.g. VARIABLE", ["-e", "--env VARIABLE"], :optional => false, :type => :list
81
+ takes_application
82
+ option ["--confirm"], "Pass to confirm removing the environment variable"
83
+ alias_action :remove
84
+ def unset(env)
85
+ rest_app = find_app
86
+
87
+ warn 'Removing environment variables is a destructive operation that may result in loss of data.'
88
+
89
+ env.each do |e|
90
+ default_display_env_var(e)
91
+ end
92
+
93
+ confirm_action "Are you sure you wish to remove the environment variable(s) above from application '#{rest_app.name}'?"
94
+ say 'Removing environment variable(s) ... '
95
+ rest_app.unset_environment_variables(env)
96
+ success 'removed'
97
+
98
+ 0
99
+ end
100
+
101
+ summary "List all environment variables set on the application"
102
+ description <<-DESC
103
+ List all user-defined environment variables set on the application.
104
+ Gear-level variables overriden by the 'pbox set-env' command
105
+ will also be listed.
106
+
107
+ DESC
108
+ syntax "<app> [--namespace NAME]"
109
+ takes_application :argument => true
110
+ option ["--table"], "Format the output list as a table"
111
+ option ["--quotes"], "Format the output list with double quotes for env var values"
112
+ def list(app)
113
+ rest_app = find_app
114
+ rest_env_vars = rest_app.environment_variables
115
+
116
+ pager
117
+
118
+ display_env_var_list(rest_env_vars, { :table => options.table, :quotes => options.quotes })
119
+
120
+ 0
121
+ end
122
+
123
+ summary "Show the value of one or more environment variable(s) currently set to your application"
124
+ syntax "<VARIABLE> [... <VARIABLE>] [--namespace NAME] [--app NAME]"
125
+ argument :env, "Name of the environment variable(s), e.g. VARIABLE", ["-e", "--env VARIABLE"], :optional => false, :type => :list
126
+ takes_application
127
+ option ["--table"], "Format the output list as a table"
128
+ option ["--quotes"], "Format the output list with double quotes for env var values"
129
+ def show(env)
130
+ rest_app = find_app
131
+ rest_env_vars = rest_app.find_environment_variables(env)
132
+
133
+ pager
134
+
135
+ display_env_var_list(rest_env_vars, { :table => options.table, :quotes => options.quotes })
136
+
137
+ 0
138
+ end
139
+
140
+ end
141
+
142
+ end
@@ -0,0 +1,29 @@
1
+ require 'rhc/commands/base'
2
+ require 'rhc/git_helpers'
3
+
4
+ module RHC::Commands
5
+ class GitClone < Base
6
+ summary "Clone and configure an application's repository locally"
7
+ description "This is a convenience wrapper for 'git clone' with the added",
8
+ "benefit of adding configuration data such as the application's",
9
+ "UUID to the local repository. It also automatically",
10
+ "figures out the Git url from the application name so you don't",
11
+ "have to look it up."
12
+ syntax "<app> [--namespace NAME]"
13
+ takes_application :argument => true
14
+ option ["-r", "--repo dir"], "Path to the Git repository (defaults to ./$app_name)"
15
+ alias_action 'app git-clone', :deprecated => true, :root_command => true
16
+ # TODO: Implement default values for arguments once ffranz has added context arguments
17
+ # argument :directory, "The name of a new directory to clone into", [], :default => nil
18
+ def run(app_name)
19
+ rest_app = find_app
20
+ dir = git_clone_application(rest_app)
21
+ success "Your application Git repository has been cloned to '#{system_path(dir)}'"
22
+
23
+ 0
24
+ end
25
+
26
+ private
27
+ include RHC::GitHelpers
28
+ end
29
+ end
@@ -0,0 +1,51 @@
1
+ module RHC::Commands
2
+ class Logout < Base
3
+ suppress_wizard
4
+
5
+ summary "End the current session"
6
+ description <<-DESC
7
+ Logout ends your current session on the server and then removes
8
+ all of the local session files. If you are using multiple
9
+ servers and configurations this will remove all of your local
10
+ session files.
11
+
12
+ The --all option will terminate all authorizations on your
13
+ account. Any previously generated authorizations will be
14
+ deleted and external tools that integrate with your account
15
+ will no longer be able to log in.
16
+ DESC
17
+ option '--all', "Remove all authorizations on your account."
18
+ alias_action 'account logout', :root_command => true
19
+ def run
20
+ if options.all
21
+ rest_client.user # force authentication
22
+ say "Deleting all authorizations associated with your account ... "
23
+ begin
24
+ rest_client.delete_authorizations
25
+ success "done"
26
+ rescue RHC::Rest::AuthorizationsNotSupported
27
+ info "not supported"
28
+ end
29
+ elsif token_for_user
30
+ options.noprompt = true
31
+ say "Ending session on server ... "
32
+ begin
33
+ rest_client.delete_authorization(token_for_user)
34
+ success "deleted"
35
+ rescue RHC::Rest::AuthorizationsNotSupported
36
+ info "not supported"
37
+ rescue RHC::Rest::TokenExpiredOrInvalid
38
+ info "already closed"
39
+ rescue => e
40
+ debug_error(e)
41
+ warn e.message
42
+ end
43
+ end
44
+
45
+ 0
46
+ ensure
47
+ token_store.clear
48
+ success "All local sessions removed."
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,148 @@
1
+ require 'rhc/commands/base'
2
+
3
+ module RHC::Commands
4
+ class Member < Base
5
+ summary "Manage membership on domains"
6
+ syntax "<action>"
7
+ description <<-DESC
8
+ Teams of developers can collaborate on applications by adding people to
9
+ domains as members: each member has a role (admin, editor, or viewer),
10
+ and those roles determine what the user can do with the domain and the
11
+ applications contained within.
12
+
13
+ Roles:
14
+
15
+ view - able to see information about the domain and its apps, but not make any changes
16
+ edit - create, update, and delete applications, and has Git and SSH access
17
+ admin - can update membership of a domain
18
+
19
+ The default role granted to members when added is 'edit' - use the '--role'
20
+ argument to use another. When adding and removing members, you can use their
21
+ 'login' value (typically their email or a short unique name for them) or their
22
+ 'id'. Both login and ID are visible via the 'pbox account' command.
23
+
24
+ To see existing members of a domain or application, use:
25
+
26
+ pbox members -n <domain_name> [-a <app_name>]
27
+
28
+ To change the role for a user, simply call the add-member command with the new role. You
29
+ cannot change the role of the owner.
30
+ DESC
31
+ syntax "<action>"
32
+ default_action :help
33
+
34
+ summary "List members of a domain or application"
35
+ syntax "<domain_or_app_name> [-n DOMAIN_NAME] [-a APP_NAME]"
36
+ description <<-DESC
37
+ Show the existing members of a domain or application - you can pass the name
38
+ of your domain with '-n', the name of your application with '-a', or combine
39
+ them in the first argument to the command like:
40
+
41
+ pbox members <domain_name>/[<app_name>]
42
+
43
+ The owner is always listed first. To see the unique ID of members, pass
44
+ '--ids'.
45
+ DESC
46
+ option ['--ids'], "Display the IDs of each member", :optional => true
47
+ takes_application_or_domain :argument => true
48
+ alias_action :members, :root_command => true
49
+ def list(path)
50
+ target = find_app_or_domain(path)
51
+ members = target.members.sort_by{ |m| [m.owner? ? 0 : 1, m.role_weight, m.name] }
52
+ show_name = members.any?{ |m| m.name && m.name != m.login }
53
+ members.map! do |m|
54
+ [
55
+ ((m.name || "") if show_name),
56
+ m.login || "",
57
+ m.owner? ? "#{m.role} (owner)" : m.role,
58
+ (m.id if options.ids)
59
+ ].compact
60
+ end
61
+ say table(members, :header => [('Name' if show_name), 'Login', 'Role', ("ID" if options.ids)].compact)
62
+
63
+ 0
64
+ end
65
+
66
+ summary "Add or update a member on a domain"
67
+ syntax "<login> [<login>...] [-n DOMAIN_NAME] [--role view|edit|admin] [--ids]"
68
+ description <<-DESC
69
+ Adds or updates members on a domain by passing one or more login
70
+ or ids for other people on ProtonBox. The login and ID values for each
71
+ account are displayed in 'pbox account'. To change the role for a user, simply
72
+ call the add-member command with the new role. You cannot change the role of
73
+ the owner.
74
+
75
+ Roles
76
+ view - able to see information about the domain and its apps,
77
+ but not make any changes
78
+ edit - create, update, and delete applications, and has Git
79
+ and SSH access
80
+ admin - can update membership of a domain
81
+
82
+ The default role granted to members when added is 'edit' - use the '--role'
83
+ argument for 'view' or 'admin'.
84
+
85
+ Examples
86
+ pbox add-member sally joe -n mydomain
87
+ Gives the accounts with logins 'sally' and 'joe' edit access on mydomain
88
+
89
+ pbox add-member bob@example.com --role admin -n mydomain
90
+ Gives the account with login 'bob@example.com' admin access on mydomain
91
+
92
+ DESC
93
+ takes_domain
94
+ option ['--ids'], "Treat the arguments as a list of IDs", :optional => true
95
+ option ['-r', '--role ROLE'], "The role to give to each member - view, edit, or admin (default 'edit')", :type => Role, :optional => true
96
+ argument :members, "A list of members logins to add. Pass --ids to treat this as a list of IDs.", [], :type => :list
97
+ def add(members)
98
+ target = find_domain
99
+ role = options.role || 'edit'
100
+ raise ArgumentError, 'You must pass one or more logins or ids to this command' unless members.present?
101
+ say "Adding #{pluralize(members.length, role_name(role))} to #{target.class.model_name.downcase} ... "
102
+ target.update_members(changes_for(members, role))
103
+ success "done"
104
+
105
+ 0
106
+ end
107
+
108
+ summary "Remove a member from a domain"
109
+ syntax "<login> [<login>...] [-n DOMAIN_NAME] [--ids]"
110
+ description <<-DESC
111
+ Remove members on a domain by passing one or more login or ids for each
112
+ member you wish to remove. View the list of existing members with
113
+ 'pbox members <domain_name>'.
114
+
115
+ Pass '--all' to remove all but the owner from the domain.
116
+ DESC
117
+ takes_domain
118
+ option ['--ids'], "Treat the arguments as a list of IDs"
119
+ option ['--all'], "Remove all members from this domain."
120
+ argument :members, "Member logins to remove from the domain. Pass --ids to treat this as a list of IDs.", [], :type => :list
121
+ def remove(members)
122
+ target = find_domain
123
+
124
+ if options.all
125
+ say "Removing all members from #{target.class.model_name.downcase} ... "
126
+ target.delete_members
127
+ success "done"
128
+
129
+ else
130
+ raise ArgumentError, 'You must pass one or more logins or ids to this command' unless members.present?
131
+ say "Removing #{pluralize(members.length, 'member')} from #{target.class.model_name.downcase} ... "
132
+ target.update_members(changes_for(members, 'none'))
133
+ success "done"
134
+ end
135
+
136
+ 0
137
+ end
138
+
139
+ protected
140
+ def changes_for(members, role)
141
+ members.map do |m|
142
+ h = {:role => role}
143
+ h[options.ids ? :id : :login] = m
144
+ h
145
+ end
146
+ end
147
+ end
148
+ end