startapp 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +7 -0
  2. data/COPYRIGHT +1 -0
  3. data/LICENSE +11 -0
  4. data/README.md +95 -0
  5. data/Rakefile +6 -0
  6. data/autocomplete/rhc_bash +1672 -0
  7. data/bin/app +37 -0
  8. data/conf/express.conf +8 -0
  9. data/features/assets/deploy.tar.gz +0 -0
  10. data/features/core_feature.rb +191 -0
  11. data/features/deployments_feature.rb +129 -0
  12. data/features/domains_feature.rb +58 -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 +185 -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 +726 -0
  27. data/lib/rhc/commands/apps.rb +20 -0
  28. data/lib/rhc/commands/authorization.rb +115 -0
  29. data/lib/rhc/commands/base.rb +174 -0
  30. data/lib/rhc/commands/cartridge.rb +329 -0
  31. data/lib/rhc/commands/clone.rb +66 -0
  32. data/lib/rhc/commands/configure.rb +20 -0
  33. data/lib/rhc/commands/create.rb +100 -0
  34. data/lib/rhc/commands/delete.rb +19 -0
  35. data/lib/rhc/commands/deploy.rb +32 -0
  36. data/lib/rhc/commands/deployment.rb +82 -0
  37. data/lib/rhc/commands/domain.rb +172 -0
  38. data/lib/rhc/commands/env.rb +142 -0
  39. data/lib/rhc/commands/force_stop.rb +17 -0
  40. data/lib/rhc/commands/git_clone.rb +34 -0
  41. data/lib/rhc/commands/logout.rb +51 -0
  42. data/lib/rhc/commands/logs.rb +21 -0
  43. data/lib/rhc/commands/member.rb +148 -0
  44. data/lib/rhc/commands/port_forward.rb +197 -0
  45. data/lib/rhc/commands/reload.rb +17 -0
  46. data/lib/rhc/commands/restart.rb +17 -0
  47. data/lib/rhc/commands/scp.rb +54 -0
  48. data/lib/rhc/commands/server.rb +40 -0
  49. data/lib/rhc/commands/setup.rb +60 -0
  50. data/lib/rhc/commands/show.rb +43 -0
  51. data/lib/rhc/commands/snapshot.rb +137 -0
  52. data/lib/rhc/commands/ssh.rb +51 -0
  53. data/lib/rhc/commands/sshkey.rb +97 -0
  54. data/lib/rhc/commands/start.rb +17 -0
  55. data/lib/rhc/commands/stop.rb +17 -0
  56. data/lib/rhc/commands/tail.rb +47 -0
  57. data/lib/rhc/commands/threaddump.rb +14 -0
  58. data/lib/rhc/commands/tidy.rb +17 -0
  59. data/lib/rhc/commands.rb +396 -0
  60. data/lib/rhc/config.rb +321 -0
  61. data/lib/rhc/context_helper.rb +121 -0
  62. data/lib/rhc/core_ext.rb +202 -0
  63. data/lib/rhc/coverage_helper.rb +33 -0
  64. data/lib/rhc/deployment_helpers.rb +111 -0
  65. data/lib/rhc/exceptions.rb +256 -0
  66. data/lib/rhc/git_helpers.rb +106 -0
  67. data/lib/rhc/help_formatter.rb +55 -0
  68. data/lib/rhc/helpers.rb +481 -0
  69. data/lib/rhc/highline_extensions.rb +479 -0
  70. data/lib/rhc/json.rb +51 -0
  71. data/lib/rhc/output_helpers.rb +260 -0
  72. data/lib/rhc/rest/activation.rb +11 -0
  73. data/lib/rhc/rest/alias.rb +42 -0
  74. data/lib/rhc/rest/api.rb +87 -0
  75. data/lib/rhc/rest/application.rb +348 -0
  76. data/lib/rhc/rest/attributes.rb +36 -0
  77. data/lib/rhc/rest/authorization.rb +8 -0
  78. data/lib/rhc/rest/base.rb +79 -0
  79. data/lib/rhc/rest/cartridge.rb +162 -0
  80. data/lib/rhc/rest/client.rb +650 -0
  81. data/lib/rhc/rest/deployment.rb +18 -0
  82. data/lib/rhc/rest/domain.rb +98 -0
  83. data/lib/rhc/rest/environment_variable.rb +15 -0
  84. data/lib/rhc/rest/gear_group.rb +16 -0
  85. data/lib/rhc/rest/httpclient.rb +145 -0
  86. data/lib/rhc/rest/key.rb +44 -0
  87. data/lib/rhc/rest/membership.rb +105 -0
  88. data/lib/rhc/rest/mock.rb +1042 -0
  89. data/lib/rhc/rest/user.rb +32 -0
  90. data/lib/rhc/rest.rb +148 -0
  91. data/lib/rhc/scp_helpers.rb +27 -0
  92. data/lib/rhc/ssh_helpers.rb +380 -0
  93. data/lib/rhc/tar_gz.rb +51 -0
  94. data/lib/rhc/usage_templates/command_help.erb +51 -0
  95. data/lib/rhc/usage_templates/command_syntax_help.erb +11 -0
  96. data/lib/rhc/usage_templates/help.erb +61 -0
  97. data/lib/rhc/usage_templates/missing_help.erb +1 -0
  98. data/lib/rhc/usage_templates/options_help.erb +12 -0
  99. data/lib/rhc/vendor/okjson.rb +600 -0
  100. data/lib/rhc/vendor/parseconfig.rb +178 -0
  101. data/lib/rhc/vendor/sshkey.rb +253 -0
  102. data/lib/rhc/vendor/zliby.rb +628 -0
  103. data/lib/rhc/version.rb +5 -0
  104. data/lib/rhc/wizard.rb +637 -0
  105. data/lib/rhc.rb +34 -0
  106. data/spec/coverage_helper.rb +82 -0
  107. data/spec/direct_execution_helper.rb +339 -0
  108. data/spec/keys/example.pem +23 -0
  109. data/spec/keys/example_private.pem +27 -0
  110. data/spec/keys/server.pem +19 -0
  111. data/spec/rest_spec_helper.rb +31 -0
  112. data/spec/rhc/assets/cert.crt +22 -0
  113. data/spec/rhc/assets/cert_key_rsa +27 -0
  114. data/spec/rhc/assets/empty.txt +0 -0
  115. data/spec/rhc/assets/env_vars.txt +7 -0
  116. data/spec/rhc/assets/env_vars_2.txt +1 -0
  117. data/spec/rhc/assets/foo.txt +1 -0
  118. data/spec/rhc/assets/targz_corrupted.tar.gz +1 -0
  119. data/spec/rhc/assets/targz_sample.tar.gz +0 -0
  120. data/spec/rhc/auth_spec.rb +442 -0
  121. data/spec/rhc/cli_spec.rb +186 -0
  122. data/spec/rhc/command_spec.rb +435 -0
  123. data/spec/rhc/commands/account_spec.rb +42 -0
  124. data/spec/rhc/commands/alias_spec.rb +333 -0
  125. data/spec/rhc/commands/app_spec.rb +777 -0
  126. data/spec/rhc/commands/apps_spec.rb +39 -0
  127. data/spec/rhc/commands/authorization_spec.rb +157 -0
  128. data/spec/rhc/commands/cartridge_spec.rb +665 -0
  129. data/spec/rhc/commands/clone_spec.rb +41 -0
  130. data/spec/rhc/commands/deployment_spec.rb +327 -0
  131. data/spec/rhc/commands/domain_spec.rb +401 -0
  132. data/spec/rhc/commands/env_spec.rb +493 -0
  133. data/spec/rhc/commands/git_clone_spec.rb +102 -0
  134. data/spec/rhc/commands/logout_spec.rb +86 -0
  135. data/spec/rhc/commands/member_spec.rb +247 -0
  136. data/spec/rhc/commands/port_forward_spec.rb +217 -0
  137. data/spec/rhc/commands/scp_spec.rb +77 -0
  138. data/spec/rhc/commands/server_spec.rb +69 -0
  139. data/spec/rhc/commands/setup_spec.rb +118 -0
  140. data/spec/rhc/commands/snapshot_spec.rb +179 -0
  141. data/spec/rhc/commands/ssh_spec.rb +163 -0
  142. data/spec/rhc/commands/sshkey_spec.rb +188 -0
  143. data/spec/rhc/commands/tail_spec.rb +81 -0
  144. data/spec/rhc/commands/threaddump_spec.rb +84 -0
  145. data/spec/rhc/config_spec.rb +407 -0
  146. data/spec/rhc/helpers_spec.rb +531 -0
  147. data/spec/rhc/highline_extensions_spec.rb +314 -0
  148. data/spec/rhc/json_spec.rb +30 -0
  149. data/spec/rhc/rest_application_spec.rb +258 -0
  150. data/spec/rhc/rest_client_spec.rb +752 -0
  151. data/spec/rhc/rest_spec.rb +740 -0
  152. data/spec/rhc/targz_spec.rb +55 -0
  153. data/spec/rhc/wizard_spec.rb +756 -0
  154. data/spec/spec_helper.rb +575 -0
  155. data/spec/wizard_spec_helper.rb +330 -0
  156. metadata +469 -0
