conjur-api 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Conjur
2
2
  class API
3
- VERSION = "2.2.1"
3
+ VERSION = "2.2.2"
4
4
  end
5
5
  end
data/lib/conjur/base.rb CHANGED
@@ -20,15 +20,26 @@ module Conjur
20
20
  class << self
21
21
  # Parse a role id into [ account, 'roles', kind, id ]
22
22
  def parse_role_id(id)
23
+ parse_id id, 'roles'
24
+ end
25
+
26
+ # Parse a resource id into [ account, 'resources', kind, id ]
27
+ def parse_resource_id(id)
28
+ parse_id id, 'resources'
29
+ end
30
+
31
+ def parse_id(id, kind)
23
32
  if id.is_a?(Hash)
24
33
  tokens = id['id'].split(':')
25
- [ id['account'], 'roles', tokens[0], tokens[1..-1].join(':') ]
34
+ [ id['account'], kind, tokens[0], tokens[1..-1].join(':') ]
26
35
  elsif id.is_a?(String)
27
36
  paths = path_escape(id).split(':')
28
- if paths.size == 2
37
+ if paths.size < 2
38
+ raise "Expecting at least two tokens in #{id}"
39
+ elsif paths.size == 2
29
40
  paths.unshift Conjur::Core::API.conjur_account
30
41
  end
31
- [ paths[0], 'roles', paths[1], paths[2..-1].join(':') ]
42
+ [ paths[0], kind, paths[1], paths[2..-1].join(':') ]
32
43
  else
33
44
  raise "Unexpected class #{id.class} for #{id}"
34
45
  end
data/lib/conjur/exists.rb CHANGED
@@ -4,6 +4,12 @@ module Conjur
4
4
  begin
5
5
  self.head(options)
6
6
  true
7
+ rescue RestClient::Forbidden
8
+ # rationale is: exists? should return true iff creating a resource with
9
+ # the same name would fail (not by client's fault). Why it would fail
10
+ # doesn't matter that much.
11
+ # (Plus, currently it always 403s when the resource exists but is unaccessible.)
12
+ true
7
13
  rescue RestClient::ResourceNotFound
8
14
  false
9
15
  end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conjur::Exists do
4
+ subject { Object.new.tap {|o| o.send :extend, Conjur::Exists } }
5
+
6
+ context "when head returns 200" do
7
+ before { subject.stub head: "" }
8
+ its(:exists?) { should be_true }
9
+ end
10
+
11
+ context "when forbidden" do
12
+ before { subject.stub(:head) { raise RestClient::Forbidden }}
13
+ its(:exists?) { should be_true }
14
+ end
15
+
16
+ context "when not found" do
17
+ before { subject.stub(:head) { raise RestClient::ResourceNotFound }}
18
+ its(:exists?) { should be_false }
19
+ end
20
+ 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.2.1
4
+ version: 2.2.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-05-20 00:00:00.000000000 Z
13
+ date: 2013-05-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -186,6 +186,7 @@ files:
186
186
  - lib/conjur/user.rb
187
187
  - lib/conjur/variable.rb
188
188
  - spec/lib/api_spec.rb
189
+ - spec/lib/exists_spec.rb
189
190
  - spec/lib/host_spec.rb
190
191
  - spec/lib/resource_spec.rb
191
192
  - spec/lib/role_spec.rb
@@ -208,7 +209,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
209
  version: '0'
209
210
  segments:
210
211
  - 0
211
- hash: 2312433878886306886
212
+ hash: -2465680462875231923
212
213
  required_rubygems_version: !ruby/object:Gem::Requirement
213
214
  none: false
214
215
  requirements:
@@ -217,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
218
  version: '0'
218
219
  segments:
219
220
  - 0
220
- hash: 2312433878886306886
221
+ hash: -2465680462875231923
221
222
  requirements: []
222
223
  rubyforge_project:
223
224
  rubygems_version: 1.8.24
@@ -230,6 +231,7 @@ test_files:
230
231
  - features/ping_as_server.feature
231
232
  - features/ping_as_user.feature
232
233
  - spec/lib/api_spec.rb
234
+ - spec/lib/exists_spec.rb
233
235
  - spec/lib/host_spec.rb
234
236
  - spec/lib/resource_spec.rb
235
237
  - spec/lib/role_spec.rb