conjur-api 2.1.1 → 2.1.2

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.
@@ -1,5 +1,5 @@
1
1
  module Conjur
2
2
  class API
3
- VERSION = "2.1.1"
3
+ VERSION = "2.1.2"
4
4
  end
5
5
  end
@@ -1,8 +1,12 @@
1
1
  module Conjur
2
2
  module ActsAsRole
3
+ def roleid
4
+ self.attributes['roleid'] or raise "roleid attribute not found"
5
+ end
6
+
3
7
  def role
4
8
  require 'conjur/role'
5
- Conjur::Role.new("#{Conjur::Authz::API.host}/roles/#{path_escape roleid}", self.options)
9
+ Conjur::Role.new(Conjur::Authz::API.host, self.options)[Conjur::API.parse_role_id(self.roleid).join('/')]
6
10
  end
7
11
  end
8
12
  end
@@ -2,6 +2,14 @@ require 'conjur/group'
2
2
 
3
3
  module Conjur
4
4
  class API
5
+ def groups
6
+ JSON.parse(RestClient::Resource.new(Conjur::Core::API.host, credentials)['groups'].get).collect do |json|
7
+ # TODO: remove this hack
8
+ json = JSON.parse json['json']
9
+ group(json['id'])
10
+ end
11
+ end
12
+
5
13
  def create_group(id, options = {})
6
14
  standard_create Conjur::Core::API.host, :group, id, options
7
15
  end
data/lib/conjur/base.rb CHANGED
@@ -20,6 +20,7 @@ module Conjur
20
20
  # Parse a role id into [ account, 'roles', kind, id ]
21
21
  def parse_role_id(id)
22
22
  paths = path_escape(id).split(':')
23
+ raise "Expecting account:kind:id in role #{id}" unless paths.size >= 3
23
24
  [ paths[0], 'roles', paths[1], paths[2..-1].join(':') ]
24
25
  end
25
26
 
data/lib/conjur/group.rb CHANGED
@@ -4,9 +4,5 @@ module Conjur
4
4
  include ActsAsRole
5
5
  include HasId
6
6
  include HasAttributes
7
-
8
- def roleid
9
- "group:#{id}"
10
- end
11
7
  end
12
8
  end
data/lib/conjur/host.rb CHANGED
@@ -6,10 +6,6 @@ module Conjur
6
6
  include HasAttributes
7
7
  include ActsAsUser
8
8
 
9
- def roleid
10
- "host:#{id}"
11
- end
12
-
13
9
  def enrollment_url
14
10
  log do |logger|
15
11
  logger << "Fetching enrollment_url for #{id}"
data/lib/conjur/role.rb CHANGED
@@ -9,6 +9,10 @@ module Conjur
9
9
 
10
10
  alias id identifier
11
11
 
12
+ def roleid
13
+ [ account, kind, identifier ].join(':')
14
+ end
15
+
12
16
  def create(options = {})
13
17
  log do |logger|
14
18
  logger << "Creating role #{kind}:#{identifier}"
@@ -21,6 +25,7 @@ module Conjur
21
25
 
22
26
  def all(options = {})
23
27
  JSON.parse(self["?all"].get(options)).collect do |id|
28
+ id = [ id['account'], id['id'] ].join(':')
24
29
  Role.new(Conjur::Authz::API.host, self.options)[Conjur::API.parse_role_id(id).join('/')]
25
30
  end
26
31
  end
data/lib/conjur/user.rb CHANGED
@@ -9,9 +9,5 @@ module Conjur
9
9
  include ActsAsUser
10
10
 
11
11
  alias login id
12
-
13
- def roleid
14
- [ 'user', id ].join(':')
15
- end
16
12
  end
17
13
  end
data/spec/lib/api_spec.rb CHANGED
@@ -61,7 +61,7 @@ describe Conjur::API do
61
61
  it_should_behave_like "API endpoint"
62
62
  end
63
63
  context "of core service" do
64
- let(:port_offset) { 300 }
64
+ let(:port_offset) { 200 }
65
65
  let(:api) { Conjur::Core::API }
66
66
  it_should_behave_like "API endpoint"
67
67
  end
@@ -12,10 +12,12 @@ describe Conjur::User do
12
12
  subject { user }
13
13
  its(:id) { should == login }
14
14
  its(:login) { should == login }
15
- its(:roleid) { should == ["user", login].join(':') }
16
15
  its(:resource_id) { should == login }
17
16
  its(:resource_kind) { should == "user" }
18
17
  its(:options) { should == credentials }
18
+ specify {
19
+ lambda { user.roleid }.should raise_error
20
+ }
19
21
  end
20
22
  before {
21
23
  Conjur.stub(:account).and_return 'ci'
@@ -28,8 +30,11 @@ describe Conjur::User do
28
30
  user.resource
29
31
  end
30
32
  it "connects to a Role" do
33
+ user.stub(:roleid).and_return "ci:user:the-login"
34
+
31
35
  require 'conjur/role'
32
- Conjur::Role.should_receive(:new).with("#{Conjur::Authz::API.host}/roles/#{user.roleid}", credentials)
36
+ Conjur::Role.should_receive(:new).with(Conjur::Authz::API.host, credentials).and_return role = double(:role)
37
+ role.should_receive(:[]).with("ci/roles/user/the-login")
33
38
 
34
39
  user.role
35
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conjur-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-29 00:00:00.000000000 Z
13
+ date: 2013-04-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -204,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
204
  version: '0'
205
205
  segments:
206
206
  - 0
207
- hash: 4047181916872803185
207
+ hash: -423708281748873360
208
208
  required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  none: false
210
210
  requirements:
@@ -213,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  version: '0'
214
214
  segments:
215
215
  - 0
216
- hash: 4047181916872803185
216
+ hash: -423708281748873360
217
217
  requirements: []
218
218
  rubyforge_project:
219
219
  rubygems_version: 1.8.24