acquia_sdk_ruby 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/acquia_sdk_ruby/cloudapi/client.rb +78 -19
- data/lib/acquia_sdk_ruby/exceptions.rb +2 -1
- data/lib/acquia_sdk_ruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efe078910a12b97cf314f3cb7b0a8754c8fc974f
|
4
|
+
data.tar.gz: 8ea0e1df7fd9eb0d43f970f741e17f115dfe35d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 556c298a7142154f4c229aff8d3ebcc443d8aad42017716661f863a01d6cd72d38e2c54618a9947149cb66cb510d9dd845bc71a300a7ff13a907a02832b45e2f
|
7
|
+
data.tar.gz: eeeea6faac539db0f956c4b6d2cfb815cd0a784c3cede394281d5f25c0364b6948c256de4df6ec07408164c62e1557c650aabe2cb1cecbe8fca5fd1feac1b52e
|
data/README.md
CHANGED
@@ -34,11 +34,21 @@ client = Acquia::CloudApi::Client.new({
|
|
34
34
|
})
|
35
35
|
|
36
36
|
# If you wish to leverage an existing cloudapi.conf or netrc entry, that is
|
37
|
-
# supported as well - just don't pass in the details and it will find it for
|
37
|
+
# supported as well - just don't pass in the details and it will find it for
|
38
38
|
# you.
|
39
39
|
client = Acquia::CloudApi::Client.new
|
40
40
|
```
|
41
41
|
|
42
|
+
### Make a request
|
43
|
+
|
44
|
+
```rb
|
45
|
+
client = Acquia::CloudApi::Client.new
|
46
|
+
|
47
|
+
# Make a request to the 'sites.json' endpoint. This URL is relative to the
|
48
|
+
# https://cloudapi.acquia.com/v1/ path.
|
49
|
+
client.get 'sites.json'
|
50
|
+
```
|
51
|
+
|
42
52
|
## Using a proxy or firewall?
|
43
53
|
|
44
54
|
No problem! The Acquia gem includes the ability to leverage environment
|
@@ -5,27 +5,61 @@ require 'json'
|
|
5
5
|
module Acquia
|
6
6
|
module CloudApi
|
7
7
|
class Client
|
8
|
+
attr_accessor :client
|
9
|
+
|
8
10
|
def initialize(options = {})
|
9
11
|
# Providing that we have both the username and the password, use it
|
10
12
|
# otherwise we will run through the available authentication sources to
|
11
13
|
# find our user details.
|
12
14
|
options[:username] ||= user_credentials[:username]
|
13
15
|
options[:password] ||= user_credentials[:password]
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
|
17
|
+
@options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
# Text representation of the client, masking sensitive information.
|
21
|
+
#
|
22
|
+
# Returns a string.
|
23
|
+
def inspect
|
24
|
+
inspected = super
|
25
|
+
|
26
|
+
# Mask the password.
|
27
|
+
if @options[:password]
|
28
|
+
inspected = inspected.gsub! @options[:password], conceal(@options[:password])
|
21
29
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
30
|
+
|
31
|
+
inspected
|
32
|
+
end
|
33
|
+
|
34
|
+
# Internal: Get the default site for the user.
|
35
|
+
#
|
36
|
+
# Returns a string containing the users first site.
|
37
|
+
def default_site
|
38
|
+
response = get 'sites.json'
|
39
|
+
response.first
|
40
|
+
end
|
41
|
+
|
42
|
+
# Public: Make a GET HTTP request.
|
43
|
+
#
|
44
|
+
# url - The URL to request.
|
45
|
+
#
|
46
|
+
# Returns a Faraday::Connection object.
|
47
|
+
def get(url)
|
48
|
+
request :get, url
|
49
|
+
end
|
50
|
+
|
51
|
+
# Internal: Conceal parts of the string.
|
52
|
+
#
|
53
|
+
# Example:
|
54
|
+
#
|
55
|
+
# conceal "thisismysensitivestring"
|
56
|
+
# # => "this****ring"
|
57
|
+
#
|
58
|
+
# Returns a string with only the first and last 4 characters visible.
|
59
|
+
def conceal(string)
|
60
|
+
front = string[0, 4]
|
61
|
+
back = string[-4, 4]
|
62
|
+
"#{front}****#{back}"
|
29
63
|
end
|
30
64
|
|
31
65
|
# Internal: Determine if the user is behind a firewall or proxy.
|
@@ -34,21 +68,21 @@ module Acquia
|
|
34
68
|
def proxy?
|
35
69
|
(ENV['HTTPS_PROXY'].nil?) ? false : true
|
36
70
|
end
|
37
|
-
|
71
|
+
|
38
72
|
# Internal: Define the proxy options for requests.
|
39
73
|
#
|
40
|
-
# Returns hash of proxy options.
|
74
|
+
# Returns hash of proxy options or nil if not in use.
|
41
75
|
def proxy_opts
|
42
|
-
{ uri: ENV['HTTPS_PROXY'] }
|
76
|
+
(proxy?) ? { uri: ENV['HTTPS_PROXY'] } : nil
|
43
77
|
end
|
44
|
-
|
78
|
+
|
45
79
|
# Internal: Build the SSL options for requests.
|
46
80
|
#
|
47
81
|
# Returns a hash of the SSL options to apply to requests.
|
48
82
|
def ssl_opts
|
49
83
|
{ verify: true, ca_file: File.expand_path('etc/ca.pem') }
|
50
84
|
end
|
51
|
-
|
85
|
+
|
52
86
|
# Internal: Get the user credentials from available sources.
|
53
87
|
#
|
54
88
|
# This method is responsible for checking the available sources and
|
@@ -106,6 +140,31 @@ module Acquia
|
|
106
140
|
def netrc_path
|
107
141
|
"#{Dir.home}/.netrc"
|
108
142
|
end
|
143
|
+
|
144
|
+
private
|
145
|
+
|
146
|
+
# Private: Make a HTTP request.
|
147
|
+
#
|
148
|
+
# url - The relative URL of the resource to request.
|
149
|
+
# options - Hash of options to pass through to the request.
|
150
|
+
#
|
151
|
+
# Returns a JSON string of the body.
|
152
|
+
def request(method, url, options = {})
|
153
|
+
request = Faraday.new(url: Acquia.cloud_api_endpoint, ssl: ssl_opts) do |c|
|
154
|
+
c.adapter Faraday.default_adapter
|
155
|
+
c.headers['User-Agent'] = "Acquia SDK (#{Acquia::VERSION})"
|
156
|
+
c.basic_auth(@options[:username], @options[:password])
|
157
|
+
c.proxy proxy_opts
|
158
|
+
c.use Faraday::Response::RaiseError
|
159
|
+
end
|
160
|
+
|
161
|
+
case method
|
162
|
+
when :get
|
163
|
+
response = request.get url
|
164
|
+
end
|
165
|
+
|
166
|
+
JSON.parse(response.body)
|
167
|
+
end
|
109
168
|
end
|
110
169
|
end
|
111
170
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acquia_sdk_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Bednarz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|