kaname 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5360e90cd0487acd376fd0fda0ccd08b978baf29
4
- data.tar.gz: 439eb8c715d90cbbe78c6f23fc3e77677b79b796
3
+ metadata.gz: 0ca630516a0934f809e07e87ee98b910496bfa41
4
+ data.tar.gz: a2b681a4c5037491c4270fdf5c859b7f39c5d6e2
5
5
  SHA512:
6
- metadata.gz: 922b9913cceaffb329d381385298e41d8808fe62339be625993c3c46af80cc24b107872ef6e4ce837a3d4eeeebde5e9085bbae7e427bf1ffba70dbe67fff9c60
7
- data.tar.gz: ffe637a4eb3e296091e67a5453253aa92da8c60112525f77923c40591cb28c1860573b63defc619b092307b8e403cb854095d5c4a246e6a879c2ab1424d1372c
6
+ metadata.gz: 48b54645f7fdbb667ddf3d4ddbfee2d601b6d3036e15a0ef28010b5199e4f2bbcfffa38419d35db93301969cba856afbff4e452a3f10a1c2a1f273b5a84cfeed
7
+ data.tar.gz: 95081c6ac8c9a8c5897ca506324dbf4ab5832ac7a4f579133e8703215fda8d523b9127f19de300ce096bf6c9a21a379c16113c1d4c2edf5614644f17646b79cd
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Kaname
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/hsbt/kaname.png)](https://travis-ci.org/hsbt/kaname)
3
+ [![Build Status](https://secure.travis-ci.org/yaocloud/kaname.png)](https://travis-ci.org/yaocloud/kaname)
4
4
 
5
5
  Kaname(要) is configuration management tool of Keystone.
6
6
 
@@ -26,15 +26,15 @@ hsbt:
26
26
  production: "member"
27
27
  ```
28
28
 
29
- You need to put fog configuration to home directory.
29
+ You need to put a configuration file to home directory.
30
30
 
31
31
  ```sh
32
- % cat ~/.fog
33
- default:
34
- openstack_auth_url: "http://your-openstack-endpoint/v2.0/tokens"
35
- openstack_username: "admin"
36
- openstack_tenant: "admin"
37
- openstack_api_key: "admin-no-password"
32
+ % cat ~/.kaname
33
+ auth_url: "http://your-openstack-auth-endpoint/v2.0"
34
+ username: "admin"
35
+ tenant: "admin"
36
+ password: "admin-no-password"
37
+ management_url: "http://your-openstack-management-endpoint/v2.0"
38
38
  ```
39
39
 
40
40
  run following command.
@@ -61,7 +61,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
61
61
 
62
62
  ## Contributing
63
63
 
64
- 1. Fork it ( https://github.com/hsbt/kaname/fork )
64
+ 1. Fork it ( https://github.com/yaocloud/kaname/fork )
65
65
  2. Create your feature branch (`git checkout -b my-new-feature`)
66
66
  3. Commit your changes (`git commit -am 'Add some feature'`)
67
67
  4. Push to the branch (`git push origin my-new-feature`)
data/kaname.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Identity configuration tool for OpenStack.}
13
13
  spec.description = %q{Identity configuration tool for OpenStack. You can apply simple YAML definition into Keystone.}
14
- spec.homepage = "https://github.com/hsbt/kaname"
14
+ spec.homepage = "https://github.com/yaocloud/kaname"
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "fog"
22
+ spec.add_dependency "yao", "~> 0.1.0"
23
23
  spec.add_dependency "diffy"
24
24
  spec.add_dependency "hashdiff"
25
25
  spec.add_dependency "thor"
data/lib/kaname.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "kaname/version"
2
2
 
3
+ require 'kaname/config'
4
+
3
5
  require 'kaname/adapter'
4
6
  require 'kaname/cli'
5
7
  require 'kaname/generator'
@@ -7,3 +9,5 @@ require 'kaname/resource'
7
9
 
8
10
  module Kaname
9
11
  end
12
+
13
+ Kaname::Config.setup unless ENV['RACK_ENV'] == 'test'
@@ -5,37 +5,43 @@ module Kaname
5
5
  module Adapter
6
6
  class Real
7
7
  def find_user(name)
8
- user = Kaname::Resource.users.find_by_name(name)
8
+ user = Yao::User.find_by_name(name)
9
9
  {"id" => user.id, "name" => user.name}
10
10
  end
11
11
 
12
12
  def create_user(name, email)
13
13
  password = Kaname::Generator.password
14
14
  puts "#{name},#{password}"
15
- response = Fog::Identity[:openstack].create_user(name, password, email)
16
- response.data[:body]["user"]
15
+
16
+ user = Yao::User.create(name: name, email: email, password: password)
17
+ {"id" => user.id, "name" => user.name}
17
18
  end
18
19
 
19
20
  def create_user_role(tenant_name, user_hash, role_name)
20
- tenant = Kaname::Resource.tenants.find{|t| t.name == tenant_name}
21
- role = Kaname::Resource.roles.find{|r| r.name == role_name}
22
- Fog::Identity[:openstack].create_user_role(tenant.id, user_hash["id"], role.id)
21
+ Yao::Role.grant(role_name, to: user_hash["name"], on: tenant_name)
23
22
  end
24
23
 
25
- def update_user_password(credentials, old_password, new_password)
24
+ def update_user_password(old_password, new_password)
25
+ unless Kaname::Config.management_url
26
+ raise 'management_url is missing. Check the configuration file.'
27
+ end
28
+
26
29
  if old_password && new_password
27
- # TODO: need to confirm port number of endpoint
28
- endpoint = "http://#{URI(credentials[:openstack_management_url]).hostname}:5000/v2.0"
29
- url = URI.parse("#{endpoint}/OS-KSCRUD/users/#{credentials[:openstack_current_user_id]}")
30
+ token = Yao::Auth.try_new.token
31
+ me = Yao::User.get_by_name(Kaname::Config.username)
32
+ endpoint = Kaname::Config.management_url
33
+
34
+ url = URI.parse("#{endpoint}/OS-KSCRUD/users/#{me.id}")
35
+
30
36
  req = Net::HTTP::Patch.new(url.path)
31
37
  req["Content-type"] = "application/json"
32
- req["X-Auth-Token"] = credentials[:openstack_auth_token]
38
+ req["X-Auth-Token"] = token
33
39
  req.body = JSON.generate({'user' => {'password' => new_password, 'original_password' => old_password}})
34
- res = Net::HTTP.start(url.host, url.port) {|http|
35
- http.request(req)
36
- }
40
+
41
+ res = Net::HTTP.start(url.host, url.port) {|http| http.request(req) }
42
+
37
43
  if res.code == "200"
38
- puts "Your password is updated. Please update your ~/.fog configuration too."
44
+ puts "Your password is updated. Please update your ~/.kaname configuration too."
39
45
  else
40
46
  raise "password updating is failed"
41
47
  end
@@ -43,14 +49,11 @@ module Kaname
43
49
  end
44
50
 
45
51
  def delete_user(name)
46
- user = find_user(name)
47
- Fog::Identity[:openstack].delete_user(user["id"])
52
+ Yao::User.destroy find_user(name)["id"]
48
53
  end
49
54
 
50
55
  def delete_user_role(tenant_name, user_hash, role_name)
51
- tenant = Kaname::Resource.tenants.find{|t| t.name == tenant_name}
52
- role = Kaname::Resource.roles.find{|r| r.name == role_name}
53
- Fog::Identity[:openstack].delete_user_role(tenant.id, user_hash["id"], role.id)
56
+ Yao::Role.revoke(role_name, from: user_hash["name"], on: tenant_name)
54
57
  end
55
58
 
56
59
  def change_user_role(tenant_name, user_hash, before_role_name, after_role_name)
data/lib/kaname/cli.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'yaml'
2
- require 'fog'
3
2
  require 'thor'
4
3
  require 'hashdiff'
5
4
  require 'diffy'
@@ -8,8 +7,7 @@ module Kaname
8
7
  class CLI < Thor
9
8
  desc 'password', 'Commands about updating user password'
10
9
  def password
11
- credentials = Fog::Identity[:openstack].credentials
12
- puts "current_user: #{credentials[:current_user]["username"]}"
10
+ puts "current_user: #{Kaname::Config.username}"
13
11
 
14
12
  print "type your current password: "
15
13
  old_password = STDIN.noecho(&:gets).strip
@@ -18,7 +16,7 @@ module Kaname
18
16
  new_password = STDIN.noecho(&:gets).strip
19
17
  puts
20
18
 
21
- Kaname::Adapter::Real.new.update_user_password(credentials, old_password, new_password)
19
+ Kaname::Adapter::Real.new.update_user_password(old_password, new_password)
22
20
  end
23
21
 
24
22
  option :dryrun, type: :boolean
@@ -0,0 +1,48 @@
1
+ require 'yao'
2
+ require 'yaml'
3
+
4
+ module Kaname
5
+ class Config
6
+ def self.setup
7
+ load_config
8
+ setup_yao
9
+ end
10
+
11
+ def self.username
12
+ @@username
13
+ end
14
+
15
+ def self.management_url
16
+ @@management_url
17
+ end
18
+
19
+ private
20
+
21
+ def self.load_config
22
+ config_file = File.join(Dir.home, '.kaname')
23
+ raise '~/.kaname is missing' unless File.exists?(config_file)
24
+
25
+ config = YAML.load_file(config_file)
26
+
27
+ %w[auth_url tenant username password].each do |conf_item|
28
+ raise "Configuration '#{conf_item}' is missing. Check your ~/.kaname" unless config[conf_item]
29
+ end
30
+
31
+ @@auth_url = config['auth_url']
32
+ @@tenant = config['tenant']
33
+ @@username = config['username']
34
+ @@password = config['password']
35
+ @@management_url = config['management_url']
36
+ true
37
+ end
38
+
39
+ def self.setup_yao
40
+ Yao.configure do
41
+ auth_url @@auth_url
42
+ tenant_name @@tenant
43
+ username @@username
44
+ password @@password
45
+ end
46
+ end
47
+ end
48
+ end
@@ -12,15 +12,15 @@ module Kaname
12
12
  end
13
13
 
14
14
  def users
15
- @_users ||= Fog::Identity[:openstack].users
15
+ @_users ||= Yao::User.list
16
16
  end
17
17
 
18
18
  def tenants
19
- @_tenants ||= Fog::Identity[:openstack].tenants
19
+ @_tenants ||= Yao::Tenant.list
20
20
  end
21
21
 
22
22
  def roles
23
- @_roles ||= Fog::Identity[:openstack].roles
23
+ @_roles ||= Yao::Role.list
24
24
  end
25
25
 
26
26
  def users_hash
@@ -33,9 +33,9 @@ module Kaname
33
33
  @h[u.name]["email"] = u.email
34
34
  @h[u.name]["tenants"] = {}
35
35
  tenants.each do |t|
36
- r = u.roles(t.id)
36
+ r = Yao::Role.list_for_user(u.name, on: t.name)
37
37
  if r.size > 0
38
- @h[u.name]["tenants"][t.name] = r.first["name"]
38
+ @h[u.name]["tenants"][t.name] = r.first.name
39
39
  end
40
40
  end
41
41
  end
@@ -1,3 +1,3 @@
1
1
  module Kaname
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaname
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - SHIBATA Hiroshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-19 00:00:00.000000000 Z
11
+ date: 2015-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: fog
14
+ name: yao
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: diffy
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -160,10 +160,11 @@ files:
160
160
  - lib/kaname/adapter/mock.rb
161
161
  - lib/kaname/adapter/real.rb
162
162
  - lib/kaname/cli.rb
163
+ - lib/kaname/config.rb
163
164
  - lib/kaname/generator.rb
164
165
  - lib/kaname/resource.rb
165
166
  - lib/kaname/version.rb
166
- homepage: https://github.com/hsbt/kaname
167
+ homepage: https://github.com/yaocloud/kaname
167
168
  licenses:
168
169
  - MIT
169
170
  metadata: {}
@@ -183,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
184
  version: '0'
184
185
  requirements: []
185
186
  rubyforge_project:
186
- rubygems_version: 2.2.3
187
+ rubygems_version: 2.5.0
187
188
  signing_key:
188
189
  specification_version: 4
189
190
  summary: Identity configuration tool for OpenStack.