ruby-keystone-client 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/.gitignore +16 -0
- data/.rspec +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +102 -0
- data/Rakefile +6 -0
- data/lib/keystone/v2_0/client.rb +89 -0
- data/lib/keystone/v2_0/manager/base.rb +63 -0
- data/lib/keystone/v2_0/manager/endpoint.rb +53 -0
- data/lib/keystone/v2_0/manager/role.rb +33 -0
- data/lib/keystone/v2_0/manager/service.rb +50 -0
- data/lib/keystone/v2_0/manager/tenant.rb +33 -0
- data/lib/keystone/v2_0/manager/user.rb +33 -0
- data/lib/keystone/v2_0/resource/base.rb +19 -0
- data/lib/keystone/v2_0/resource/endpoint.rb +29 -0
- data/lib/keystone/v2_0/resource/role.rb +23 -0
- data/lib/keystone/v2_0/resource/service.rb +25 -0
- data/lib/keystone/v2_0/resource/tenant.rb +23 -0
- data/lib/keystone/v2_0/resource/user.rb +25 -0
- data/lib/keystone/v2_0/version.rb +5 -0
- data/ruby-keystone-client.gemspec +28 -0
- data/spec/features/client_spec.rb +63 -0
- data/spec/features/manager/base_spec.rb +50 -0
- data/spec/features/manager/endpoint_spec.rb +120 -0
- data/spec/features/manager/role_spec.rb +44 -0
- data/spec/features/manager/service_spec.rb +91 -0
- data/spec/features/manager/tenant_spec.rb +42 -0
- data/spec/features/manager/user_spec.rb +43 -0
- data/spec/features/resource/endpoint_spec.rb +60 -0
- data/spec/features/resource/role_spec.rb +42 -0
- data/spec/features/resource/service_spec.rb +48 -0
- data/spec/features/resource/tenant_spec.rb +42 -0
- data/spec/features/resource/user_spec.rb +48 -0
- data/spec/spec_helper.rb +14 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 585a295cf2751dee490fe1956e44133bd8ac33e8
|
4
|
+
data.tar.gz: c281bd9a20458285b700319faa7ad3bf501820ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 69780b126eaae6bd00acced9a978e6a5601bdc469437cfd585849b1502edc5e8eded9077e79fd21a1ac9cdc44947ebb0063e386a6f2d7b4641d51c1427067667
|
7
|
+
data.tar.gz: ef7d55082aeeb0a962dbcea68f931084e730468dbc704118d827a6d7abbe9a0bc554f152e945c316b07dc37d70f81b75b208c28345cf528ffad799356acd6dfb
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
keystone-client
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.1.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2015 Cimpress
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Keystone::V2_0::Client
|
2
|
+
|
3
|
+
Ruby client to interact with the OpenStack Keystone identity and
|
4
|
+
service catalog service for Version 2.0 of the API.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'ruby-keystone-client'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
bundle
|
18
|
+
```
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
gem install ruby-keystone-client
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### Initialization
|
29
|
+
|
30
|
+
To interface with a Keystone installation, start by requiring the Keystone library:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
require 'keystone/v2_0/client'
|
34
|
+
|
35
|
+
=> true
|
36
|
+
```
|
37
|
+
|
38
|
+
Then, establish a connection to the Keystone service with which you wish to interact. For example, this
|
39
|
+
Keystone service is installed on localhost running on port 35357, and we are connecting with the following:
|
40
|
+
|
41
|
+
- Username: admin
|
42
|
+
- Password adminpass
|
43
|
+
- Tenant: admin
|
44
|
+
- Auth URL: http://127.0.0.1:35357/v2.0/
|
45
|
+
|
46
|
+
```bash
|
47
|
+
ks_client = Keystone::V2_0::Client.new("admin", "adminpass", "admin", "http://127.0.0.1:35357/v2.0/")
|
48
|
+
|
49
|
+
=> #<Keystone::V2_0::Client:0x000000030715b8 @username="admin", @password="adminpass", @tenant_name="admin", @auth_url="http://127.0.0.1:35357/v2.0/", @user_manager=#<Keystone::V2_0::Manager::User:0x00000003071590 @auth_url="http://127.0.0.1:35357/v2.0/", @url_endpoint="users", @json_key="users">, @role_manager=#<Keystone::V2_0::Manager::Role:0x00000003071568 @auth_url="http://127.0.0.1:35357/v2.0/", @url_endpoint="OS-KSADM/roles", @json_key="roles">, @tenant_manager=#<Keystone::V2_0::Manager::Tenant:0x00000003071540 @auth_url="http://127.0.0.1:35357/v2.0/", @url_endpoint="tenants", @json_key="tenants">, @service_manager=#<Keystone::V2_0::Manager::Service:0x000000030714f0 @auth_url="http://127.0.0.1:35357/v2.0/", @url_endpoint="OS-KSADM/services", @json_key="OS-KSADM:services">, @endpoint_manager=#<Keystone::V2_0::Manager::Endpoint:0x000000030714c8 @auth_url="http://127.0.0.1:35357/v2.0/", @url_endpoint="endpoints", @json_key="endpoints">>
|
50
|
+
```
|
51
|
+
|
52
|
+
Once you have your client "ks", you can continue to query for data within Keystone.
|
53
|
+
|
54
|
+
### Tenants
|
55
|
+
|
56
|
+
To query for tenants within Keystone:
|
57
|
+
|
58
|
+
```bash
|
59
|
+
ks_client.tenant_interface.list
|
60
|
+
|
61
|
+
=> [#<Keystone::V2_0::Resource::Tenant:0x00000003007398 @description="Admin Tenant", @enabled=true, @id="9958cfb44628476b8f16996e76703292", @name="admin">]
|
62
|
+
```
|
63
|
+
|
64
|
+
### Users
|
65
|
+
|
66
|
+
To query for users within Keystone:
|
67
|
+
|
68
|
+
```bash
|
69
|
+
ks_client.user_interface.list
|
70
|
+
|
71
|
+
=> [#<Keystone::V2_0::Resource::User:0x0000000309e518 @username="admin", @name="admin", @enabled=true, @email=nil, @id="49f544c6b0d0403b97d90fe0ee0b585f">]
|
72
|
+
```
|
73
|
+
|
74
|
+
### Roles
|
75
|
+
|
76
|
+
To query for roles within Keystone:
|
77
|
+
|
78
|
+
```bash
|
79
|
+
ks_client.role_interface.list
|
80
|
+
|
81
|
+
=> [#<Keystone::V2_0::Resource::Role:0x0000000303e258 @enabled="True", @description="Default role for project membership", @name="_member_", @id="9fe2ff9ee4384b1894a90878d3e92bab">, #<Keystone::V2_0::Resource::Role:0x0000000303dfd8 @name="admin", @id="e409aeca08b548ceb94ced546e1a4a18">]
|
82
|
+
```
|
83
|
+
|
84
|
+
### Endpoints
|
85
|
+
|
86
|
+
To query for endpoints within Keystone:
|
87
|
+
|
88
|
+
```bash
|
89
|
+
ks_client.endpoint_interface.list
|
90
|
+
|
91
|
+
=> [#<Keystone::V2_0::Resource::Endpoint:0x000000032add90 @admin_url="http://127.0.0.1:35357/v2.0", @service_id="876fce0975f841fdbebd8352acda75f4", @region="regionOne", @public_url="http://10.11.13.10:5000/v2.0", @enabled=true, @id="a584ab022f0348ab9335fa2468960578", @internal_url="http://10.11.13.10:5000/v2.0">]
|
92
|
+
```
|
93
|
+
|
94
|
+
### Services
|
95
|
+
|
96
|
+
To query for services within Keystone:
|
97
|
+
|
98
|
+
```bash
|
99
|
+
ks_client.service_interface.list
|
100
|
+
|
101
|
+
=> [#<Keystone::V2_0::Resource::Service:0x00000002f9d628 @id="876fce0975f841fdbebd8352acda75f4", @enabled=true, @type="identity", @name="keystone", @description="Keystone Identity Service">]
|
102
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require "keystone/v2_0/version"
|
2
|
+
require "keystone/v2_0/manager/user"
|
3
|
+
require "keystone/v2_0/manager/role"
|
4
|
+
require "keystone/v2_0/manager/tenant"
|
5
|
+
require "keystone/v2_0/manager/service"
|
6
|
+
require "keystone/v2_0/manager/endpoint"
|
7
|
+
require "rest-client"
|
8
|
+
require "json"
|
9
|
+
|
10
|
+
module Keystone
|
11
|
+
module V2_0
|
12
|
+
class Client
|
13
|
+
# client specific attributes
|
14
|
+
attr_accessor :username
|
15
|
+
attr_accessor :password
|
16
|
+
attr_accessor :tenant_name
|
17
|
+
attr_accessor :auth_url
|
18
|
+
|
19
|
+
# query providers
|
20
|
+
attr_accessor :user_manager
|
21
|
+
attr_accessor :role_manager
|
22
|
+
attr_accessor :tenant_manager
|
23
|
+
attr_accessor :service_manager
|
24
|
+
attr_accessor :endpoint_manager
|
25
|
+
|
26
|
+
# create a new Keystone client instance with the given credentials
|
27
|
+
def initialize(username, password, tenant_name, auth_url)
|
28
|
+
# initialize the object
|
29
|
+
self.username = username
|
30
|
+
self.password = password
|
31
|
+
self.tenant_name = tenant_name
|
32
|
+
self.auth_url = auth_url
|
33
|
+
|
34
|
+
# create the initial query managers
|
35
|
+
self.user_manager = Keystone::V2_0::Manager::User.new auth_url
|
36
|
+
self.role_manager = Keystone::V2_0::Manager::Role.new auth_url
|
37
|
+
self.tenant_manager = Keystone::V2_0::Manager::Tenant.new auth_url
|
38
|
+
self.service_manager = Keystone::V2_0::Manager::Service.new auth_url
|
39
|
+
self.endpoint_manager = Keystone::V2_0::Manager::Endpoint.new auth_url
|
40
|
+
|
41
|
+
# create the manager methods through which queries will be performed
|
42
|
+
# using meta-programming to ensure DRY principle is followed
|
43
|
+
[ "users", "roles", "tenants", "services", "endpoints" ].each do |query|
|
44
|
+
singular_method = query.sub(/s$/, '')
|
45
|
+
self.class.send(:define_method, "#{singular_method}_interface") do
|
46
|
+
unless (token = get_token).nil?
|
47
|
+
self.send("#{singular_method}_manager").token = token
|
48
|
+
return self.send("#{singular_method}_manager")
|
49
|
+
else
|
50
|
+
raise "An exception has occurred attempting to invoke '#{query}'"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
# obtain a token for the action being performed
|
59
|
+
def get_token
|
60
|
+
options = {}
|
61
|
+
options[:url] = self.auth_url + "/tokens"
|
62
|
+
options[:method] = :post
|
63
|
+
options[:headers] = {}
|
64
|
+
options[:headers]["User-Agent"] = "keystone-client"
|
65
|
+
options[:headers]["Accept"] = "application/json"
|
66
|
+
options[:headers]["Content-Type"] = "application/json"
|
67
|
+
options[:payload] = { "auth" =>
|
68
|
+
{ "tenantName" => self.tenant_name,
|
69
|
+
"passwordCredentials" =>
|
70
|
+
{
|
71
|
+
"username" => self.username,
|
72
|
+
"password" => self.password
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}.to_json
|
76
|
+
|
77
|
+
# provide a block to ensure the response is parseable rather than
|
78
|
+
# having RestClient throw an exception
|
79
|
+
RestClient::Request.execute(options) do |response, request, result|
|
80
|
+
if response and response.code == 200
|
81
|
+
return JSON.parse(response.body)["access"]["token"]["id"]
|
82
|
+
else
|
83
|
+
return nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "rest-client"
|
2
|
+
|
3
|
+
module Keystone
|
4
|
+
module V2_0
|
5
|
+
module Manager
|
6
|
+
class Base
|
7
|
+
attr_accessor :auth_url
|
8
|
+
attr_accessor :url_endpoint
|
9
|
+
attr_accessor :token
|
10
|
+
|
11
|
+
def initialize(auth_url, url_endpoint)
|
12
|
+
self.auth_url = auth_url
|
13
|
+
self.url_endpoint = url_endpoint
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def list
|
19
|
+
options = {}
|
20
|
+
options[:url] = "#{self.auth_url.sub(/\/$/, '')}/#{self.url_endpoint}"
|
21
|
+
options[:method] = :get
|
22
|
+
options[:headers] = {}
|
23
|
+
options[:headers]["X-Auth-Token"] = self.token
|
24
|
+
options[:headers]["User-Agent"] = "keystone-client"
|
25
|
+
options[:headers]["Accept"] = "application/json"
|
26
|
+
options[:headers]["Content-Type"] = "application/json"
|
27
|
+
|
28
|
+
# provide a block to ensure the response is parseable rather than
|
29
|
+
# having RestClient throw an exception
|
30
|
+
RestClient::Request.execute(options) do |response, request, result|
|
31
|
+
if response and response.code == 200
|
32
|
+
return JSON.parse(response.body)
|
33
|
+
else
|
34
|
+
return nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def create(payload)
|
40
|
+
options = {}
|
41
|
+
options[:url] = "#{self.auth_url.sub(/\/$/, '')}/#{self.url_endpoint}"
|
42
|
+
options[:method] = :post
|
43
|
+
options[:headers] = {}
|
44
|
+
options[:headers]["X-Auth-Token"] = self.token
|
45
|
+
options[:headers]["User-Agent"] = "keystone-client"
|
46
|
+
options[:headers]["Accept"] = "application/json"
|
47
|
+
options[:headers]["Content-Type"] = "application/json"
|
48
|
+
options[:payload] = payload
|
49
|
+
|
50
|
+
# provide a block to ensure the response is parseable rather than
|
51
|
+
# having RestClient throw an exception
|
52
|
+
RestClient::Request.execute(options) do |response, request, result|
|
53
|
+
if response and response.code == 200
|
54
|
+
return JSON.parse(response.body)
|
55
|
+
else
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "keystone/v2_0/manager/base"
|
2
|
+
require "keystone/v2_0/resource/endpoint"
|
3
|
+
|
4
|
+
module Keystone
|
5
|
+
module V2_0
|
6
|
+
module Manager
|
7
|
+
class Endpoint < Keystone::V2_0::Manager::Base
|
8
|
+
@@url_endpoint = "endpoints"
|
9
|
+
|
10
|
+
def initialize(auth_url)
|
11
|
+
super auth_url, @@url_endpoint
|
12
|
+
end
|
13
|
+
|
14
|
+
def list
|
15
|
+
endpoints = super
|
16
|
+
endpoint_list = []
|
17
|
+
|
18
|
+
# map role hash to array of Endpoint objects
|
19
|
+
unless endpoints.nil?
|
20
|
+
endpoints["endpoints"].each do |endpoint_data|
|
21
|
+
endpoint_resource = Keystone::V2_0::Resource::Endpoint.new(endpoint_data)
|
22
|
+
endpoint_list << endpoint_resource
|
23
|
+
end
|
24
|
+
|
25
|
+
return endpoint_list
|
26
|
+
else
|
27
|
+
return nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def create(service_id: '', region: '', admin_url: '', internal_url: '', public_url: '', enabled: true)
|
32
|
+
create_key = "endpoint"
|
33
|
+
payload = { create_key =>
|
34
|
+
{ "service_id" => service_id,
|
35
|
+
"region" => region,
|
36
|
+
"adminurl" => admin_url,
|
37
|
+
"internalurl" => internal_url,
|
38
|
+
"publicurl" => public_url,
|
39
|
+
"enabled" => enabled
|
40
|
+
}
|
41
|
+
}
|
42
|
+
endpoint_data = super(payload.to_json)
|
43
|
+
|
44
|
+
if endpoint_data and endpoint_data[create_key]
|
45
|
+
return Keystone::V2_0::Resource::Endpoint.new(endpoint_data[create_key])
|
46
|
+
else
|
47
|
+
return nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "keystone/v2_0/manager/base"
|
2
|
+
require "keystone/v2_0/resource/role"
|
3
|
+
|
4
|
+
module Keystone
|
5
|
+
module V2_0
|
6
|
+
module Manager
|
7
|
+
class Role < Keystone::V2_0::Manager::Base
|
8
|
+
@@url_endpoint = "OS-KSADM/roles"
|
9
|
+
|
10
|
+
def initialize(auth_url)
|
11
|
+
super auth_url, @@url_endpoint
|
12
|
+
end
|
13
|
+
|
14
|
+
def list
|
15
|
+
roles = super
|
16
|
+
role_list = []
|
17
|
+
|
18
|
+
# map role hash to array of Role objects
|
19
|
+
unless roles.nil?
|
20
|
+
roles["roles"].each do |role_data|
|
21
|
+
role_resource = Keystone::V2_0::Resource::Role.new(role_data)
|
22
|
+
role_list << role_resource
|
23
|
+
end
|
24
|
+
|
25
|
+
return role_list
|
26
|
+
else
|
27
|
+
return nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "keystone/v2_0/manager/base"
|
2
|
+
require "keystone/v2_0/resource/service"
|
3
|
+
|
4
|
+
module Keystone
|
5
|
+
module V2_0
|
6
|
+
module Manager
|
7
|
+
class Service < Keystone::V2_0::Manager::Base
|
8
|
+
@@url_endpoint = "OS-KSADM/services"
|
9
|
+
|
10
|
+
def initialize(auth_url)
|
11
|
+
super auth_url, @@url_endpoint
|
12
|
+
end
|
13
|
+
|
14
|
+
def list
|
15
|
+
services = super
|
16
|
+
service_list = []
|
17
|
+
|
18
|
+
# map role hash to array of Service objects
|
19
|
+
unless services.nil?
|
20
|
+
services["OS-KSADM:services"].each do |service_data|
|
21
|
+
service_resource = Keystone::V2_0::Resource::Service.new(service_data)
|
22
|
+
service_list << service_resource
|
23
|
+
end
|
24
|
+
|
25
|
+
return service_list
|
26
|
+
else
|
27
|
+
return nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def create(name: '', type: '', description: '')
|
32
|
+
create_key = "OS-KSADM:service"
|
33
|
+
payload = { create_key =>
|
34
|
+
{ "name" => name,
|
35
|
+
"type" => type,
|
36
|
+
"description" => description
|
37
|
+
}
|
38
|
+
}
|
39
|
+
service_data = super(payload.to_json)
|
40
|
+
|
41
|
+
if service_data and service_data[create_key]
|
42
|
+
return Keystone::V2_0::Resource::Service.new(service_data[create_key])
|
43
|
+
else
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "keystone/v2_0/manager/base"
|
2
|
+
require "keystone/v2_0/resource/tenant"
|
3
|
+
|
4
|
+
module Keystone
|
5
|
+
module V2_0
|
6
|
+
module Manager
|
7
|
+
class Tenant < Keystone::V2_0::Manager::Base
|
8
|
+
@@url_endpoint = "tenants"
|
9
|
+
|
10
|
+
def initialize(auth_url)
|
11
|
+
super auth_url, @@url_endpoint
|
12
|
+
end
|
13
|
+
|
14
|
+
def list
|
15
|
+
tenants = super
|
16
|
+
tenant_list = []
|
17
|
+
|
18
|
+
# map role hash to array of Tenant objects
|
19
|
+
unless tenants.nil?
|
20
|
+
tenants["tenants"].each do |tenant_data|
|
21
|
+
tenant_resource = Keystone::V2_0::Resource::Tenant.new(tenant_data)
|
22
|
+
tenant_list << tenant_resource
|
23
|
+
end
|
24
|
+
|
25
|
+
return tenant_list
|
26
|
+
else
|
27
|
+
return nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "keystone/v2_0/manager/base"
|
2
|
+
require "keystone/v2_0/resource/user"
|
3
|
+
|
4
|
+
module Keystone
|
5
|
+
module V2_0
|
6
|
+
module Manager
|
7
|
+
class User < Keystone::V2_0::Manager::Base
|
8
|
+
@@url_endpoint = "users"
|
9
|
+
|
10
|
+
def initialize(auth_url)
|
11
|
+
super auth_url, @@url_endpoint
|
12
|
+
end
|
13
|
+
|
14
|
+
def list
|
15
|
+
users = super
|
16
|
+
user_list = []
|
17
|
+
|
18
|
+
# map user hash to array of User objects
|
19
|
+
unless users.nil?
|
20
|
+
users["users"].each do |user_data|
|
21
|
+
user_resource = Keystone::V2_0::Resource::User.new(user_data)
|
22
|
+
user_list << user_resource
|
23
|
+
end
|
24
|
+
|
25
|
+
return user_list
|
26
|
+
else
|
27
|
+
return nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Keystone
|
4
|
+
module V2_0
|
5
|
+
module Resource
|
6
|
+
class Base
|
7
|
+
def initialize(data)
|
8
|
+
# dynaically assign attributes based on the
|
9
|
+
# mappings provided by the subclass
|
10
|
+
data.each do |key, val|
|
11
|
+
if self.class.attr_mappings.keys.include?(key)
|
12
|
+
self.send("#{self.class.attr_mappings[key]}=", data[key])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "keystone/v2_0/resource/base"
|
2
|
+
|
3
|
+
module Keystone
|
4
|
+
module V2_0
|
5
|
+
module Resource
|
6
|
+
class Endpoint < Keystone::V2_0::Resource::Base
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :service_id
|
9
|
+
attr_accessor :region
|
10
|
+
attr_accessor :admin_url
|
11
|
+
attr_accessor :internal_url
|
12
|
+
attr_accessor :public_url
|
13
|
+
attr_accessor :enabled
|
14
|
+
|
15
|
+
@@attr_mappings = { "id" => :id,
|
16
|
+
"service_id" => :service_id,
|
17
|
+
"region" => :region,
|
18
|
+
"adminurl" => :admin_url,
|
19
|
+
"internalurl" => :internal_url,
|
20
|
+
"publicurl" => :public_url,
|
21
|
+
"enabled" => :enabled }
|
22
|
+
|
23
|
+
def self.attr_mappings
|
24
|
+
@@attr_mappings
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "keystone/v2_0/resource/base"
|
2
|
+
|
3
|
+
module Keystone
|
4
|
+
module V2_0
|
5
|
+
module Resource
|
6
|
+
class Role < Keystone::V2_0::Resource::Base
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :name
|
9
|
+
attr_accessor :description
|
10
|
+
attr_accessor :enabled
|
11
|
+
|
12
|
+
@@attr_mappings = { "id" => :id,
|
13
|
+
"name" => :name,
|
14
|
+
"description" => :description,
|
15
|
+
"enabled" => :enabled }
|
16
|
+
|
17
|
+
def self.attr_mappings
|
18
|
+
@@attr_mappings
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "keystone/v2_0/resource/base"
|
2
|
+
|
3
|
+
module Keystone
|
4
|
+
module V2_0
|
5
|
+
module Resource
|
6
|
+
class Service < Keystone::V2_0::Resource::Base
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :name
|
9
|
+
attr_accessor :type
|
10
|
+
attr_accessor :description
|
11
|
+
attr_accessor :enabled
|
12
|
+
|
13
|
+
@@attr_mappings = { "id" => :id,
|
14
|
+
"name" => :name,
|
15
|
+
"type" => :type,
|
16
|
+
"description" => :description,
|
17
|
+
"enabled" => :enabled }
|
18
|
+
|
19
|
+
def self.attr_mappings
|
20
|
+
@@attr_mappings
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "keystone/v2_0/resource/base"
|
2
|
+
|
3
|
+
module Keystone
|
4
|
+
module V2_0
|
5
|
+
module Resource
|
6
|
+
class Tenant < Keystone::V2_0::Resource::Base
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :name
|
9
|
+
attr_accessor :description
|
10
|
+
attr_accessor :enabled
|
11
|
+
|
12
|
+
@@attr_mappings = { "id" => :id,
|
13
|
+
"name" => :name,
|
14
|
+
"description" => :description,
|
15
|
+
"enabled" => :enabled }
|
16
|
+
|
17
|
+
def self.attr_mappings
|
18
|
+
@@attr_mappings
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "keystone/v2_0/resource/base"
|
2
|
+
|
3
|
+
module Keystone
|
4
|
+
module V2_0
|
5
|
+
module Resource
|
6
|
+
class User < Keystone::V2_0::Resource::Base
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :username
|
9
|
+
attr_accessor :name
|
10
|
+
attr_accessor :enabled
|
11
|
+
attr_accessor :email
|
12
|
+
|
13
|
+
@@attr_mappings = { "id" => :id,
|
14
|
+
"username" => :username,
|
15
|
+
"name" => :name,
|
16
|
+
"enabled" => :enabled,
|
17
|
+
"email" => :email }
|
18
|
+
|
19
|
+
def self.attr_mappings
|
20
|
+
@@attr_mappings
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|