conjur-api 4.10.0 → 4.10.1

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: 433c76ede7475ca9af07431734069c9692ace125
4
- data.tar.gz: 842baac408d16a623dc0539dbb312d970040eafc
3
+ metadata.gz: 8082f753ddebe272f08498fb3e144dcd5477cc57
4
+ data.tar.gz: 1de7d39d363c091712b8d73add7cf7d87b952ce1
5
5
  SHA512:
6
- metadata.gz: beb95d37603ab34b37f33e297d1c8ba5efb90d800432def027f110a895782d6e5eb730d220ac02430d95320ad684b0edb3d3ff76d0b04c799dc75ec309ad6458
7
- data.tar.gz: 115862f1080d52472f0cae83359f86526d6166668af11fa603cc0b38170c0f23a6fe6646c90eb62965839f789b51aefa624111212403174c4304386191da3e21
6
+ metadata.gz: 28727a8a68e30751fc2234329ceee61857d02fc6fbb41d8f51e1997523b66b21146d740f2af6577160a4d8aebc2f4026994a03fb20542750bb299a251deb80d1
7
+ data.tar.gz: 93e98f2269bd14ac60e4e3cd7ff8b6453aca5b0f7e4c2cc77da8e2e5736ed035a2712c460874f2ec72f467fd844ccbf9a41ec9b1db9d141bfda4476dd470a5a5
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ #ruby-gemset=conjur-api
4
+
3
5
  # Specify your gem's dependencies in conjur-api.gemspec
4
6
  gemspec
5
7
 
@@ -26,7 +26,7 @@ Gem::Specification.new do |gem|
26
26
  gem.add_development_dependency 'spork'
27
27
  gem.add_development_dependency 'rspec', '>= 2.14', '< 3.0'
28
28
  gem.add_development_dependency 'webmock'
29
- gem.add_development_dependency 'ci_reporter'
29
+ gem.add_development_dependency 'ci_reporter_rspec'
30
30
  gem.add_development_dependency 'simplecov'
31
31
  gem.add_development_dependency 'io-grab'
32
32
  gem.add_development_dependency 'yard'
@@ -20,6 +20,6 @@
20
20
  #
21
21
  module Conjur
22
22
  class API
23
- VERSION = "4.10.0"
23
+ VERSION = "4.10.1"
24
24
  end
25
25
  end
@@ -21,16 +21,38 @@
21
21
  module Conjur
22
22
 
23
23
  class << self
24
+ # Sets the Configuration for the current thread, yields the block, then resets the thread-local variable.
25
+ def with_configuration(config, &block)
26
+ oldvalue = Thread.current[:conjur_configuration]
27
+ Thread.current[:conjur_configuration] = config
28
+ yield
29
+ ensure
30
+ Thread.current[:conjur_configuration] = oldvalue
31
+ end
32
+
33
+ # Gets the current thread-local or global configuration.
24
34
  def configuration
25
- @config ||= Configuration.new
35
+ Thread.current[:conjur_configuration] || (@config ||= Configuration.new)
26
36
  end
27
37
 
38
+ # Sets the global configuration.
28
39
  def configuration=(config)
29
40
  @config = config
30
41
  end
31
42
  end
32
43
 
33
44
  class Configuration
45
+ # All explicit values.
46
+ attr_reader :explicit
47
+
48
+ # All explicit and cached values.
49
+ attr_reader :supplied
50
+
51
+ def initialize explicit = {}
52
+ @explicit = explicit.dup
53
+ @supplied = explicit.dup
54
+ end
55
+
34
56
  class << self
35
57
  # @api private
36
58
  def accepted_options
@@ -94,9 +116,15 @@ module Conjur
94
116
  alias_method("#{name}?", name) if options[:boolean]
95
117
  end
96
118
  end
119
+
120
+ # Copies the current configuration, except a set of overridden options.
121
+ def clone override_options
122
+ self.class.new self.explicit.dup.merge(override_options)
123
+ end
97
124
 
98
125
  def set(key, value)
99
126
  if self.class.accepted_options.include?(key.to_sym)
127
+ explicit[key.to_sym] = value
100
128
  supplied[key.to_sym] = value
101
129
  end
