conjur-api 2.1.0 → 2.1.1
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/acts_as_asset.rb +12 -0
- data/lib/conjur/api.rb +8 -0
- data/lib/conjur/build_from_response.rb +18 -0
- data/lib/conjur/core-api.rb +1 -1
- data/lib/conjur/env.rb +1 -1
- data/lib/conjur/has_attributes.rb +1 -0
- data/lib/conjur/has_id.rb +1 -2
- data/lib/conjur/standard_methods.rb +1 -8
- data/lib/conjur/token_cache.rb +2 -1
- data/spec/lib/api_spec.rb +2 -2
- metadata +6 -4
data/lib/conjur-api/version.rb
CHANGED
data/lib/conjur/api.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'conjur/env'
|
2
2
|
require 'conjur/base'
|
3
|
+
require 'conjur/build_from_response'
|
3
4
|
require 'conjur/acts_as_resource'
|
4
5
|
require 'conjur/acts_as_role'
|
5
6
|
require 'conjur/acts_as_user'
|
@@ -7,6 +8,7 @@ require 'conjur/log_source'
|
|
7
8
|
require 'conjur/has_attributes'
|
8
9
|
require 'conjur/has_identifier'
|
9
10
|
require 'conjur/has_id'
|
11
|
+
require 'conjur/acts_as_asset'
|
10
12
|
require 'conjur/authn-api'
|
11
13
|
require 'conjur/authz-api'
|
12
14
|
require 'conjur/core-api'
|
@@ -14,6 +16,12 @@ require 'conjur/core-api'
|
|
14
16
|
class RestClient::Resource
|
15
17
|
include Conjur::Escape
|
16
18
|
include Conjur::LogSource
|
19
|
+
extend Conjur::BuildFromResponse
|
20
|
+
|
21
|
+
def path_components
|
22
|
+
require 'uri'
|
23
|
+
URI.parse(self.url).path.split('/').map{|e| URI.unescape e}
|
24
|
+
end
|
17
25
|
|
18
26
|
def username
|
19
27
|
options[:user] || options[:username]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Conjur
|
2
|
+
module BuildFromResponse
|
3
|
+
def build_from_response(response, credentials)
|
4
|
+
new(response.headers[:location], credentials).tap do |obj|
|
5
|
+
obj.attributes = JSON.parse(response.body)
|
6
|
+
if obj.respond_to?(:resource_kind)
|
7
|
+
obj.log do |logger|
|
8
|
+
logger << "Created #{obj.resource_kind} #{obj.resource_id}"
|
9
|
+
end
|
10
|
+
elsif obj.respond_to?(:id)
|
11
|
+
obj.log do |logger|
|
12
|
+
logger << "Created #{self.name} #{obj.id}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/conjur/core-api.rb
CHANGED
@@ -9,7 +9,7 @@ module Conjur
|
|
9
9
|
def default_host
|
10
10
|
case Conjur.env
|
11
11
|
when 'test', 'development'
|
12
|
-
"http://localhost:#{Conjur.service_base_port +
|
12
|
+
"http://localhost:#{Conjur.service_base_port + 200}"
|
13
13
|
else
|
14
14
|
"https://core-#{Conjur.stack}-conjur.herokuapp.com"
|
15
15
|
end
|
data/lib/conjur/env.rb
CHANGED
data/lib/conjur/has_id.rb
CHANGED
@@ -14,14 +14,7 @@ module Conjur
|
|
14
14
|
options ||= {}
|
15
15
|
options[:id] = id if id
|
16
16
|
resp = RestClient::Resource.new(host, credentials)[type.to_s.pluralize].post(options)
|
17
|
-
"Conjur::#{type.to_s.classify}".constantize.
|
18
|
-
obj.attributes = JSON.parse(resp.body)
|
19
|
-
if id.blank? && obj.respond_to?(:id)
|
20
|
-
log do |logger|
|
21
|
-
logger << "Created #{type} #{obj.id}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
17
|
+
"Conjur::#{type.to_s.classify}".constantize.build_from_response(resp, credentials)
|
25
18
|
end
|
26
19
|
|
27
20
|
def standard_list(host, type, options)
|
data/lib/conjur/token_cache.rb
CHANGED
@@ -15,7 +15,7 @@ module Conjur
|
|
15
15
|
elsif token.nil?
|
16
16
|
raise "Token is nil and no api_key is available to create it"
|
17
17
|
else
|
18
|
-
$stderr.puts "Token
|
18
|
+
$stderr.puts "Token will soon expire and no api_key is available to renew it"
|
19
19
|
end
|
20
20
|
end
|
21
21
|
token
|
@@ -33,6 +33,7 @@ module Conjur
|
|
33
33
|
|
34
34
|
# Expire tokens after 1 minute, even though they are valid for longer.
|
35
35
|
def expired?(token, expiry = 1 * 60)
|
36
|
+
raise "No timestamp in token" unless token['timestamp']
|
36
37
|
Time.parse(token["timestamp"]) + expiry < Time.now
|
37
38
|
end
|
38
39
|
end
|
data/spec/lib/api_spec.rb
CHANGED
@@ -34,7 +34,7 @@ shared_examples_for "API endpoint" do
|
|
34
34
|
Conjur.stub(:env).and_return "production"
|
35
35
|
end
|
36
36
|
its "default_host" do
|
37
|
-
should == "https://#{service_name}-
|
37
|
+
should == "https://#{service_name}-v3-conjur.herokuapp.com"
|
38
38
|
end
|
39
39
|
end
|
40
40
|
context "in named production version" do
|
@@ -81,7 +81,7 @@ describe Conjur::API do
|
|
81
81
|
Conjur::TokenCache.stub(:expired?).and_return true
|
82
82
|
}
|
83
83
|
it "should raise an error" do
|
84
|
-
$stderr.should_receive(:puts).with("Token
|
84
|
+
$stderr.should_receive(:puts).with("Token will soon expire and no api_key is available to renew it")
|
85
85
|
|
86
86
|
api.credentials
|
87
87
|
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.
|
4
|
+
version: 2.1.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-03-
|
13
|
+
date: 2013-03-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- features/ping_as_server.feature
|
147
147
|
- features/ping_as_user.feature
|
148
148
|
- lib/conjur-api/version.rb
|
149
|
+
- lib/conjur/acts_as_asset.rb
|
149
150
|
- lib/conjur/acts_as_resource.rb
|
150
151
|
- lib/conjur/acts_as_role.rb
|
151
152
|
- lib/conjur/acts_as_user.rb
|
@@ -161,6 +162,7 @@ files:
|
|
161
162
|
- lib/conjur/authn-api.rb
|
162
163
|
- lib/conjur/authz-api.rb
|
163
164
|
- lib/conjur/base.rb
|
165
|
+
- lib/conjur/build_from_response.rb
|
164
166
|
- lib/conjur/core-api.rb
|
165
167
|
- lib/conjur/env.rb
|
166
168
|
- lib/conjur/escape.rb
|
@@ -202,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
202
204
|
version: '0'
|
203
205
|
segments:
|
204
206
|
- 0
|
205
|
-
hash:
|
207
|
+
hash: 4047181916872803185
|
206
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
209
|
none: false
|
208
210
|
requirements:
|
@@ -211,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
213
|
version: '0'
|
212
214
|
segments:
|
213
215
|
- 0
|
214
|
-
hash:
|
216
|
+
hash: 4047181916872803185
|
215
217
|
requirements: []
|
216
218
|
rubyforge_project:
|
217
219
|
rubygems_version: 1.8.24
|