xnode-keystone 0.1.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/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/xnode/keystone.rb +71 -0
- data/lib/xnode/keystone/http.rb +41 -0
- data/lib/xnode/keystone/utils.rb +24 -0
- data/lib/xnode/keystone/version.rb +7 -0
- data/xnode-keystone.gemspec +28 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9faa42e7c5f50577cc4d610767b4b021a7e6f622
|
4
|
+
data.tar.gz: ad518d1b937e84929b1ac9d79a75e427a7508d4a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 346eb8480ffd28829dc528b5917499c1289e9c0da04160ab8bb8c7341c51b15f99ae3a626e19f9eede7e48b406a243c4c8efc5fb638b65e9c0a5303202734216
|
7
|
+
data.tar.gz: 663691086092b08fa30cf74460627b000bb7aa77d3c0ff58d3e355182f93ca9e29102f7ec54162181008a2b27cc1558dcc132732cbe02140bc3d4a43dcf97c80
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Paul Stevens
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Xnode::Keystone
|
2
|
+
|
3
|
+

|
4
|
+
|
5
|
+
`xnode-keystone` provides methods that allow you to interact with the Keystone Identity service provided by an OpenStack
|
6
|
+
cloud. It covers your authentication, and depending on your rights within the cloud, the ability to query and manipulate
|
7
|
+
users and tenants.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'xnode-keystone'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install xnode-keystone
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Basic usage is as follows. You need to have an openrc file somewhere that looks something like this:
|
28
|
+
|
29
|
+
```
|
30
|
+
export OS_USERNAME=demo
|
31
|
+
export OS_PASSWORD=supas33krit
|
32
|
+
export OS_TENANT_NAME=Demo
|
33
|
+
export OS_AUTH_URL=https://controller:5000/v2.0
|
34
|
+
```
|
35
|
+
|
36
|
+
Source it with `. openrc.sh` to load the environment variables. `xnode-keystone` needs these to find your creds.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'xnode-keystone'
|
40
|
+
|
41
|
+
# Initialise a new instance of the base class
|
42
|
+
auth = Xnode::Keystone::Authenticate.new
|
43
|
+
|
44
|
+
# Send an authentication request, and get a JSON response back that's been decoded bash into a Hash
|
45
|
+
request = auth.request
|
46
|
+
|
47
|
+
# To extract a token from the request...
|
48
|
+
token = auth.get_token(request)
|
49
|
+
|
50
|
+
# And to get the public compute API endpoint back...
|
51
|
+
endpoints = auth.catalog(request)
|
52
|
+
compute = endpoints['compute']['public']
|
53
|
+
```
|
54
|
+
|
55
|
+
## Development
|
56
|
+
|
57
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
58
|
+
|
59
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/xnoder/xnode-keystone.
|
64
|
+
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "xnode/keystone"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# This gem provides methods for interacting with the OpenStack Keystone Identity service via HTTP calls to the
|
2
|
+
# RESTful API. On initialization of the class, it simply reads in environment variables sourced to your shell
|
3
|
+
# via an openrc.sh file (see http://docs.openstack.org/icehouse/install-guide/install/apt/content/ch_clients_openrc_files.html)
|
4
|
+
# for the details.
|
5
|
+
#
|
6
|
+
# Author:: Paul Stevens (mailto:ps@xnode.co.za)
|
7
|
+
# Copyright:: Copyright (c) 2015 Paul Stevens
|
8
|
+
# License:: Distributed under the MIT license.
|
9
|
+
|
10
|
+
require "xnode/keystone/version"
|
11
|
+
require "xnode/keystone/http"
|
12
|
+
require "xnode/keystone/utils"
|
13
|
+
|
14
|
+
require 'json'
|
15
|
+
|
16
|
+
module Xnode
|
17
|
+
module Keystone
|
18
|
+
|
19
|
+
# This class sets up an authenticated session with the OpenStack API's via Keystone, and exposes methods for
|
20
|
+
# interacting the Identity service.
|
21
|
+
#
|
22
|
+
# ==== Example
|
23
|
+
#
|
24
|
+
# => auth = Xnode::Keystone::Authenticate.new
|
25
|
+
# => request = auth.request
|
26
|
+
# => token = auth.get_token(request)
|
27
|
+
class Authenticate
|
28
|
+
|
29
|
+
# Set accessors for credentials
|
30
|
+
attr_accessor :username, :password, :tenant, :baseurl, :url
|
31
|
+
|
32
|
+
# Authenticates against the OpenStack Identity API endpoint on 5000/tcp or 35357/tcp via HTTP/S.
|
33
|
+
# Uses environment variables to set your authentication credentials.
|
34
|
+
def initialize
|
35
|
+
@username = ENV['OS_USERNAME']
|
36
|
+
@password = ENV['OS_PASSWORD']
|
37
|
+
@tenant = ENV['OS_TENANT_NAME']
|
38
|
+
@baseurl = ENV['OS_AUTH_URL']
|
39
|
+
end
|
40
|
+
|
41
|
+
# Uses a private post method (keystone/http.rb) to send an HTTP POST request to OpenStack. The JSON response is
|
42
|
+
# automatically decoded into a Ruby Hash for later manipulation. The response body remains untouched otherwise,
|
43
|
+
# so everything you'd expect to find in the response is within the Hash.
|
44
|
+
def request
|
45
|
+
url = @baseurl + '/tokens'
|
46
|
+
data = Xnode::Keystone.auth_data(@tenant, @username, @password).to_json
|
47
|
+
response = Xnode::Keystone.post(url, data)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Extracts the authentication token from the response, returning it as a String.
|
51
|
+
def get_token(data)
|
52
|
+
data['access']['token']['id']
|
53
|
+
end
|
54
|
+
|
55
|
+
# Parses the serviceCatalog returned within the response, and writes it into a modified Hash that makes it
|
56
|
+
# easy to extract public, internal or admin URI's by service type.
|
57
|
+
def catalog(data)
|
58
|
+
mapendpoints = Hash.new
|
59
|
+
data['access']['serviceCatalog'].each do |key, value|
|
60
|
+
mapendpoints[key['type']] = {
|
61
|
+
'public' => key['endpoints'][0]['publicURL'],
|
62
|
+
'internal' => key['endpoints'][0]['internalURL'],
|
63
|
+
'admin' => key['endpoints'][0]['adminURL']
|
64
|
+
}
|
65
|
+
end
|
66
|
+
return mapendpoints
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# This module manages the actual HTTP requests made throughout the gem. The methods are effectively wrappers around
|
2
|
+
# other library calls, but allows the author to switch out and modify the requests without breaking the API, as
|
3
|
+
# the request responses are dictated by the OpenStack platform, allowing some scope in modifying the request/response
|
4
|
+
# features for speed or error handling proficiency.
|
5
|
+
|
6
|
+
require 'rest-client'
|
7
|
+
|
8
|
+
module Xnode
|
9
|
+
module Keystone
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# Send an HTTP GET request to an OpenStack API endpoint.
|
14
|
+
def get(url, headers)
|
15
|
+
end
|
16
|
+
module_function :get
|
17
|
+
|
18
|
+
# Send an HTTP POST request to an OpenStack API endpoint.
|
19
|
+
def post(url, data)
|
20
|
+
request = RestClient.post "#{url}", data, :content_type => :json, :accept => :json
|
21
|
+
response = JSON.parse(request.body)
|
22
|
+
end
|
23
|
+
module_function :post
|
24
|
+
|
25
|
+
# Send an HTTP DELETE request to an OpenStack API endpoint.
|
26
|
+
def delete
|
27
|
+
end
|
28
|
+
module_function :delete
|
29
|
+
|
30
|
+
# Send an HTTP PATCH request to an OpenStack API endpoint.
|
31
|
+
def patch
|
32
|
+
end
|
33
|
+
module_function :patch
|
34
|
+
|
35
|
+
# Send an HTTP PUT request to an OpenStack API endpoint.
|
36
|
+
def put
|
37
|
+
end
|
38
|
+
module_function :put
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This module contains basic utility functions, such as structing headers, data structures for JSON conversion and
|
2
|
+
# so on.
|
3
|
+
|
4
|
+
module Xnode
|
5
|
+
module Keystone
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
# Set up a Keystone JSON request body for authentication purposes.
|
10
|
+
def auth_data(tenant, username, password)
|
11
|
+
headers = {
|
12
|
+
:auth => {
|
13
|
+
:tenantName => tenant,
|
14
|
+
:passwordCredentials => {
|
15
|
+
:username => username,
|
16
|
+
:password => password
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
module_function :auth_data
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'xnode/keystone/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "xnode-keystone"
|
8
|
+
spec.version = Xnode::Keystone::VERSION
|
9
|
+
spec.authors = ["Paul Stevens"]
|
10
|
+
spec.email = ["ps@xnode.co.za"]
|
11
|
+
|
12
|
+
spec.summary = %q{Authenticate against the OpenStack Keystone Identity Service.}
|
13
|
+
spec.description = %q{Exposes methods to allow easy authentication and URI identification of OpenStack resources.}
|
14
|
+
spec.homepage = "https://github.com/xnoder/xnode-keystone"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.add_runtime_dependency 'rest-client', "~> 1.8", ">= 1.8.0"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.3", ">= 3.3.0"
|
27
|
+
spec.add_development_dependency "webmock", "~> 1.21", ">= 1.21.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xnode-keystone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Stevens
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.8.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.8'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.8.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.10'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.10'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.3'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 3.3.0
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '3.3'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 3.3.0
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: webmock
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '1.21'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.21.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.21'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.21.0
|
101
|
+
description: Exposes methods to allow easy authentication and URI identification of
|
102
|
+
OpenStack resources.
|
103
|
+
email:
|
104
|
+
- ps@xnode.co.za
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- ".gitignore"
|
110
|
+
- ".rspec"
|
111
|
+
- ".travis.yml"
|
112
|
+
- Gemfile
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- bin/console
|
117
|
+
- bin/setup
|
118
|
+
- lib/xnode/keystone.rb
|
119
|
+
- lib/xnode/keystone/http.rb
|
120
|
+
- lib/xnode/keystone/utils.rb
|
121
|
+
- lib/xnode/keystone/version.rb
|
122
|
+
- xnode-keystone.gemspec
|
123
|
+
homepage: https://github.com/xnoder/xnode-keystone
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.4.5
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Authenticate against the OpenStack Keystone Identity Service.
|
147
|
+
test_files: []
|