102
130
  end
@@ -176,9 +204,5 @@ module Conjur
176
204
  def herokuize name
177
205
  name.downcase.gsub(/[^a-z0-9\-]/, '-')
178
206
  end
179
-
180
- def supplied
181
- @supplied ||= {}
182
- end
183
207
  end
184
208
  end
@@ -24,6 +24,8 @@ module Conjur
24
24
  begin
25
25
  self.head(options)
26
26
  true
27
+ rescue RestClient::Forbidden
28
+ true
27
29
  rescue RestClient::ResourceNotFound
28
30
  false
29
31
  end
@@ -20,7 +20,6 @@ describe Conjur::API, api: :dummy do
20
20
  let(:invoke) { subject.create_host :options }
21
21
  end
22
22
  end
23
-
24
23
  describe '#host' do
25
24
  it_should_behave_like "standard_show with", :host, :id do
26
25
  let(:invoke) { subject.host :id }
@@ -4,7 +4,67 @@ describe Conjur::Configuration do
4
4
  before {
5
5
  Conjur.configuration = Conjur::Configuration.new
6
6
  }
7
- subject { Conjur.configuration }
7
+ let(:configuration) { Conjur.configuration }
8
+ subject { configuration }
9
+ context "thread-local behavior" do
10
+ it "can swap the Configuration in a new thread" do
11
+ original = Conjur.configuration
12
+ c = Conjur::Configuration.new
13
+ Thread.new do
14
+ Thread.current[:conjur_configuration] = :foo
15
+ Conjur.with_configuration c do
16
+ Conjur.configuration.should == c
17
+ end
18
+ Thread.current[:conjur_configuration].should == :foo
19
+ end.join
20
+ Conjur.configuration.should == original
21
+ end
22
+ end
23
+ context "with various options" do
24
+ before {
25
+ configuration.account = "the-account"
26
+ configuration.appliance_url = "https://conjur/api"
27
+ }
28
+ it "core_url is not pre-cached" do
29
+ configuration.supplied[:core_url].should_not be
30
+ end
31
+ it "core_url is cached after use" do
32
+ configuration.core_url
33
+ configuration.supplied[:core_url].should == configuration.core_url
34
+ end
35
+ context "and core_url fetched" do
36
+ before {
37
+ configuration.core_url
38
+ }
39
+ context "and duplicated" do
40
+ subject { configuration.clone override_options }
41
+ let(:override_options) { Hash.new }
42
+ its(:account) { should == configuration.account }
43
+ its(:appliance_url) { should == configuration.appliance_url }
44
+ its(:core_url) { should == configuration.appliance_url }
45
+ context "core_url fetched" do
46
+ it "is then cached in the original" do
47
+ configuration.supplied[:core_url].should be
48
+ end
49
+ it "is not cached in the copy" do
50
+ subject.supplied[:core_url].should_not be
51
+ end
52
+ end
53
+ context "appliance_url overridden" do
54
+ let(:override_options) {
55
+ { :appliance_url => "https://example/api" }
56
+ }
57
+ it "is ignored by the configuration core_url" do
58
+ configuration.core_url.should == "https://conjur/api"
59
+ end
60
+ it "is reflected in the copy core_url" do
61
+ subject.core_url.should == "https://example/api"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+
8
68
  context "CONJUR_ENV unspecified" do
9
69
  before {
10
70
  ENV.delete('CONJUR_ENV')
@@ -10,8 +10,8 @@ describe Conjur::Exists do
10
10
 
11
11
  context "when forbidden" do
12
12
  before { subject.stub(:head) { raise RestClient::Forbidden }}
13
- it "propagates the error" do
14
- lambda { subject.exists? }.should raise_error(RestClient::Forbidden)
13
+ it "returns true" do
14
+ subject.exists?.should be_truthy
15
15
  end
16
16
  end
17
17
 
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: 4.10.0
4
+ version: 4.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafał Rzepecki
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-15 00:00:00.000000000 Z
12
+ date: 2014-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -102,7 +102,7 @@ dependencies:
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  - !ruby/object:Gem::Dependency
105
- name: ci_reporter
105
+ name: ci_reporter_rspec
106
106
  requirement: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '>='