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.
@@ -1,5 +1,5 @@
1
1
  module Conjur
2
2
  class API
3
- VERSION = "2.1.0"
3
+ VERSION = "2.1.1"
4
4
  end
5
5
  end
@@ -0,0 +1,12 @@
1
+ module Conjur
2
+ module ActsAsAsset
3
+ def self.included(base)
4
+ base.instance_eval do
5
+ include ActsAsResource
6
+ include HasAttributes
7
+ include Exists
8
+ include HasId
9
+ end
10
+ end
11
+ end
12
+ end
@@ -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
@@ -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 + 300}"
12
+ "http://localhost:#{Conjur.service_base_port + 200}"
13
13
  else
14
14
  "https://core-#{Conjur.stack}-conjur.herokuapp.com"
15
15
  end
@@ -16,7 +16,7 @@ module Conjur
16
16
  def stack
17
17
  ENV['CONJUR_STACK'] || case env
18
18
  when "production"
19
- "v21"
19
+ "v3"
20
20
  else
21
21
  env
22
22
  end
@@ -20,6 +20,7 @@ module Conjur
20
20
 
21
21
  def invalidate(&block)
22
22
  yield
23
+ ensure
23
24
  @attributes = nil
24
25
  end
25
26
 
@@ -1,8 +1,7 @@
1
1
  module Conjur
2
2
  module HasId
3
3
  def id
4
- require 'uri'
5
- URI.unescape URI.parse(self.url).path.split('/')[-1]
4
+ path_components[-1]
6
5
  end
7
6
  end
8
7
  end
@@ -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.new(resp.headers[:location], credentials).tap do |obj|
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)
@@ -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 is expired and no api_key is available to renew it"
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
@@ -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}-v2-conjur.herokuapp.com"
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 is expired and no api_key is available to renew it")
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.0
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-25 00:00:00.000000000 Z
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: -1471203965853689802
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: -1471203965853689802
216
+ hash: 4047181916872803185
215
217
  requirements: []
216
218
  rubyforge_project:
217
219
  rubygems_version: 1.8.24