acquia_sdk_ruby 0.0.1
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 +7 -0
- data/LICENSE +22 -0
- data/README.md +57 -0
- data/lib/acquia_sdk_ruby/cloudapi/client.rb +111 -0
- data/lib/acquia_sdk_ruby/cloudapi.rb +1 -0
- data/lib/acquia_sdk_ruby/exceptions.rb +6 -0
- data/lib/acquia_sdk_ruby/version.rb +6 -0
- data/lib/acquia_sdk_ruby.rb +26 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8210a7ea2066ad8da88280c4e8ddc879ce08d634
|
4
|
+
data.tar.gz: 7cce14d03026589de66e6b33fbf5aa83ea12718f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1408dbcb924e951f422fb7903ae582c731ab4f7333d82fbcec3819771d3a85b7c718ab2fbb133d6a8ab4ada19b47776397182edbf07250a7e2f8228333e67068
|
7
|
+
data.tar.gz: 6a4d5206361accda30df276ceabf41ab585788f5176ae3eb5d8235e48653aaaa45c8794ee3c315151689df530af88f172985046cc81a782707c67641f09d3344
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jacob Bednarz
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Acquia Ruby SDK
|
2
|
+
|
3
|
+
The Acquia Ruby SDK allows developers to interact and build tools using the
|
4
|
+
Acquia platform.
|
5
|
+
|
6
|
+
## Requirements
|
7
|
+
|
8
|
+
- Ruby 2.0+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Pop the following into your Gemfile.
|
13
|
+
|
14
|
+
```rb
|
15
|
+
gem 'acquia_sdk_ruby'
|
16
|
+
```
|
17
|
+
|
18
|
+
Or if you would like to install it yourself, try this:
|
19
|
+
|
20
|
+
```sh
|
21
|
+
$ gem install acquia_sdk_ruby
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage examples
|
25
|
+
|
26
|
+
### Cloud API
|
27
|
+
|
28
|
+
```rb
|
29
|
+
# Initiate a connection by passing in the user credentials.
|
30
|
+
client = Acquia::CloudApi::Client.new({
|
31
|
+
username: 'my_user@example.com',
|
32
|
+
password: 'topsecretpassword',
|
33
|
+
site: 'devcloud:example'
|
34
|
+
})
|
35
|
+
|
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
|
38
|
+
# you.
|
39
|
+
client = Acquia::CloudApi::Client.new
|
40
|
+
```
|
41
|
+
|
42
|
+
## Using a proxy or firewall?
|
43
|
+
|
44
|
+
No problem! The Acquia gem includes the ability to leverage environment
|
45
|
+
variables for defining proxies or firewall rules. Just define your gateway using
|
46
|
+
the `HTTPS_PROXY` variable and it will be included for all requests.
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
- Fork this repository.
|
51
|
+
- Create a new feature branch (`git checkout -b my-awesome-feature`).
|
52
|
+
- Make your proposed changes.
|
53
|
+
- Commit them to the feature branch.
|
54
|
+
- Push up your changes and open a new pull request.
|
55
|
+
|
56
|
+
_NB: If you are making code changes, they will require tests to accompany them
|
57
|
+
otherwise your changes may accidently break in future releases._
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'netrc'
|
2
|
+
require 'faraday'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Acquia
|
6
|
+
module CloudApi
|
7
|
+
class Client
|
8
|
+
def initialize(options = {})
|
9
|
+
# Providing that we have both the username and the password, use it
|
10
|
+
# otherwise we will run through the available authentication sources to
|
11
|
+
# find our user details.
|
12
|
+
options[:username] ||= user_credentials[:username]
|
13
|
+
options[:password] ||= user_credentials[:password]
|
14
|
+
|
15
|
+
# Build our connection using a proxy and correct SSL options.
|
16
|
+
connection = Faraday.new(url: Acquia.cloud_api_endpoint, ssl: ssl_opts) do |c|
|
17
|
+
c.adapter Faraday.default_adapter
|
18
|
+
c.headers['User-Agent'] = "Acquia SDK (#{Acquia::VERSION})"
|
19
|
+
c.basic_auth(options[:username], options[:password])
|
20
|
+
c.proxy = proxy_opts if proxy?
|
21
|
+
end
|
22
|
+
|
23
|
+
response = connection.get 'sites.json'
|
24
|
+
fail InvalidUserCredentials, 'Invalid user credentials' if response.status == 401
|
25
|
+
|
26
|
+
# Haven't made a site selection? Looks like you get the first one we
|
27
|
+
# find.
|
28
|
+
options[:site] ||= JSON.parse(response.body).first
|
29
|
+
end
|
30
|
+
|
31
|
+
# Internal: Determine if the user is behind a firewall or proxy.
|
32
|
+
#
|
33
|
+
# Returns a boolean based on whether the environment variable is found.
|
34
|
+
def proxy?
|
35
|
+
(ENV['HTTPS_PROXY'].nil?) ? false : true
|
36
|
+
end
|
37
|
+
|
38
|
+
# Internal: Define the proxy options for requests.
|
39
|
+
#
|
40
|
+
# Returns hash of proxy options.
|
41
|
+
def proxy_opts
|
42
|
+
{ uri: ENV['HTTPS_PROXY'] }
|
43
|
+
end
|
44
|
+
|
45
|
+
# Internal: Build the SSL options for requests.
|
46
|
+
#
|
47
|
+
# Returns a hash of the SSL options to apply to requests.
|
48
|
+
def ssl_opts
|
49
|
+
{ verify: true, ca_file: File.expand_path('etc/ca.pem') }
|
50
|
+
end
|
51
|
+
|
52
|
+
# Internal: Get the user credentials from available sources.
|
53
|
+
#
|
54
|
+
# This method is responsible for checking the available sources and
|
55
|
+
# providing the user credentials back in a hash.
|
56
|
+
#
|
57
|
+
# Returns a hash of the user credentials keyed with 'username' and
|
58
|
+
# 'password'.
|
59
|
+
def user_credentials
|
60
|
+
acquia_conf_auth if File.exist? acquia_conf_path
|
61
|
+
netrc_auth if File.exist? netrc_path
|
62
|
+
end
|
63
|
+
|
64
|
+
# Internal: Pull the details out of the Acquia configuration file.
|
65
|
+
#
|
66
|
+
# This will find the Acquia Cloud configuration file and extract the
|
67
|
+
# username and password from the JSON object.
|
68
|
+
#
|
69
|
+
# Returns a hash of the username and password.
|
70
|
+
def acquia_conf_auth
|
71
|
+
user_data = JSON.parse(File.read(acquia_conf_path))
|
72
|
+
{ username: user_data['email'], password: user_data['key'] }
|
73
|
+
end
|
74
|
+
|
75
|
+
# Internal: Fetch the user credentials from a netrc file.
|
76
|
+
#
|
77
|
+
# Check and see if the user has a local netrc entry for the Cloud API and
|
78
|
+
# should it be found, use it.
|
79
|
+
#
|
80
|
+
# Returns a hash of the username and password.
|
81
|
+
def netrc_auth
|
82
|
+
n = Netrc.read
|
83
|
+
|
84
|
+
# While netrc file may exist, we cannot always be certain that the Cloud
|
85
|
+
# API credentials are present.
|
86
|
+
if n['cloudapi.acquia.com'].nil?
|
87
|
+
fail MissingNetrcConfiguration, "No entry for cloudapi.acquia.com found in #{netrc_path}"
|
88
|
+
end
|
89
|
+
|
90
|
+
username = n['cloudapi.acquia.com'].login
|
91
|
+
password = n['cloudapi.acquia.com'].password
|
92
|
+
|
93
|
+
{ username: username, password: password }
|
94
|
+
end
|
95
|
+
|
96
|
+
# Internal: Path to the Acquia Cloud configuration file.
|
97
|
+
#
|
98
|
+
# Returns a string of the file path to the cloudapi.conf file.
|
99
|
+
def acquia_conf_path
|
100
|
+
"#{Dir.home}/.acquia/cloudapi.conf"
|
101
|
+
end
|
102
|
+
|
103
|
+
# Internal: Path to the user's netrc.
|
104
|
+
#
|
105
|
+
# Returns a string of the file path to the users netrc file.
|
106
|
+
def netrc_path
|
107
|
+
"#{Dir.home}/.netrc"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'acquia_sdk_ruby/cloudapi/client'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'acquia_sdk_ruby/version'
|
2
|
+
require 'acquia_sdk_ruby/cloudapi'
|
3
|
+
require 'acquia_sdk_ruby/exceptions'
|
4
|
+
|
5
|
+
module Acquia
|
6
|
+
# Internal: The Cloud API endpoint as a full URI.
|
7
|
+
#
|
8
|
+
# Returns a string of the endpoint.
|
9
|
+
def self.cloud_api_endpoint
|
10
|
+
"#{cloud_api_uri}/#{cloud_api_version}/"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Internal: The base URI of the Acquia Cloud API.
|
14
|
+
#
|
15
|
+
# Returns a string of the base URI.
|
16
|
+
def self.cloud_api_uri
|
17
|
+
'https://cloudapi.acquia.com'
|
18
|
+
end
|
19
|
+
|
20
|
+
# Internal: Current version of the Cloud API.
|
21
|
+
#
|
22
|
+
# Returns a string which indicates the current version of the Cloud API.
|
23
|
+
def self.cloud_api_version
|
24
|
+
'v1'
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acquia_sdk_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jacob Bednarz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 3.0.0
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '3.0'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.0.0
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: faraday
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0.9'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0.9'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: netrc
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.10'
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0.10'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: json
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.8'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.8'
|
103
|
+
description: A Ruby based SDK for interacting with the Acquia Hosting platform
|
104
|
+
email:
|
105
|
+
- jacob.bednarz@gmail.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- LICENSE
|
111
|
+
- README.md
|
112
|
+
- lib/acquia_sdk_ruby.rb
|
113
|
+
- lib/acquia_sdk_ruby/cloudapi.rb
|
114
|
+
- lib/acquia_sdk_ruby/cloudapi/client.rb
|
115
|
+
- lib/acquia_sdk_ruby/exceptions.rb
|
116
|
+
- lib/acquia_sdk_ruby/version.rb
|
117
|
+
homepage: http://github.com/jacobbednarz/acquia-sdk-ruby
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '2.0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.4.5
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Acquia Ruby SDK
|
141
|
+
test_files: []
|