conjur-api 4.7.2 → 4.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/conjur-api/version.rb +1 -1
- data/lib/conjur/api/variables.rb +14 -1
- data/lib/conjur/configuration.rb +2 -2
- data/spec/api/variables_spec.rb +67 -0
- data/spec/lib/audit_spec.rb +2 -4
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
data/lib/conjur-api/version.rb
CHANGED
data/lib/conjur/api/variables.rb
CHANGED
@@ -29,5 +29,18 @@ module Conjur
|
|
29
29
|
def variable id
|
30
30
|
standard_show Conjur::Core::API.host, :variable, id
|
31
31
|
end
|
32
|
+
|
33
|
+
def variable_values(varlist)
|
34
|
+
raise ArgumentError, "Variables list must be an array" unless varlist.kind_of? Array
|
35
|
+
raise ArgumentError, "Variables list is empty" if varlist.empty?
|
36
|
+
opts = "?vars=#{varlist.map { |v| fully_escape(v) }.join(',')}"
|
37
|
+
begin
|
38
|
+
resp = RestClient::Resource.new(Conjur::Core::API.host, self.credentials)['variables/values'+opts].get
|
39
|
+
return JSON.parse( resp.body )
|
40
|
+
rescue RestClient::ResourceNotFound
|
41
|
+
return Hash[ *varlist.map { |v| [ v, variable(v).value ] }.flatten ]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
32
45
|
end
|
33
|
-
end
|
46
|
+
end
|
data/lib/conjur/configuration.rb
CHANGED
@@ -42,7 +42,7 @@ module Conjur
|
|
42
42
|
# @param [Hash] options
|
43
43
|
# @option options [Boolean] :boolean (false) whether this option should have a '?' accessor
|
44
44
|
# @option options [Boolean, String] :env Environment variable for this option. Set to false
|
45
|
-
# to disallow environment based configuration. Default is
|
45
|
+
# to disallow environment based configuration. Default is CONJUR_<OPTION_NAME>.
|
46
46
|
# @option options [Proc, *] :default Default value or proc to provide it
|
47
47
|
# @option options [Boolean] :required (false) when true, raise an exception if the option is
|
48
48
|
# not set
|
@@ -172,4 +172,4 @@ module Conjur
|
|
172
172
|
@supplied ||= {}
|
173
173
|
end
|
174
174
|
end
|
175
|
-
end
|
175
|
+
end
|
data/spec/api/variables_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'standard_methods_helper'
|
3
3
|
|
4
|
+
|
4
5
|
describe Conjur::API, api: :dummy do
|
5
6
|
describe '#create_variable' do
|
6
7
|
let(:invoke) { api.create_variable :type, :kind, other: true }
|
@@ -11,4 +12,70 @@ describe Conjur::API, api: :dummy do
|
|
11
12
|
let(:invoke) { api.variable :id }
|
12
13
|
it_should_behave_like 'standard_show with', :variable, :id
|
13
14
|
end
|
15
|
+
|
16
|
+
describe "#variable_values" do
|
17
|
+
|
18
|
+
let (:varlist) { ["var/1","var/2","var/3" ] }
|
19
|
+
|
20
|
+
it 'requires non-empty array of variables' do
|
21
|
+
expect { api.variable_values("something") }.to raise_exception(ArgumentError)
|
22
|
+
expect { api.variable_values([]) }.to raise_exception(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
shared_context "Stubbed API" do
|
26
|
+
let (:expected_url) { "#{core_host}/variables/values?vars=#{varlist.map {|v| api.fully_escape(v) }.join(",")}" }
|
27
|
+
before {
|
28
|
+
RestClient::Request.should_receive(:execute).with(
|
29
|
+
method: :get,
|
30
|
+
url: expected_url,
|
31
|
+
headers: credentials[:headers]
|
32
|
+
).and_return {
|
33
|
+
if defined? return_error
|
34
|
+
raise return_error
|
35
|
+
else
|
36
|
+
double( code: return_code, body: return_body )
|
37
|
+
end
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
let (:invoke) { api.variable_values(varlist) }
|
43
|
+
|
44
|
+
describe "if '/variables/values' method is responding with JSON" do
|
45
|
+
include_context "Stubbed API"
|
46
|
+
let (:return_code) { '200' }
|
47
|
+
let (:return_body) { '{"var/1":"val1","var/2":"val2","var/3":"val3"}' }
|
48
|
+
it "returns Hash of values built from the response" do
|
49
|
+
api.should_not_receive(:variable)
|
50
|
+
invoke.should == { "var/1"=>"val1", "var/2"=>"val2", "var/3"=>"val3" }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "if '/variables/values' method is returning 404 error" do
|
55
|
+
include_context "Stubbed API"
|
56
|
+
let (:return_error) { RestClient::ResourceNotFound }
|
57
|
+
before {
|
58
|
+
api.should_receive(:variable).with("var/1").and_return(double(value:"val1_obtained_separately"))
|
59
|
+
api.should_receive(:variable).with("var/2").and_return(double(value:"val2_obtained_separately"))
|
60
|
+
api.should_receive(:variable).with("var/3").and_return(double(value:"val3_obtained_separately"))
|
61
|
+
}
|
62
|
+
it 'tries variables one by one and returns Hash of values' do
|
63
|
+
invoke.should == { "var/1"=>"val1_obtained_separately",
|
64
|
+
"var/2"=>"val2_obtained_separately",
|
65
|
+
"var/3"=>"val3_obtained_separately"
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "if '/variables/values' method is returning any other error" do
|
71
|
+
include_context "Stubbed API"
|
72
|
+
let (:return_error) { RestClient::Forbidden }
|
73
|
+
it 're-raises error without checking particular variables' do
|
74
|
+
api.should_not_receive(:variable)
|
75
|
+
expect { invoke }.to raise_error(return_error)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
14
81
|
end
|
data/spec/lib/audit_spec.rb
CHANGED
@@ -13,9 +13,7 @@ describe Conjur::API, api: :dummy do
|
|
13
13
|
|
14
14
|
def expect_request
|
15
15
|
RestClient::Request.should_receive(:execute).with(
|
16
|
-
|
17
|
-
password: nil,
|
18
|
-
headers: {},
|
16
|
+
headers: credentials[:headers],
|
19
17
|
url: expected_url,
|
20
18
|
method: :get
|
21
19
|
).and_return response.to_json
|
@@ -105,4 +103,4 @@ describe Conjur::API, api: :dummy do
|
|
105
103
|
end
|
106
104
|
end
|
107
105
|
end
|
108
|
-
end
|
106
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -96,7 +96,7 @@ shared_context api: :dummy do
|
|
96
96
|
let(:api){ Conjur::API.new_from_key username, 'key' }
|
97
97
|
let(:authz_host) { 'http://authz.example.com' }
|
98
98
|
let(:audit_host) { 'http://audit.example.com' }
|
99
|
-
let(:credentials) {
|
99
|
+
let(:credentials) { { headers: { authorization: "Token token=\"stub\"" } } } #, username: username } }
|
100
100
|
let(:core_host) { 'http://core.example.com' }
|
101
101
|
let(:account) { 'the-account' }
|
102
102
|
|
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.
|
4
|
+
version: 4.8.0
|
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: 2014-
|
13
|
+
date: 2014-05-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
@@ -307,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
307
307
|
version: '0'
|
308
308
|
segments:
|
309
309
|
- 0
|
310
|
-
hash:
|
310
|
+
hash: 2336930098172204581
|
311
311
|
requirements: []
|
312
312
|
rubyforge_project:
|
313
313
|
rubygems_version: 1.8.25
|