acquia_toolbelt 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/.gitignore +7 -0
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +7 -0
  4. data/CONTRIBUTING.md +11 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +55 -0
  7. data/Guardfile +5 -0
  8. data/LICENSE +19 -0
  9. data/README.md +149 -0
  10. data/Rakefile +1 -0
  11. data/acquia_toolbelt.gemspec +34 -0
  12. data/bin/acquia +9 -0
  13. data/lib/acquia_toolbelt/cli/api.rb +164 -0
  14. data/lib/acquia_toolbelt/cli/auth.rb +31 -0
  15. data/lib/acquia_toolbelt/cli/database.rb +237 -0
  16. data/lib/acquia_toolbelt/cli/deploy.rb +36 -0
  17. data/lib/acquia_toolbelt/cli/domain.rb +177 -0
  18. data/lib/acquia_toolbelt/cli/environment.rb +71 -0
  19. data/lib/acquia_toolbelt/cli/file.rb +31 -0
  20. data/lib/acquia_toolbelt/cli/server.rb +67 -0
  21. data/lib/acquia_toolbelt/cli/site.rb +28 -0
  22. data/lib/acquia_toolbelt/cli/ssh.rb +78 -0
  23. data/lib/acquia_toolbelt/cli/svn.rb +73 -0
  24. data/lib/acquia_toolbelt/cli/task.rb +74 -0
  25. data/lib/acquia_toolbelt/cli/ui.rb +44 -0
  26. data/lib/acquia_toolbelt/cli.rb +103 -0
  27. data/lib/acquia_toolbelt/error.rb +4 -0
  28. data/lib/acquia_toolbelt/thor.rb +95 -0
  29. data/lib/acquia_toolbelt/version.rb +3 -0
  30. data/lib/acquia_toolbelt.rb +4 -0
  31. data/lib/vendor/thor/CHANGELOG.md +139 -0
  32. data/lib/vendor/thor/Gemfile +20 -0
  33. data/lib/vendor/thor/LICENSE.md +20 -0
  34. data/lib/vendor/thor/README.md +35 -0
  35. data/lib/vendor/thor/lib/thor/actions/create_file.rb +105 -0
  36. data/lib/vendor/thor/lib/thor/actions/create_link.rb +60 -0
  37. data/lib/vendor/thor/lib/thor/actions/directory.rb +119 -0
  38. data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +137 -0
  39. data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +317 -0
  40. data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +109 -0
  41. data/lib/vendor/thor/lib/thor/actions.rb +318 -0
  42. data/lib/vendor/thor/lib/thor/base.rb +654 -0
  43. data/lib/vendor/thor/lib/thor/command.rb +136 -0
  44. data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
  45. data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
  46. data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +100 -0
  47. data/lib/vendor/thor/lib/thor/error.rb +32 -0
  48. data/lib/vendor/thor/lib/thor/group.rb +282 -0
  49. data/lib/vendor/thor/lib/thor/invocation.rb +172 -0
  50. data/lib/vendor/thor/lib/thor/parser/argument.rb +74 -0
  51. data/lib/vendor/thor/lib/thor/parser/arguments.rb +171 -0
  52. data/lib/vendor/thor/lib/thor/parser/option.rb +121 -0
  53. data/lib/vendor/thor/lib/thor/parser/options.rb +218 -0
  54. data/lib/vendor/thor/lib/thor/parser.rb +4 -0
  55. data/lib/vendor/thor/lib/thor/rake_compat.rb +72 -0
  56. data/lib/vendor/thor/lib/thor/runner.rb +322 -0
  57. data/lib/vendor/thor/lib/thor/shell/basic.rb +422 -0
  58. data/lib/vendor/thor/lib/thor/shell/color.rb +148 -0
  59. data/lib/vendor/thor/lib/thor/shell/html.rb +127 -0
  60. data/lib/vendor/thor/lib/thor/shell.rb +88 -0
  61. data/lib/vendor/thor/lib/thor/util.rb +270 -0
  62. data/lib/vendor/thor/lib/thor/version.rb +3 -0
  63. data/lib/vendor/thor/lib/thor.rb +474 -0
  64. data/lib/vendor/thor/spec/actions/create_file_spec.rb +170 -0
  65. data/lib/vendor/thor/spec/actions/create_link_spec.rb +95 -0
  66. data/lib/vendor/thor/spec/actions/directory_spec.rb +169 -0
  67. data/lib/vendor/thor/spec/actions/empty_directory_spec.rb +129 -0
  68. data/lib/vendor/thor/spec/actions/file_manipulation_spec.rb +382 -0
  69. data/lib/vendor/thor/spec/actions/inject_into_file_spec.rb +135 -0
  70. data/lib/vendor/thor/spec/actions_spec.rb +331 -0
  71. data/lib/vendor/thor/spec/base_spec.rb +291 -0
  72. data/lib/vendor/thor/spec/command_spec.rb +80 -0
  73. data/lib/vendor/thor/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
  74. data/lib/vendor/thor/spec/core_ext/ordered_hash_spec.rb +115 -0
  75. data/lib/vendor/thor/spec/exit_condition_spec.rb +19 -0
  76. data/lib/vendor/thor/spec/fixtures/application.rb +2 -0
  77. data/lib/vendor/thor/spec/fixtures/app{1}/README +3 -0
  78. data/lib/vendor/thor/spec/fixtures/bundle/execute.rb +6 -0
  79. data/lib/vendor/thor/spec/fixtures/bundle/main.thor +1 -0
  80. data/lib/vendor/thor/spec/fixtures/command.thor +10 -0
  81. data/lib/vendor/thor/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  82. data/lib/vendor/thor/spec/fixtures/doc/COMMENTER +11 -0
  83. data/lib/vendor/thor/spec/fixtures/doc/README +3 -0
  84. data/lib/vendor/thor/spec/fixtures/doc/block_helper.rb +3 -0
  85. data/lib/vendor/thor/spec/fixtures/doc/components/.empty_directory +0 -0
  86. data/lib/vendor/thor/spec/fixtures/doc/config.rb +1 -0
  87. data/lib/vendor/thor/spec/fixtures/doc/config.yaml.tt +1 -0
  88. data/lib/vendor/thor/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
  89. data/lib/vendor/thor/spec/fixtures/enum.thor +10 -0
  90. data/lib/vendor/thor/spec/fixtures/group.thor +128 -0
  91. data/lib/vendor/thor/spec/fixtures/invoke.thor +118 -0
  92. data/lib/vendor/thor/spec/fixtures/path with spaces +0 -0
  93. data/lib/vendor/thor/spec/fixtures/preserve/script.sh +3 -0
  94. data/lib/vendor/thor/spec/fixtures/script.thor +220 -0
  95. data/lib/vendor/thor/spec/fixtures/subcommand.thor +17 -0
  96. data/lib/vendor/thor/spec/group_spec.rb +222 -0
  97. data/lib/vendor/thor/spec/helper.rb +67 -0
  98. data/lib/vendor/thor/spec/invocation_spec.rb +108 -0
  99. data/lib/vendor/thor/spec/parser/argument_spec.rb +53 -0
  100. data/lib/vendor/thor/spec/parser/arguments_spec.rb +66 -0
  101. data/lib/vendor/thor/spec/parser/option_spec.rb +202 -0
  102. data/lib/vendor/thor/spec/parser/options_spec.rb +400 -0
  103. data/lib/vendor/thor/spec/rake_compat_spec.rb +72 -0
  104. data/lib/vendor/thor/spec/register_spec.rb +197 -0
  105. data/lib/vendor/thor/spec/runner_spec.rb +241 -0
  106. data/lib/vendor/thor/spec/shell/basic_spec.rb +330 -0
  107. data/lib/vendor/thor/spec/shell/color_spec.rb +95 -0
  108. data/lib/vendor/thor/spec/shell/html_spec.rb +31 -0
  109. data/lib/vendor/thor/spec/shell_spec.rb +47 -0
  110. data/lib/vendor/thor/spec/subcommand_spec.rb +30 -0
  111. data/lib/vendor/thor/spec/thor_spec.rb +499 -0
  112. data/lib/vendor/thor/spec/util_spec.rb +196 -0
  113. data/lib/vendor/thor/thor.gemspec +24 -0
  114. data/script/release +50 -0
  115. data/script/setup_build +6 -0
  116. data/script/test +23 -0
  117. data/spec/auth_spec.rb +15 -0
  118. data/spec/cassettes/databases/all_databases.json +1 -0
  119. data/spec/cassettes/databases/copy_database_from_dev_to_stage.json +1 -0
  120. data/spec/cassettes/databases/create_a_database_backup.json +1 -0
  121. data/spec/cassettes/databases/create_a_new_database.json +1 -0
  122. data/spec/cassettes/databases/delete_a_database.json +1 -0
  123. data/spec/cassettes/databases/get_all_existing_databases.json +1 -0
  124. data/spec/cassettes/databases/list_all_database_backups.json +1 -0
  125. data/spec/cassettes/databases/view_database_instance_details.json +1 -0
  126. data/spec/cassettes/deploy/release_vcs_branch.json +1 -0
  127. data/spec/cassettes/domains/create_new_domain.json +1 -0
  128. data/spec/cassettes/domains/delete_a_domain.json +1 -0
  129. data/spec/cassettes/domains/get_all_existing_domains.json +1 -0
  130. data/spec/cassettes/domains/list_all_dev_domains.json +1 -0
  131. data/spec/cassettes/domains/move_from_dev_to_stage.json +1 -0
  132. data/spec/cassettes/domains/purge_varnish_cache.json +1 -0
  133. data/spec/cassettes/environments/all_environments.json +1 -0
  134. data/spec/cassettes/environments/disable_live_development.json +1 -0
  135. data/spec/cassettes/environments/enable_live_development.json +1 -0
  136. data/spec/cassettes/files/copy_from_dev_to_stage.json +1 -0
  137. data/spec/cassettes/servers/all_dev_servers.json +1 -0
  138. data/spec/cassettes/servers/all_prod_servers.json +1 -0
  139. data/spec/cassettes/sites/all_sites.json +1 -0
  140. data/spec/cassettes/ssh/all_sshkeys.json +1 -0
  141. data/spec/cassettes/svn/all_svnusers.json +1 -0
  142. data/spec/cassettes/tasks/all_tasks.json +1 -0
  143. data/spec/databases_spec.rb +78 -0
  144. data/spec/deploy_spec.rb +12 -0
  145. data/spec/domains_spec.rb +59 -0
  146. data/spec/environments_spec.rb +35 -0
  147. data/spec/files_spec.rb +11 -0
  148. data/spec/helper.rb +104 -0
  149. data/spec/servers_spec.rb +59 -0
  150. data/spec/sites_spec.rb +19 -0
  151. data/spec/ssh_spec.rb +19 -0
  152. data/spec/svn_spec.rb +11 -0
  153. data/spec/tasks_spec.rb +11 -0
  154. metadata +158 -4
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ *.tmp
3
+ *.swp
4
+ *.gem
5
+
6
+ coverage/*
7
+ tmp/*
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ - "2.0.0"
6
+ script: "bundle exec rspec spec"
7
+ before_install: "ruby ./script/setup_build"
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,11 @@
1
+ # Submitting a Pull Request
2
+
3
+ * Check out the README guide for getting the project setup and running locally.
4
+ * Fork the repository.
5
+ * Create a topic branch.
6
+ * Add specs for your unimplemented feature or bug fix.
7
+ * Run `script/test` from the repository root. If your specs and tests pass,
8
+ continue on, otherwise fix them.
9
+ * Add documentation for your feature or bug fix.
10
+ * Add, commit, and push your changes.
11
+ * Submit a pull request.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ acquia_toolbelt (2.3.1)
5
+ faraday (= 0.8.8)
6
+ highline (= 1.6.19)
7
+ json (= 1.8.0)
8
+ multi_json (= 1.8.2)
9
+ netrc (= 0.7.7)
10
+ rainbow (= 1.1.4)
11
+ sshkey (= 1.6.0)
12
+ thor (= 0.18.1)
13
+
14
+ GEM
15
+ remote: https://rubygems.org/
16
+ specs:
17
+ addressable (2.3.5)
18
+ crack (0.4.1)
19
+ safe_yaml (~> 0.9.0)
20
+ diff-lcs (1.2.4)
21
+ faraday (0.8.8)
22
+ multipart-post (~> 1.2.0)
23
+ highline (1.6.19)
24
+ json (1.8.0)
25
+ multi_json (1.8.2)
26
+ multipart-post (1.2.0)
27
+ netrc (0.7.7)
28
+ rainbow (1.1.4)
29
+ rake (10.1.0)
30
+ rspec (2.14.1)
31
+ rspec-core (~> 2.14.0)
32
+ rspec-expectations (~> 2.14.0)
33
+ rspec-mocks (~> 2.14.0)
34
+ rspec-core (2.14.7)
35
+ rspec-expectations (2.14.4)
36
+ diff-lcs (>= 1.1.3, < 2.0)
37
+ rspec-mocks (2.14.4)
38
+ safe_yaml (0.9.7)
39
+ sshkey (1.6.0)
40
+ thor (0.18.1)
41
+ vcr (2.7.0)
42
+ webmock (1.15.2)
43
+ addressable (>= 2.2.7)
44
+ crack (>= 0.3.2)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ acquia_toolbelt!
51
+ bundler (~> 1.3)
52
+ rake (= 10.1.0)
53
+ rspec (= 2.14.1)
54
+ vcr (= 2.7.0)
55
+ webmock (= 1.15.2)
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Jacob Bednarz.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,149 @@
1
+ # Acquia Toolbelt
2
+
3
+ The Acquia Toolbelt is a CLI tool for using the Acquia Cloud API. Some of the
4
+ features include getting information around your servers, subscription,
5
+ databases, tasks and domains.
6
+
7
+ ## Installation
8
+
9
+ Installation is available (and recommended) via Ruby Gems.
10
+
11
+ ```bash
12
+ $ gem install acquia_toolbelt
13
+ ```
14
+
15
+ Once installed, the toolbelt is accessible via invoking `acquia` within the
16
+ command line.
17
+
18
+ ## Usage
19
+ You can see all available commands by running `acquia help`. Additonally, more
20
+ information on each command is available via `acquia [COMMAND] help`.
21
+
22
+ ```bash
23
+ $ acquia help
24
+
25
+ Type 'acquia [COMMAND] help' for more details on subcommands or to show example usage.
26
+
27
+ Commands:
28
+ acquia auth
29
+ acquia databases
30
+ acquia deploy
31
+ acquia domains
32
+ acquia environments
33
+ acquia files
34
+ acquia servers
35
+ acquia sites
36
+ acquia ssh
37
+ acquia svn
38
+ acquia tasks
39
+
40
+ Options:
41
+ -s, [--subscription=SUBSCRIPTION] # Name of a subscription you would like to target.
42
+ -e, [--environment=ENVIRONMENT] # Environment to target for commands.
43
+ -v, [--verbose] # Increase the verbose output from the commands.
44
+ ```
45
+
46
+ #### Example commands
47
+
48
+ Without parameters:
49
+
50
+ ```bash
51
+ $ acquia databases:list
52
+
53
+ > mydb
54
+ > mydb2
55
+ ```
56
+
57
+ With parameters:
58
+
59
+ ```bash
60
+ $ acquia databases:list -e dev -d mydb
61
+
62
+ > Username: exampledb
63
+ > Password: h5hKN4v2nc*1nd
64
+ > Host: staging-1234
65
+ > DB cluster: 1111
66
+ > Instance name: mydb8717
67
+ ```
68
+
69
+ ## Getting started
70
+
71
+ Before you can start using any commands, you need to first run
72
+ `acquia auth:login`. This will write your login details to a local netrc file so
73
+ that you won't be prompted for login details every time a request is made. After
74
+ that, the sky is the limit!
75
+
76
+ ## FAQ
77
+
78
+ **Q: Is there support for proxies and corporate firewalls?**
79
+
80
+ **A:** By god yes. Proxies and corporate firewalls are the bane of my existence
81
+ so there was no way this toolbelt _wasn't_ going to support it. To use a proxy,
82
+ all you need to do is set your HTTPS_PROXY environment variable to the required
83
+ value. Example:
84
+
85
+ ```bash
86
+ $ export HTTPS_PROXY="http://myproxy.url.internal:1234"
87
+ ```
88
+
89
+ Then to check the value was correctly set:
90
+
91
+ ```bash
92
+ $ echo $HTTPS_PROXY
93
+ $ http://myproxy.url.internal:1234
94
+ ```
95
+
96
+ **Q: Is there somewhere I can see all the commands with required parameters?**
97
+
98
+ **A:** Yep. Check out the
99
+ [commands listing](https://github.com/jacobbednarz/acquia-toolbelt/wiki/Commands)
100
+ in the [wiki](https://github.com/jacobbednarz/acquia-toolbelt/wiki).
101
+
102
+ ## Hacking on the Acquia Toolbelt
103
+
104
+ The Acquia Toolbelt uses [VCR](https://github.com/vcr/vcr) for recording and
105
+ replaying API fixtures during test runs - doing this allows the tests to stay
106
+ fast and easy for anyone to run.
107
+
108
+ Authenticated requests are currently using the user credentials from the netrc
109
+ file on your local system. It is a good idea to have this setup first (simply
110
+ by running `acquia auth:login`) as if you are recording new cassettes you will
111
+ need to be able to make actual requests. Don't worry about your user credentials
112
+ being stored in the fixtures as they are removed during the request and they
113
+ will appear as ACQUIA_USERNAME and ACQUIA_PASSWORD in the requests
114
+ respectively.
115
+
116
+ Since the cassettes are periodically refreshed to match changes to the API,
117
+ remember the keep the following in mind when making cassettes.
118
+
119
+ * **Specs should be idempotent.** The HTTP calls made during a spec should be
120
+ able to be run over and over. This means deleting a known resource prior to
121
+ creating it if the name has to be unique.
122
+ * **Specs should be able to be run in random order.** If a spec depends on
123
+ another resource as a fixture, make sure that's created in the scope of the
124
+ spec and not depend on a previous spec to create the data needed.
125
+ * **Do not depend on authenticated user info.** Instead of asserting actual
126
+ values in resources, try to assert the existence of a key or that a response
127
+ is an Array. We're testing the client, not the API.
128
+
129
+ ### Running and writing new tests
130
+
131
+ The testing is mainly done via [RSpec](https://github.com/rspec/rspec). To run
132
+ the test suite, execute the `script/test` script in the root of the repository:
133
+
134
+ ```bash
135
+ $ script/test
136
+ ```
137
+
138
+ This will ensure all dependencies are installed and kick off the test suite.
139
+
140
+ ### Supported versions
141
+
142
+ This library aims to support and is [tested against](https://travis-ci.org/jacobbednarz/acquia-toolbelt) the following Ruby implementations:
143
+
144
+ * Ruby 1.9.2
145
+ * Ruby 1.9.3
146
+ * Ruby 2.0.0
147
+
148
+ If you would like support for other implementations or versions, please open an
149
+ issue and it can be looked into.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'acquia_toolbelt/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'acquia_toolbelt'
8
+ spec.version = AcquiaToolbelt::VERSION
9
+ spec.authors = ['Jacob Bednarz']
10
+ spec.email = ['jacob.bednarz@gmail.com']
11
+ spec.summary = %q{A CLI tool for interacting with Acquia's hosting services.}
12
+ spec.description = %q{The Acquia Toolbelt allows you to interact with the Acquia Cloud API via the CLI.}
13
+ spec.homepage = 'https://github.com/jacobbednarz/acquia-toolbelt'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_runtime_dependency 'thor', '0.18.1'
21
+ spec.add_runtime_dependency 'netrc', '0.7.7'
22
+ spec.add_runtime_dependency 'highline', '1.6.19'
23
+ spec.add_runtime_dependency 'faraday', '0.8.8'
24
+ spec.add_runtime_dependency 'json', '1.8.0'
25
+ spec.add_runtime_dependency 'rainbow', '1.1.4'
26
+ spec.add_runtime_dependency 'sshkey', '1.6.0'
27
+ spec.add_runtime_dependency 'multi_json', '1.8.2'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.3'
30
+ spec.add_development_dependency 'rake', '10.1.0'
31
+ spec.add_development_dependency 'rspec', '2.14.1'
32
+ spec.add_development_dependency 'vcr', '2.7.0'
33
+ spec.add_development_dependency 'webmock', '1.15.2'
34
+ end
data/bin/acquia ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.expand_path('../../lib', __FILE__))
3
+ require 'acquia_toolbelt/cli'
4
+
5
+ begin
6
+ AcquiaToolbelt::CLI.start
7
+ rescue
8
+ exit(1)
9
+ end
@@ -0,0 +1,164 @@
1
+ require "netrc"
2
+ require "faraday"
3
+ require "json"
4
+ require "acquia_toolbelt/version"
5
+
6
+ module AcquiaToolbelt
7
+ class CLI
8
+ class API
9
+ USER_AGENT = "AcquiaToolbelt/#{AcquiaToolbelt::VERSION}"
10
+ ENDPOINT = "https://cloudapi.acquia.com"
11
+ ENDPOINT_VERSION = "v1"
12
+
13
+ # Internal: Send a request to the Acquia API.
14
+ #
15
+ # Build a HTTP request to connect to the Acquia API and handle the JSON
16
+ # response accordingly.
17
+ #
18
+ # resource - The resource URI that is after the version in the API
19
+ # URI.
20
+ # method - HTTP verb to use on the request.
21
+ # data - Data to send to the endpoint.
22
+ # parse_request - Whether to JSON parse the body before returning or just
23
+ # return the whole request object. The whole request is
24
+ # returned during tests whereas only the body is required
25
+ # for the application.
26
+ #
27
+ # Retuns JSON object from the response body.
28
+ def self.request(resource, method = "GET", data = {}, parse_request = true)
29
+ n = Netrc.read
30
+
31
+ # Make sure there is an entry for the Acquia API before generating the
32
+ # requests.
33
+ if n["cloudapi.acquia.com"].nil?
34
+ puts "No entry for cloudapi.acquia.com within your netrc file."
35
+ puts "You can login/reset your user credentials by running `acquia auth:login`"
36
+ return
37
+ end
38
+
39
+ @acquia_user, @acquia_password = n["cloudapi.acquia.com"]
40
+
41
+ # Check if the user is behind a proxy and add the proxy settings if
42
+ # they are.
43
+ conn = (using_proxy?) ? Faraday.new(:proxy => ENV["HTTPS_PROXY"]) : Faraday.new
44
+ conn.basic_auth(@acquia_user, @acquia_password)
45
+
46
+ # Be nice and send a user agent - help tracking and issue detection on
47
+ # Acquia's end as well as the client.
48
+ conn.headers["User-Agent"] = "#{AcquiaToolbelt::CLI::API::USER_AGENT}"
49
+
50
+ case method
51
+ when "GET"
52
+ response = conn.get "#{endpoint_uri}/#{resource}.json"
53
+ is_successful_response? response
54
+
55
+ if parse_request == true
56
+ JSON.parse(response.body)
57
+ else
58
+ response
59
+ end
60
+ when "POST"
61
+ response = conn.post "#{endpoint_uri}/#{resource}.json", data.to_json
62
+ is_successful_response? response
63
+
64
+ if parse_request == true
65
+ JSON.parse(response.body)
66
+ else
67
+ response
68
+ end
69
+ when "QUERY-STRING-POST"
70
+ response = conn.post "#{endpoint_uri}/#{resource}.json?#{data[:key]}=#{data[:value]}", data.to_json
71
+ is_successful_response? response
72
+
73
+ if parse_request == true
74
+ JSON.parse(response.body)
75
+ else
76
+ response
77
+ end
78
+ when "DELETE"
79
+ response = conn.delete "#{endpoint_uri}/#{resource}.json"
80
+ is_successful_response? response
81
+
82
+ if parse_request == true
83
+ JSON.parse(response.body)
84
+ else
85
+ response
86
+ end
87
+ else
88
+ end
89
+ end
90
+
91
+ # Internal: Get defined subscription environments.
92
+ #
93
+ # This is a helper method that fetches all the available environments for
94
+ # a subscription and returns them for use in other methods.
95
+ #
96
+ # Returns an array of environments.
97
+ def self.get_environments
98
+ subscription = default_subscription
99
+ env_data = request "sites/#{subscription}/envs"
100
+
101
+ envs = []
102
+ env_data.each do |env|
103
+ envs << env["name"]
104
+ end
105
+
106
+ envs
107
+ end
108
+
109
+ # Internal: Use the default environment the user has access to.
110
+ #
111
+ # If the -s (subscription) flag is not set, just use the first
112
+ # subscription the user has access to. This is handy for users that
113
+ # primarily only deal with a specific subscription.
114
+ #
115
+ # Returns the first subscription name.
116
+ def self.default_subscription
117
+ sites = request "sites"
118
+ sites.first
119
+ end
120
+
121
+ # Internal: Build the endpoint URI.
122
+ #
123
+ # By building the URI here, we ensure that it is consistent throughout the
124
+ # application and also allows a single point to update should it be
125
+ # needed.
126
+ #
127
+ # Returns a URI string.
128
+ def self.endpoint_uri
129
+ "#{AcquiaToolbelt::CLI::API::ENDPOINT}/#{AcquiaToolbelt::CLI::API::ENDPOINT_VERSION}"
130
+ end
131
+
132
+ # Internal: Check whether a proxy is in use.
133
+ #
134
+ # Return boolean based on whether HTTPS_PROXY is set.
135
+ def self.using_proxy?
136
+ ENV["HTTPS_PROXY"] ? true : false
137
+ end
138
+
139
+ # Internal: Show the error message from the response.
140
+ #
141
+ # If the API request fails, this will get the "message" and allow that to
142
+ # be outputted to the end user to be a little more helpful.
143
+ #
144
+ # Returns string of the message.
145
+ def self.display_error(response)
146
+ "Oops, an error occurred! Reason: #{response["message"]}"
147
+ end
148
+
149
+ # Internal: Ensure the response returns a HTTP 200.
150
+ #
151
+ # If the response status isn't a HTTP 200, we need to find out why. This
152
+ # helps identify the issues earlier on and will prevent extra API calls
153
+ # that won't complete.
154
+ #
155
+ # Returns false if the response code isn't a HTTP 200.
156
+ def self.is_successful_response?(response)
157
+ if response.status != 200
158
+ puts display_error(JSON.parse(response.body))
159
+ return
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,31 @@
1
+ require "highline/import"
2
+ require "netrc"
3
+ require "acquia_toolbelt/cli"
4
+
5
+ module AcquiaToolbelt
6
+ class CLI
7
+ class Auth < AcquiaToolbelt::Thor
8
+ # Public: Login to an Acquia account.
9
+ #
10
+ # Save the login details in a netrc file for use for all authenticated
11
+ # requests.
12
+ #
13
+ # Returns a status message.
14
+ desc "login", "Login to your Acquia account."
15
+ def login
16
+ cli = HighLine.new
17
+ user = cli.ask("Enter your username: ")
18
+ password = cli.ask("Enter your password: ") { |q| q.echo = false }
19
+
20
+ # Update (or create if needed) the netrc file that will contain the user
21
+ # authentication details.
22
+ n = Netrc.read
23
+ n.new_item_prefix = "# This entry was added for connecting to the Acquia Cloud API\n"
24
+ n["cloudapi.acquia.com"] = user, password
25
+ n.save
26
+
27
+ ui.success "Your user credentials have been successfully set."
28
+ end
29
+ end
30
+ end
31
+ end