ridley 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/ridley/chef_objects/user_object.rb +57 -0
- data/lib/ridley/client.rb +6 -0
- data/lib/ridley/resources/user_resource.rb +36 -0
- data/lib/ridley/version.rb +1 -1
- data/spec/acceptance/user_resource_spec.rb +130 -0
- data/spec/support/chef_server.rb +4 -0
- data/spec/unit/ridley/resources/user_resource_spec.rb +33 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7da3aeb7959de4937cc94f7ca1f72214816ed75
|
4
|
+
data.tar.gz: e103b754e4768cf2a704104978da665fcccf27f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52b2039fca91e517019c01472e0bd8679a33427c964f7508989d77f19ca60037e5a5a68ceb75a6089f7997c5812c83516139cea71f6c0c68006b65ef8642c223
|
7
|
+
data.tar.gz: d550361f34542efa082c38ff3c8abd71aca4d0ee59a4427f640e49e3a9405db7fadf8b56b6e7fa8903ccb160406391114206ddd25c0836f9cfd636350fd7f6b6
|
data/README.md
CHANGED
@@ -134,6 +134,7 @@ ridley.node #=> Ridley::NodeResource
|
|
134
134
|
ridley.role #=> Ridley::RoleResource
|
135
135
|
ridley.sandbox #=> Ridley::SandboxResource
|
136
136
|
ridley.search #=> Ridley::SearchResource
|
137
|
+
ridley.user #=> Ridley::UserResource
|
137
138
|
```
|
138
139
|
|
139
140
|
DataBagItems are the only exception to this rule. The DataBagItem resource is accessed from a DataBagObject
|
@@ -377,6 +378,21 @@ Search will return an array of the appropriate Chef Objects if one of the defaul
|
|
377
378
|
- client
|
378
379
|
- environment
|
379
380
|
|
381
|
+
User Resource
|
382
|
+
-------------
|
383
|
+
|
384
|
+
### Regenerating a user's private key
|
385
|
+
|
386
|
+
Works the same way as with a client resource.
|
387
|
+
|
388
|
+
### Authenticating user's password
|
389
|
+
|
390
|
+
```ruby
|
391
|
+
ridley = Ridley.new(...)
|
392
|
+
ridley.user.authenticate('username', 'password')
|
393
|
+
ridley.user.find('username').authenticate('password')
|
394
|
+
```
|
395
|
+
|
380
396
|
Authors and Contributors
|
381
397
|
------------------------
|
382
398
|
- Jamie Winsor (<jamie@vialstudios.com>)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Ridley
|
2
|
+
class UserObject < Ridley::ChefObject
|
3
|
+
set_chef_id "name"
|
4
|
+
set_chef_type "user"
|
5
|
+
set_chef_json_class "Chef::User"
|
6
|
+
|
7
|
+
attribute :name,
|
8
|
+
type: String,
|
9
|
+
required: true
|
10
|
+
|
11
|
+
attribute :admin,
|
12
|
+
type: Boolean,
|
13
|
+
required: true,
|
14
|
+
default: false
|
15
|
+
|
16
|
+
attribute :certificate,
|
17
|
+
type: String
|
18
|
+
|
19
|
+
attribute :public_key,
|
20
|
+
type: String
|
21
|
+
|
22
|
+
attribute :private_key,
|
23
|
+
type: [ String, Boolean ],
|
24
|
+
default: false
|
25
|
+
|
26
|
+
attribute :password,
|
27
|
+
type: String
|
28
|
+
|
29
|
+
attribute :orgname,
|
30
|
+
type: String
|
31
|
+
|
32
|
+
# Regenerates the private key of the instantiated user object. The new
|
33
|
+
# private key will be set to the value of the 'private_key' accessor
|
34
|
+
# of the instantiated user object.
|
35
|
+
#
|
36
|
+
# @return [Boolean]
|
37
|
+
# true for success and false for failure
|
38
|
+
def regenerate_key
|
39
|
+
self.private_key = true
|
40
|
+
self.save
|
41
|
+
end
|
42
|
+
|
43
|
+
def authenticate(password)
|
44
|
+
@resource.authenticate(self.chef_id, password)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Override to_json to reflect to massage the returned attributes based on the type
|
48
|
+
# of connection. Only OHC/OPC requires the json_class attribute is not present.
|
49
|
+
def to_json
|
50
|
+
if resource.connection.hosted?
|
51
|
+
to_hash.except(:json_class).to_json
|
52
|
+
else
|
53
|
+
super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/ridley/client.rb
CHANGED
@@ -26,6 +26,7 @@ module Ridley
|
|
26
26
|
supervise_as :sandbox_resource, Ridley::SandboxResource, connection_registry,
|
27
27
|
options[:client_name], options[:client_key], options.slice(*Ridley::Connection::VALID_OPTIONS)
|
28
28
|
supervise_as :search_resource, Ridley::SearchResource, connection_registry
|
29
|
+
supervise_as :user_resource, Ridley::UserResource, connection_registry
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
@@ -181,6 +182,11 @@ module Ridley
|
|
181
182
|
@resources_registry[:sandbox_resource]
|
182
183
|
end
|
183
184
|
|
185
|
+
# @return [Ridley::UserResource]
|
186
|
+
def user
|
187
|
+
@resources_registry[:user_resource]
|
188
|
+
end
|
189
|
+
|
184
190
|
# Perform a search the Chef Server
|
185
191
|
#
|
186
192
|
# @param [#to_sym, #to_s] index
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Ridley
|
2
|
+
# @example listing all users
|
3
|
+
# conn = Ridley.new(...)
|
4
|
+
# conn.user.all #=> [
|
5
|
+
# #<Ridley::ClientObject chef_id:'admin'>
|
6
|
+
# ]
|
7
|
+
class UserResource < Ridley::Resource
|
8
|
+
set_resource_path "users"
|
9
|
+
represented_by Ridley::UserObject
|
10
|
+
|
11
|
+
# Retrieves a user from the remote connection matching the given chef_id
|
12
|
+
# and regenerates it's private key. An instance of the updated object will
|
13
|
+
# be returned and have a value set for the 'private_key' accessor.
|
14
|
+
#
|
15
|
+
# @param [String, #chef_id] chef_user
|
16
|
+
#
|
17
|
+
# @raise [Errors::ResourceNotFound]
|
18
|
+
# if a user with the given chef_id is not found
|
19
|
+
#
|
20
|
+
# @return [Ridley::UserObject]
|
21
|
+
def regenerate_key(chef_user)
|
22
|
+
unless chef_user = find(chef_user)
|
23
|
+
abort Errors::ResourceNotFound.new("user '#{chef_user}' not found")
|
24
|
+
end
|
25
|
+
|
26
|
+
chef_user.private_key = true
|
27
|
+
update(chef_user)
|
28
|
+
end
|
29
|
+
|
30
|
+
def authenticate(username, password)
|
31
|
+
resp = request(:post, '/authenticate_user', {'name' => username, 'password' => password}.to_json)
|
32
|
+
abort("Username mismatch: sent #{username}, received #{resp['name']}") unless resp['name'] == username
|
33
|
+
resp['verified']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/ridley/version.rb
CHANGED
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "User API operations", type: "wip" do
|
4
|
+
let(:server_url) { Ridley::RSpec::ChefServer.server_url }
|
5
|
+
let(:user_name) { "reset" }
|
6
|
+
let(:user_key) { fixtures_path.join('reset.pem').to_s }
|
7
|
+
let(:connection) { Ridley.new(server_url: server_url, client_name: user_name, client_key: user_key) }
|
8
|
+
|
9
|
+
describe "finding a user" do
|
10
|
+
context "when the server has a user of the given name" do
|
11
|
+
before { chef_user("reset", admin: false) }
|
12
|
+
|
13
|
+
it "returns a UserObject" do
|
14
|
+
connection.user.find("reset").should be_a(Ridley::UserObject)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when the server does not have the user" do
|
19
|
+
it "returns a nil value" do
|
20
|
+
connection.user.find("not_there").should be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "creating a user" do
|
26
|
+
it "returns a Ridley::UserObject" do
|
27
|
+
connection.user.create(name: "reset").should be_a(Ridley::UserObject)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "adds a user to the chef server" do
|
31
|
+
old = connection.user.all.length
|
32
|
+
connection.user.create(name: "reset")
|
33
|
+
connection.user.all.should have(old + 1).items
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has a value for #private_key" do
|
37
|
+
connection.user.create(name: "reset").private_key.should_not be_nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "deleting a user" do
|
42
|
+
before { chef_user("reset", admin: false) }
|
43
|
+
|
44
|
+
it "returns a Ridley::UserObject object" do
|
45
|
+
connection.user.delete("reset").should be_a(Ridley::UserObject)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "removes the user from the server" do
|
49
|
+
connection.user.delete("reset")
|
50
|
+
|
51
|
+
connection.user.find("reset").should be_nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "deleting all users" do
|
56
|
+
before(:each) do
|
57
|
+
chef_user("reset", admin: false)
|
58
|
+
chef_user("jwinsor", admin: false)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns an array of Ridley::UserObject objects" do
|
62
|
+
connection.user.delete_all.should each be_a(Ridley::UserObject)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "deletes all users from the remote" do
|
66
|
+
connection.user.delete_all
|
67
|
+
connection.user.all.should have(0).users
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "listing all users" do
|
72
|
+
before(:each) do
|
73
|
+
chef_user("reset", admin: false)
|
74
|
+
chef_user("jwinsor", admin: false)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns an array of Ridley::UserObject objects" do
|
78
|
+
connection.user.all.should each be_a(Ridley::UserObject)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "returns all of the users on the server" do
|
82
|
+
connection.user.all.should have(3).items
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "regenerating a user's private key" do
|
87
|
+
before { chef_user("reset", admin: false) }
|
88
|
+
|
89
|
+
it "returns a Ridley::UserObject object with a value for #private_key" do
|
90
|
+
connection.user.regenerate_key("reset").private_key.should match(/^-----BEGIN RSA PRIVATE KEY-----/)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "authenticating a user" do
|
95
|
+
before { chef_user('reset', password: 'swordfish') }
|
96
|
+
|
97
|
+
it "returns true when given valid username & password" do
|
98
|
+
expect(connection.user.authenticate('reset', 'swordfish')).to be_true
|
99
|
+
end
|
100
|
+
|
101
|
+
it "returns false when given valid username & invalid password" do
|
102
|
+
expect(connection.user.authenticate('reset', "not a swordfish")).to be_false
|
103
|
+
end
|
104
|
+
|
105
|
+
it "returns false when given invalid username & valid password" do
|
106
|
+
expect(connection.user.authenticate("someone-else", 'swordfish')).to be_false
|
107
|
+
end
|
108
|
+
|
109
|
+
it "works also on a User object level" do
|
110
|
+
expect(connection.user.find('reset').authenticate('swordfish')).to be_true
|
111
|
+
expect(connection.user.find('reset').authenticate('not a swordfish')).to be_false
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "changing user's password" do
|
116
|
+
before { chef_user('reset', password: 'swordfish') }
|
117
|
+
subject { connection.user.find('reset') }
|
118
|
+
|
119
|
+
it "changes the password with which user can authenticate" do
|
120
|
+
expect(subject.authenticate('swordfish')).to be_true
|
121
|
+
expect(subject.authenticate('salmon')).to be_false
|
122
|
+
|
123
|
+
subject.password = 'salmon'
|
124
|
+
subject.save
|
125
|
+
|
126
|
+
expect(subject.authenticate('swordfish')).to be_false
|
127
|
+
expect(subject.authenticate('salmon')).to be_true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
data/spec/support/chef_server.rb
CHANGED
@@ -69,6 +69,10 @@ module Ridley::RSpec
|
|
69
69
|
load_data(:roles, name, hash)
|
70
70
|
end
|
71
71
|
|
72
|
+
def chef_user(name, hash = Hash.new)
|
73
|
+
load_data(:users, name, hash)
|
74
|
+
end
|
75
|
+
|
72
76
|
def chef_zero_connection
|
73
77
|
Ridley::Connection.new(ChefServer.server_url, "reset", fixtures_path.join('reset.pem').to_s)
|
74
78
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ridley::UserResource, type: 'wip' do
|
4
|
+
subject { described_class.new(double('registry')) }
|
5
|
+
let(:user_id) { "rspec-user" }
|
6
|
+
let(:user_password) { "swordfish" }
|
7
|
+
|
8
|
+
describe "#regenerate_key" do
|
9
|
+
before { subject.stub(find: nil) }
|
10
|
+
|
11
|
+
context "when a user with the given ID exists" do
|
12
|
+
let(:user) { double('chef-user') }
|
13
|
+
before { subject.should_receive(:find).with(user_id).and_return(user) }
|
14
|
+
|
15
|
+
it "sets the private key to true and updates the user" do
|
16
|
+
user.should_receive(:private_key=).with(true)
|
17
|
+
subject.should_receive(:update).with(user)
|
18
|
+
|
19
|
+
subject.regenerate_key(user_id)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when a user with the given ID does not exist" do
|
24
|
+
before { subject.should_receive(:find).with(user_id).and_return(nil) }
|
25
|
+
|
26
|
+
it "raises a ResourceNotFound error" do
|
27
|
+
expect {
|
28
|
+
subject.regenerate_key(user_id)
|
29
|
+
}.to raise_error(Ridley::Errors::ResourceNotFound)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ridley
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Winsor
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -289,6 +289,7 @@ files:
|
|
289
289
|
- lib/ridley/chef_objects/node_object.rb
|
290
290
|
- lib/ridley/chef_objects/role_object.rb
|
291
291
|
- lib/ridley/chef_objects/sandbox_object.rb
|
292
|
+
- lib/ridley/chef_objects/user_object.rb
|
292
293
|
- lib/ridley/client.rb
|
293
294
|
- lib/ridley/command_context.rb
|
294
295
|
- lib/ridley/command_context/unix_uninstall.rb
|
@@ -319,6 +320,7 @@ files:
|
|
319
320
|
- lib/ridley/resources/role_resource.rb
|
320
321
|
- lib/ridley/resources/sandbox_resource.rb
|
321
322
|
- lib/ridley/resources/search_resource.rb
|
323
|
+
- lib/ridley/resources/user_resource.rb
|
322
324
|
- lib/ridley/sandbox_uploader.rb
|
323
325
|
- lib/ridley/version.rb
|
324
326
|
- ridley.gemspec
|
@@ -333,6 +335,7 @@ files:
|
|
333
335
|
- spec/acceptance/role_resource_spec.rb
|
334
336
|
- spec/acceptance/sandbox_resource_spec.rb
|
335
337
|
- spec/acceptance/search_resource_spec.rb
|
338
|
+
- spec/acceptance/user_resource_spec.rb
|
336
339
|
- spec/fixtures/chefignore
|
337
340
|
- spec/fixtures/encrypted_data_bag_secret
|
338
341
|
- spec/fixtures/example_cookbook/Guardfile
|
@@ -394,6 +397,7 @@ files:
|
|
394
397
|
- spec/unit/ridley/resources/role_resource_spec.rb
|
395
398
|
- spec/unit/ridley/resources/sandbox_resource_spec.rb
|
396
399
|
- spec/unit/ridley/resources/search_resource_spec.rb
|
400
|
+
- spec/unit/ridley/resources/user_resource_spec.rb
|
397
401
|
- spec/unit/ridley/sandbox_uploader_spec.rb
|
398
402
|
- spec/unit/ridley_spec.rb
|
399
403
|
homepage: https://github.com/RiotGames/ridley
|
@@ -430,6 +434,7 @@ test_files:
|
|
430
434
|
- spec/acceptance/role_resource_spec.rb
|
431
435
|
- spec/acceptance/sandbox_resource_spec.rb
|
432
436
|
- spec/acceptance/search_resource_spec.rb
|
437
|
+
- spec/acceptance/user_resource_spec.rb
|
433
438
|
- spec/fixtures/chefignore
|
434
439
|
- spec/fixtures/encrypted_data_bag_secret
|
435
440
|
- spec/fixtures/example_cookbook/Guardfile
|
@@ -491,6 +496,7 @@ test_files:
|
|
491
496
|
- spec/unit/ridley/resources/role_resource_spec.rb
|
492
497
|
- spec/unit/ridley/resources/sandbox_resource_spec.rb
|
493
498
|
- spec/unit/ridley/resources/search_resource_spec.rb
|
499
|
+
- spec/unit/ridley/resources/user_resource_spec.rb
|
494
500
|
- spec/unit/ridley/sandbox_uploader_spec.rb
|
495
501
|
- spec/unit/ridley_spec.rb
|
496
502
|
has_rdoc:
|