@@ -0,0 +1,66 @@
1
+ require 'rhc/commands/git_clone'
2
+
3
+ module RHC::Commands
4
+ class Clone < GitClone
5
+ summary "Clone and configure an application's repository locally"
6
+ description "This is a convenience wrapper for 'git clone' with the added",
7
+ "benefit of adding configuration data such as the application's",
8
+ "UUID to the local repository. It also automatically",
9
+ "figures out the Git url from the application name so you don't",
10
+ "have to look it up."
11
+ syntax "<app> [--namespace NAME]"
12
+ takes_application :argument => true
13
+ option ["-r", "--repo dir"], "Path to the Git repository (defaults to ./$app_name)"
14
+ # alias_action 'app git-clone', :deprecated => true, :root_command => true
15
+ # TODO: Implement default values for arguments once ffranz has added context arguments
16
+ # argument :directory, "The name of a new directory to clone into", [], :default => nil
17
+ def run(app_name)
18
+
19
+ if url? app_name
20
+ if app = clonable_url?(app_name)
21
+ app_name = options.app = app[:name]
22
+ options.namespace = app[:domain]
23
+ else
24
+ warn "URL is invalid. To clone app your url must be something like this: http://appname-domain.startapp.bg/"
25
+ return 1
26
+ end
27
+ end
28
+
29
+ super app_name
30
+ end
31
+
32
+ private
33
+
34
+ def clonable_url?(app_name)
35
+ if startapp_url? app_name
36
+ app_name = clean_url(app_name)
37
+ app = extract_name_and_domain(app_name)
38
+
39
+ app
40
+ else
41
+ false
42
+ end
43
+ end
44
+
45
+ def url?(candidate)
46
+ !!(/http|\./.match(candidate))
47
+ end
48
+
49
+ def startapp_url?(candidate)
50
+ !!(/[a-zA-Z0-9]+-[a-zA-Z0-9]+\.startapp\./.match(candidate))
51
+ end
52
+
53
+ def clean_url(url)
54
+ url.dup.gsub!(/http(s?):\/\/|\//,'')
55
+ end
56
+
57
+ def extract_name_and_domain(url)
58
+ result = {}
59
+ name_and_domain = /([a-zA-Z0-9]+)-([a-zA-Z0-9]+)/.match(url)
60
+ result[:name], result[:domain] = name_and_domain[1], name_and_domain[2]
61
+
62
+ result
63
+ end
64
+
65
+ end
66
+ end
@@ -0,0 +1,20 @@
1
+ require 'rhc/commands/app'
2
+
3
+ module RHC::Commands
4
+ class Configure < App
5
+ summary "Configure several properties that apply to an application"
6
+ syntax "<app> [--[no-]auto-deploy] [--keep-deployments INTEGER] [--deployment-branch BRANCH] [--deployment-type TYPE] [--namespace NAME]"
7
+ takes_application :argument => true
8
+ option ["--[no-]auto-deploy"], "Build and deploy automatically when pushing to the git repo. Defaults to true."
9
+ option ["--keep-deployments INTEGER", Integer], "Number of deployments to preserve. Defaults to 1."
10
+ option ["--deployment-branch BRANCH"], "Which branch should trigger an automatic deployment, if automatic deployment is enabled with --auto-deploy. Defaults to master."
11
+ option ["--deployment-type git|binary"], "Type of deployment the application accepts ('git' or 'binary'). Defaults to git."
12
+
13
+ def run(app_name)
14
+ self.class.superclass.instance_method(:configure).bind(self).call app_name
15
+
16
+ 0
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,100 @@
1
+ require 'rhc/commands/app'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ module RHC::Commands
6
+ class Create < App
7
+
8
+ summary "Create an application"
9
+ description <<-DESC
10
+ Create an application. Every StartApp application must have one
11
+ web cartridge which serves web requests, and can have a number of
12
+ other cartridges which provide capabilities like databases,
13
+ scheduled jobs, or continuous integration.
14
+
15
+ You can see a list of all valid cartridge types by running
16
+ 'app cartridge list'. StartApp also supports downloading cartridges -
17
+ pass a URL in place of the cartridge name and we'll download
18
+ and install that cartridge into your app. Keep in mind that
19
+ these cartridges receive no security updates. Note that not
20
+ all StartAPp servers allow downloaded cartridges.
21
+
22
+ When your application is created, a URL combining the name of
23
+ your app and the name of your domain will be registered in DNS.
24
+ A copy of the code for your application will be checked out locally
25
+ into a folder with the same name as your application. Note that
26
+ different types of applications may require different folder
27
+ structures - check the README provided with the cartridge if
28
+ you have questions.
29
+
30
+ StartApp runs the components of your application on small virtual
31
+ servers called "gears". Each account or plan is limited to a number
32
+ of gears which you can use across multiple applications. Some
33
+ accounts or plans provide access to gears with more memory or more
34
+ CPU. Run 'app account' to see the number and sizes of gears available
35
+ to you. When creating an application the --gear-size parameter
36
+ may be specified to change the gears used.
37
+
38
+ DESC
39
+ syntax "<name> <cartridge> [... <cartridge>] [... VARIABLE=VALUE] [-n namespace]"
40
+ option ["-n", "--namespace NAME"], "Namespace for the application"
41
+ option ["-g", "--gear-size SIZE"], "Gear size controls how much memory and CPU your cartridges can use."
42
+ option ["-s", "--scaling"], "Enable scaling for the web cartridge."
43
+ option ["-r", "--repo DIR"], "Path to the Git repository (defaults to ./$app_name)"
44
+ option ["-e", "--env VARIABLE=VALUE"], "Environment variable(s) to be set on this app, or path to a file containing environment variables", :type => :list
45
+ option ["--from-code URL"], "URL to a Git repository that will become the initial contents of the application"
46
+ option ["--[no-]git"], "Skip creating the local Git repository."
47
+ option ["--[no-]dns"], "Skip waiting for the application DNS name to resolve. Must be used in combination with --no-git"
48
+ option ['--no-keys'], "Skip checking SSH keys during app creation", :hide => true
49
+ option ["--enable-jenkins [NAME]"], "Enable Jenkins builds for this application (will create a Jenkins application if not already available). The default name will be 'jenkins' if not specified."
50
+ argument :name, "Name for your application", ["-a", "--app NAME"], :optional => true
51
+ argument :cartridges, "The web framework this application should use", ["-t", "--type CARTRIDGE"], :optional => true, :type => :list
52
+
53
+ def run(name, cartridges)
54
+
55
+ quickstarts = get_quickstarts
56
+
57
+ if quickstarts.include? cartridges.first
58
+ bundle = quickstarts[cartridges.first]
59
+ cartridges = bundle["cartridges"]
60
+ options.from_code = bundle["code"]
61
+ end
62
+
63
+ cartridges = helping_words_cleaner(cartridges)
64
+ self.class.superclass.instance_method(:create).bind(self).call name, cartridges
65
+
66
+ 0
67
+ end
68
+
69
+ private
70
+
71
+ def get_quickstarts
72
+ @response ||= Net::HTTP.get(URI.parse('http://install.startapp.bg/q/quickstarts.json'))
73
+ JSON.parse @response
74
+ end
75
+
76
+ def list_quickstarts(quickstarts)
77
+ quicks = quickstarts.map{ |q| ([q[0], q[1]['name'] || '' ] ) if q[1]['view_on_cli'] == "true" }.compact!.sort{ |a,b| a[1].downcase <=> b[1].downcase }
78
+ quicks.unshift ['==========', '=========']
79
+ quicks.unshift ['Quickstart', 'Full name']
80
+ say table(quicks)
81
+ end
82
+
83
+ def helping_words_cleaner(words_list)
84
+ words = ['with', 'and']
85
+ words.each do |word|
86
+ words_list.delete word
87
+ end
88
+ words_list
89
+ end
90
+
91
+ def check_name!(name)
92
+ return unless name.blank?
93
+
94
+ paragraph{ say "You can choose some of ours quickstarts. Just write `app create myapp quickstart`" }
95
+ paragraph{ list_quickstarts(get_quickstarts) }
96
+
97
+ end
98
+
99
+ end
100
+ end
@@ -0,0 +1,19 @@
1
+ require 'rhc/commands/app'
2
+
3
+ module RHC::Commands
4
+ class Delete < App
5
+ summary "Delete an application from the server"
6
+ description "Deletes your application and all of its data from the server.",
7
+ "Use with caution as this operation is permanent."
8
+ syntax "<app> [--namespace NAME]"
9
+ takes_application :argument => true
10
+ option ["--confirm"], "Pass to confirm deleting the application"
11
+
12
+ def run(app)
13
+ self.class.superclass.instance_method(:delete).bind(self).call app
14
+
15
+ 0
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ require 'rhc/commands/app'
2
+
3
+ module RHC::Commands
4
+ class Deploy < App
5
+
6
+ summary "Deploy a git reference or binary file of an application"
7
+ syntax "<ref> --app NAME [--namespace NAME]"
8
+ description <<-DESC
9
+ By default OpenShift applications prepare, distribute, and activate deployments
10
+ on every git push. Alternatively, a user may choose to disable automatic
11
+ deployments and use 'rhc deploy' and 'rhc deployment' commands to fully control the
12
+ deployment lifecycle.
13
+
14
+ Use this command to prepare, distribute and deploy manually from a git reference
15
+ (commit id, tag or branch) or from a binary file. Check also 'rhc configure-app'
16
+ to configure your application to deploy manually and set the number of deployments
17
+ to keep in history.
18
+
19
+ DESC
20
+ takes_application
21
+ argument :ref, "Git tag, branch or commit id or path to binary file to be deployed", ["--ref REF"], :optional => false
22
+ option "--[no-]hot-deploy", "Perform hot deployment according to the specified argument rather than checking for the presence of the hot_deploy marker in the application git repo"
23
+ option "--[no-]force-clean-build", "Perform a clean build according to the specified argument rather than checking for the presence of the force_clean_build marker in the application git repo"
24
+
25
+ def run(ref)
26
+ self.class.superclass.instance_method(:delete).bind(self).call ref
27
+
28
+ 0
29
+ end
30
+
31
+ end
32
+ end
@@ -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 OpenShift applications prepare, distribute, and activate deployments
11
+ on every git push. Alternatively, a user may choose to disable automatic
12
+ deployments and use this 'rhc 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 'rhc 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 'rhc 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 'rhc 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 'rhc
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,172 @@
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 StartApp 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.startapp.bg
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 'app setup' or 'app 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.startapp.bg
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'], 'Do not allow any gear sizes in this domain.', :optional => true
41
+ option ['--allowed-gear-sizes [SIZES]'], 'A comma-delimited list of the gear sizes that will be allowed in this domain.', :optional => true
42
+ argument :namespace, "New domain name (letters and numbers, max 16 chars)", ["-n", "--namespace NAME"]
43
+ def create(namespace)
44
+ say "Creating domain '#{namespace}' ... "
45
+ rest_client.add_domain(namespace, :allowed_gear_sizes => check_allowed_gear_sizes)
46
+ success "done"
47
+
48
+ info "You may now create an application using the 'app create-app' command"
49
+
50
+ 0
51
+ end
52
+
53
+ summary "Rename a domain (will change application urls)"
54
+ syntax "<old name> <new name>"
55
+ argument :old_namespace, "Existing domain name", []
56
+ argument :new_namespace, "New domain name (letters and numbers, max 16 chars)", ["-n", "--namespace NAME"]
57
+ alias_action :update, :deprecated => true
58
+ def rename(old_namespace, new_namespace)
59
+ domain = rest_client.find_domain(old_namespace)
60
+
61
+ say "Renaming domain '#{domain.name}' to '#{new_namespace}' ... "
62
+ domain.rename(new_namespace)
63
+ success "done"
64
+
65
+ info "Applications in this domain will use the new name in their URL."
66
+
67
+ 0
68
+ end
69
+
70
+ summary "Change one or more configuration settings on the domain"
71
+ syntax "<namespace>"
72
+ option ['--no-allowed-gear-sizes'], 'Do not allow any gear sizes in this domain.', :optional => true
73
+ option ['--allowed-gear-sizes [SIZES]'], "A comma-delimited list of gear sizes allowed in this domain. To see available sizes, run 'app account'.", :optional => true
74
+ takes_domain :argument => true
75
+ def configure(_)
76
+ domain = find_domain
77
+ payload = {}
78
+ payload[:allowed_gear_sizes] = check_allowed_gear_sizes unless options.allowed_gear_sizes.nil? and options.no_allowed_gear_sizes.nil?
79
+
80
+ if payload.present?
81
+ say "Updating domain configuration ... "
82
+ domain.configure(payload)
83
+ success "done"
84
+ end
85
+
86
+ paragraph do
87
+ say format_table("Domain #{domain.name} configuration", get_properties(domain, :allowed_gear_sizes), :delete => true)
88
+ end
89
+
90
+ 0
91
+ end
92
+
93
+ summary "Display a domain and its applications"
94
+ takes_domain :argument => true
95
+ def show(_)
96
+ domain = find_domain
97
+
98
+ warn "In order to deploy applications, you must create a domain with 'app setup' or 'app create-domain'." and return 1 unless domain
99
+
100
+ applications = domain.applications(:include => :cartridges)
101
+ display_domain(domain, applications, true)
102
+
103
+ if applications.present?
104
+ success "You have #{pluralize(applications.length, 'application')} in your domain."
105
+ else
106
+ success "The domain #{domain.name} exists but has no applications. You can use 'app create-app' to create a new application."
107
+ end
108
+
109
+ 0
110
+ end
111
+
112
+ summary "Display all domains you have access to"
113
+ option ['--mine'], "Display only domains you own"
114
+ option ['--ids'], "Display the unique id of the domain (deprecated, domain IDs are now displayed by default)"
115
+ alias_action :domains, :root_command => true
116
+ def list
117
+ domains = rest_client.send(options.mine ? :owned_domains : :domains)
118
+
119
+ warn "In order to deploy applications, you must create a domain with 'app setup' or 'app create-domain'." and return 1 unless domains.present?
120
+ warn "The --ids option is deprecated. Domain IDs are displayed by default." if options.ids
121
+
122
+ domains.each do |d|
123
+ display_domain(d, nil, true)
124
+ end
125
+
126
+ success "You have access to #{pluralize(domains.length, 'domain')}."
127
+
128
+ 0
129
+ end
130
+
131
+ summary "Delete a domain"
132
+ syntax "<namespace>"
133
+ takes_domain :argument => true
134
+ option ["-f", "--force"], "Force the action"
135
+ def delete(_)
136
+ domain = find_domain
137
+
138
+ say "Deleting domain '#{domain.name}' ... "
139
+ domain.destroy(options.force.present?)
140
+ success "deleted"
141
+
142
+ 0
143
+ end
144
+
145
+ summary "Leave a domain (remove your membership)"
146
+ syntax "<namespace>"
147
+ argument :namespace, "Name of the domain", ["-n", "--namespace NAME"]
148
+ def leave(namespace)
149
+ domain = rest_client.find_domain(namespace)
150
+
151
+ say "Leaving domain ... "
152
+ domain.leave
153
+ success "done"
154
+
155
+ 0
156
+ end
157
+
158
+ protected
159
+ def check_allowed_gear_sizes
160
+ raise OptionParser::InvalidOption, "--allowed-gear-sizes and --no-allowed-gear-sizes cannot both be specified" unless options.allowed_gear_sizes.nil? or options.no_allowed_gear_sizes.nil?
161
+ sizes = options.no_allowed_gear_sizes.nil? ? options.allowed_gear_sizes : false
162
+ raise OptionParser::InvalidOption, "The server does not support --allowed-gear-sizes" unless sizes.nil? || rest_client.api.has_param?(:add_domain, 'allowed_gear_sizes')
163
+ if sizes.is_a? String
164
+ sizes.split(',').map(&:strip).map(&:presence)
165
+ elsif sizes == false
166
+ []
167
+ elsif sizes
168
+ raise OptionParser::InvalidOption, "Provide a comma delimited list of valid gear sizes to --allowed-gear-sizes"
169
+ end
170
+ end
171
+ end
172
+ 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
+ 'rhc 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 'rhc 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
+ rhc 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
+ rhc 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 'rhc 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,17 @@
1
+ require 'rhc/commands/app'
2
+
3
+ module RHC::Commands
4
+ class ForceStop < App
5
+
6
+ summary "Stops all application processes"
7
+ syntax "<app> [--namespace NAME]"
8
+ takes_application :argument => true
9
+
10
+ def run(app)
11
+ self.class.superclass.instance_method(:force_stop).bind(self).call app
12
+
13
+ 0
14
+ end
15
+
16
+ end
17
+ end