conjur-api 2.2.3 → 2.3.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.
data/lib/conjur/api.rb CHANGED
@@ -12,6 +12,7 @@ require 'conjur/acts_as_asset'
12
12
  require 'conjur/authn-api'
13
13
  require 'conjur/authz-api'
14
14
  require 'conjur/core-api'
15
+ require 'conjur-api/version'
15
16
 
16
17
  class RestClient::Resource
17
18
  include Conjur::Escape
data/lib/conjur/role.rb CHANGED
@@ -32,17 +32,30 @@ module Conjur
32
32
  end
33
33
  end
34
34
 
35
- def grant_to(member, admin_option = false, options = {})
35
+ def grant_to(member, *args)
36
+ if Conjur::API::VERSION < "3.0.0"
37
+ options = args[-1]
38
+ if args.length > 1
39
+ warning = "WARNING: Deprecated arguments to grant_to. Please put admin_option in the options hash."
40
+ options[:admin_option] = args[0]
41
+ end
42
+
43
+ unless options.nil? || options.is_a?(Hash)
44
+ warning = "WARNING: Deprecated arguments to grant_to. Please put admin_option in the options hash."
45
+ options = { admin_option: options }
46
+ end
47
+ else
48
+ raise "Please remove the deprecated API in 3.0 and change the method signature to grant_to(member, options)"
49
+ end
50
+
36
51
  log do |logger|
52
+ logger << warning if warning
37
53
  logger << "Granting role #{identifier} to #{member}"
38
- if admin_option
39
- logger << " with admin option"
40
- end
41
- unless options.empty?
42
- logger << " and extended options #{options.to_json}"
54
+ unless options.blank?
55
+ logger << " with options #{options.to_json}"
43
56
  end
44
57
  end
45
- self["?members&member=#{query_escape member}&admin_option=#{query_escape admin_option}"].put(options)
58
+ self["?members&member=#{query_escape member}"].put(options)
46
59
  end
47
60
 
48
61
  def revoke_from(member, options = {})
@@ -1,5 +1,6 @@
1
1
  module Conjur
2
2
  class API
3
- VERSION = "2.2.3"
3
+ VERSION = "2.3.1"
4
+ # Note: when bumping major version, please remove compatibility code in role#grant_to
4
5
  end
5
6
  end
@@ -1,27 +1,57 @@
1
1
  require 'spec_helper'
2
2
 
3
- shared_examples_for "properties" do
4
- subject { role }
5
- its(:kind) { should == kind }
6
- its(:id) { should == id }
7
- end
8
-
9
3
  describe Conjur::Role do
10
4
  let(:account) { "the-account" }
11
- context "#new" do
12
- let(:kind) { "test" }
13
- let(:role) { Conjur::API.new_from_token({ 'data' => 'the-login' }).role([ account, kind, id ].join(":")) }
5
+ let(:kind) { "test" }
6
+ let(:role) { Conjur::API.new_from_token({ 'data' => 'the-login' }).role([ account, kind, id ].join(":")) }
7
+ subject { role }
8
+
9
+ describe ".new" do
14
10
  context "with plain id" do
15
11
  let(:id) { "foo" }
16
- context "credentials" do
17
- subject { role }
18
- its(:options) { should == {:headers=>{:authorization=>"Token token=\"eyJkYXRhIjoidGhlLWxvZ2luIn0=\""}, :username=>'the-login'} }
19
- end
20
- it_should_behave_like "properties"
12
+ its(:options) { should == {:headers=>{:authorization=>"Token token=\"eyJkYXRhIjoidGhlLWxvZ2luIn0=\""}, :username=>'the-login'} }
13
+ its(:kind) { should == kind }
14
+ its(:id) { should == id }
21
15
  end
16
+
22
17
  context "with more complex id" do
23
18
  let(:id) { "foo/bar" }
24
- it_should_behave_like "properties"
19
+ its(:kind) { should == kind }
20
+ its(:id) { should == id }
25
21
  end
26
22
  end
27
- end
23
+
24
+ let(:id) { "role/id" }
25
+
26
+ describe "#grant_to" do
27
+ it "should take hash as the second argument and put it" do
28
+ members = double "members request"
29
+ subject.should_receive(:[]).with('?members&member=other').and_return(members)
30
+ members.should_receive(:put).with admin_option: true
31
+ subject.grant_to "other", admin_option: true
32
+ end
33
+
34
+ it "works without arguments" do
35
+ members = double "members request"
36
+ subject.should_receive(:[]).with('?members&member=other').and_return(members)
37
+ members.should_receive(:put).with nil
38
+ subject.grant_to "other"
39
+ end
40
+
41
+ context deprecated: 'v3' do # remove in 3.0
42
+ it "should also accept the deprecated argument format with extra options" do
43
+ members = double "members request"
44
+ subject.should_receive(:[]).with('?members&member=other').and_return(members)
45
+ members.should_receive(:put).with admin_option: true, foo: 'bar'
46
+ subject.grant_to "other", true, foo: 'bar'
47
+ end
48
+
49
+ it "should also accept the deprecated argument format without extra options" do
50
+ members = double "members request"
51
+ subject.should_receive(:[]).with('?members&member=other').and_return(members)
52
+ members.should_receive(:put).with admin_option: true, foo: 'bar'
53
+ subject.grant_to "other", true, foo: 'bar'
54
+ end
55
+ end
56
+ end
57
+ 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.3
4
+ version: 2.3.1
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-31 00:00:00.000000000 Z
13
+ date: 2013-06-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -208,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
208
  version: '0'
209
209
  segments:
210
210
  - 0
211
- hash: -3721927865223886977
211
+ hash: -1659157987203846410
212
212
  required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  none: false
214
214
  requirements:
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
217
217
  version: '0'
218
218
  segments:
219
219
  - 0
220
- hash: -3721927865223886977
220
+ hash: -1659157987203846410
221
221
  requirements: []
222
222
  rubyforge_project:
223
223
  rubygems_version: 1.8.24