conjur-api 2.0.0 → 2.0.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/conjur-api.gemspec +3 -4
- data/lib/conjur-api/version.rb +1 -1
- data/lib/conjur/api.rb +0 -1
- data/lib/conjur/api/authn.rb +3 -3
- data/lib/conjur/api/groups.rb +2 -7
- data/lib/conjur/api/hosts.rb +5 -14
- data/lib/conjur/api/roles.rb +5 -6
- data/lib/conjur/api/secrets.rb +2 -12
- data/lib/conjur/api/users.rb +2 -12
- data/lib/conjur/api/variables.rb +2 -14
- data/lib/conjur/base.rb +14 -7
- data/lib/conjur/group.rb +1 -0
- data/lib/conjur/resource.rb +1 -1
- data/lib/conjur/role.rb +4 -4
- data/lib/conjur/secret.rb +1 -1
- data/lib/conjur/standard_methods.rb +39 -0
- data/lib/conjur/token_cache.rb +40 -0
- data/spec/lib/api_spec.rb +24 -8
- data/spec/lib/resource_spec.rb +0 -47
- data/spec/spec_helper.rb +0 -10
- metadata +6 -22
- data/spec/lib/das_spec.rb +0 -33
data/conjur-api.gemspec
CHANGED
|
@@ -15,14 +15,13 @@ Gem::Specification.new do |gem|
|
|
|
15
15
|
gem.require_paths = ["lib"]
|
|
16
16
|
gem.version = Conjur::API::VERSION
|
|
17
17
|
|
|
18
|
-
gem.
|
|
19
|
-
gem.
|
|
20
|
-
gem.
|
|
18
|
+
gem.add_dependency 'rest-client'
|
|
19
|
+
gem.add_dependency 'slosilo'
|
|
20
|
+
gem.add_dependency 'activesupport'
|
|
21
21
|
|
|
22
22
|
gem.add_development_dependency 'rake'
|
|
23
23
|
gem.add_development_dependency 'spork'
|
|
24
24
|
gem.add_development_dependency 'rspec'
|
|
25
|
-
gem.add_development_dependency 'vcr'
|
|
26
25
|
gem.add_development_dependency 'webmock'
|
|
27
26
|
gem.add_development_dependency 'ci_reporter'
|
|
28
27
|
end
|
data/lib/conjur-api/version.rb
CHANGED
data/lib/conjur/api.rb
CHANGED
data/lib/conjur/api/authn.rb
CHANGED
|
@@ -17,7 +17,7 @@ module Conjur
|
|
|
17
17
|
if Conjur.log
|
|
18
18
|
Conjur.log << "Logging in #{username} via Basic authentication\n"
|
|
19
19
|
end
|
|
20
|
-
RestClient::Resource.new(Conjur::Authn::API.host, user: username, password: password)['
|
|
20
|
+
RestClient::Resource.new(Conjur::Authn::API.host, user: username, password: password)['users/login'].get
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
# Perform login by CAS authentication.
|
|
@@ -34,7 +34,7 @@ module Conjur
|
|
|
34
34
|
if Conjur.log
|
|
35
35
|
Conjur.log << "Authenticating #{username}\n"
|
|
36
36
|
end
|
|
37
|
-
JSON::parse(RestClient::Resource.new(Conjur::Authn::API.host)["
|
|
37
|
+
JSON::parse(RestClient::Resource.new(Conjur::Authn::API.host)["users/#{path_escape username}/authenticate"].post password, content_type: 'text/plain').tap do |token|
|
|
38
38
|
raise InvalidToken.new unless token_valid?(token)
|
|
39
39
|
end
|
|
40
40
|
end
|
|
@@ -60,7 +60,7 @@ module Conjur
|
|
|
60
60
|
log do |logger|
|
|
61
61
|
logger << "Creating authn user #{login}"
|
|
62
62
|
end
|
|
63
|
-
JSON.parse RestClient::Resource.new(Conjur::Authn::API.host, credentials)['
|
|
63
|
+
JSON.parse RestClient::Resource.new(Conjur::Authn::API.host, credentials)['users'].post(options.merge(login: login))
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
end
|
data/lib/conjur/api/groups.rb
CHANGED
|
@@ -3,16 +3,11 @@ require 'conjur/group'
|
|
|
3
3
|
module Conjur
|
|
4
4
|
class API
|
|
5
5
|
def create_group(id, options = {})
|
|
6
|
-
|
|
7
|
-
logger << "Creating group "
|
|
8
|
-
logger << id
|
|
9
|
-
end
|
|
10
|
-
resp = RestClient::Resource.new(Conjur::Core::API.host, credentials)['/groups'].post(options.merge(id: id))
|
|
11
|
-
Group.new(resp.headers[:location], credentials)
|
|
6
|
+
standard_create Conjur::Core::API.host, :group, id, options
|
|
12
7
|
end
|
|
13
8
|
|
|
14
9
|
def group id
|
|
15
|
-
|
|
10
|
+
standard_show Conjur::Core::API.host, :group, id
|
|
16
11
|
end
|
|
17
12
|
end
|
|
18
13
|
end
|
data/lib/conjur/api/hosts.rb
CHANGED
|
@@ -2,19 +2,6 @@ require 'conjur/host'
|
|
|
2
2
|
|
|
3
3
|
module Conjur
|
|
4
4
|
class API
|
|
5
|
-
def create_host options
|
|
6
|
-
log do |logger|
|
|
7
|
-
logger << "Creating host"
|
|
8
|
-
end
|
|
9
|
-
resp = JSON.parse RestClient::Resource.new("#{Conjur::Core::API.host}/hosts", credentials).post(options)
|
|
10
|
-
host(resp['id']).tap do |h|
|
|
11
|
-
log do |logger|
|
|
12
|
-
logger << "Created host #{h.id}"
|
|
13
|
-
end
|
|
14
|
-
h.attributes = resp
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
5
|
class << self
|
|
19
6
|
def enroll_host(url)
|
|
20
7
|
if Conjur.log
|
|
@@ -30,8 +17,12 @@ module Conjur
|
|
|
30
17
|
end
|
|
31
18
|
end
|
|
32
19
|
|
|
20
|
+
def create_host options
|
|
21
|
+
standard_create Conjur::Core::API.host, :host, nil, options
|
|
22
|
+
end
|
|
23
|
+
|
|
33
24
|
def host id
|
|
34
|
-
|
|
25
|
+
standard_show Conjur::Core::API.host, :host, id
|
|
35
26
|
end
|
|
36
27
|
end
|
|
37
28
|
end
|
data/lib/conjur/api/roles.rb
CHANGED
|
@@ -4,15 +4,14 @@ module Conjur
|
|
|
4
4
|
class API
|
|
5
5
|
def create_role(role, options = {})
|
|
6
6
|
log do |logger|
|
|
7
|
-
logger << "Creating role "
|
|
8
|
-
logger << role
|
|
7
|
+
logger << "Creating role #{account}/#{role}"
|
|
9
8
|
end
|
|
10
|
-
RestClient::Resource.new(Conjur::Authz::API.host, credentials)["
|
|
11
|
-
|
|
9
|
+
RestClient::Resource.new(Conjur::Authz::API.host, credentials)["roles/#{path_escape role}"].put(options)
|
|
10
|
+
role(role)
|
|
12
11
|
end
|
|
13
12
|
|
|
14
|
-
def role
|
|
15
|
-
Role.new(
|
|
13
|
+
def role role
|
|
14
|
+
Role.new(Conjur::Authz::API.host, credentials)["roles/#{path_escape role}"]
|
|
16
15
|
end
|
|
17
16
|
end
|
|
18
17
|
end
|
data/lib/conjur/api/secrets.rb
CHANGED
|
@@ -3,21 +3,11 @@ require 'conjur/secret'
|
|
|
3
3
|
module Conjur
|
|
4
4
|
class API
|
|
5
5
|
def create_secret(value, options = {})
|
|
6
|
-
|
|
7
|
-
logger << "Creating secret "
|
|
8
|
-
logger << value
|
|
9
|
-
end
|
|
10
|
-
resp = RestClient::Resource.new(Conjur::Core::API.host, credentials)['/secrets'].post(options.merge(value: value))
|
|
11
|
-
Secret.new(resp.headers[:location], credentials).tap do |secret|
|
|
12
|
-
log do |logger|
|
|
13
|
-
logger << "Created secret "
|
|
14
|
-
logger << secret.id
|
|
15
|
-
end
|
|
16
|
-
end
|
|
6
|
+
standard_create Conjur::Core::API.host, :secret, nil, options.merge(value: value)
|
|
17
7
|
end
|
|
18
8
|
|
|
19
9
|
def secret id
|
|
20
|
-
|
|
10
|
+
standard_show Conjur::Core::API.host, :secret, id
|
|
21
11
|
end
|
|
22
12
|
end
|
|
23
13
|
end
|
data/lib/conjur/api/users.rb
CHANGED
|
@@ -3,21 +3,11 @@ require 'conjur/user'
|
|
|
3
3
|
module Conjur
|
|
4
4
|
class API
|
|
5
5
|
def create_user(login, options = {})
|
|
6
|
-
|
|
7
|
-
logger << "Creating user "
|
|
8
|
-
logger << login
|
|
9
|
-
end
|
|
10
|
-
resp = JSON.parse RestClient::Resource.new(Conjur::Core::API.host, credentials)['/users'].post(options.merge(login: login))
|
|
11
|
-
user(resp['login']).tap do |u|
|
|
12
|
-
log do |logger|
|
|
13
|
-
logger << "Created user #{u.login}"
|
|
14
|
-
end
|
|
15
|
-
u.attributes = resp
|
|
16
|
-
end
|
|
6
|
+
standard_create Conjur::Core::API.host, :user, nil, options.merge(login: login)
|
|
17
7
|
end
|
|
18
8
|
|
|
19
9
|
def user login
|
|
20
|
-
|
|
10
|
+
standard_show Conjur::Core::API.host, :user, login
|
|
21
11
|
end
|
|
22
12
|
end
|
|
23
13
|
end
|
data/lib/conjur/api/variables.rb
CHANGED
|
@@ -3,23 +3,11 @@ require 'conjur/variable'
|
|
|
3
3
|
module Conjur
|
|
4
4
|
class API
|
|
5
5
|
def create_variable(mime_type, kind, options = {})
|
|
6
|
-
|
|
7
|
-
logger << "Creating #{mime_type} variable #{kind}"
|
|
8
|
-
if options
|
|
9
|
-
logger << " with options #{options.inspect}"
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
resp = RestClient::Resource.new(Conjur::Core::API.host, credentials)['variables'].post(options.merge(mime_type: mime_type, kind: kind))
|
|
13
|
-
Variable.new(resp.headers[:location], credentials).tap do |variable|
|
|
14
|
-
log do |logger|
|
|
15
|
-
logger << "Created variable "
|
|
16
|
-
logger << variable.id
|
|
17
|
-
end
|
|
18
|
-
end
|
|
6
|
+
standard_create Conjur::Core::API.host, :variable, nil, options.merge(mime_type: mime_type, kind: kind)
|
|
19
7
|
end
|
|
20
8
|
|
|
21
9
|
def variable id
|
|
22
|
-
|
|
10
|
+
standard_show Conjur::Core::API.host, :variable, id
|
|
23
11
|
end
|
|
24
12
|
end
|
|
25
13
|
end
|
data/lib/conjur/base.rb
CHANGED
|
@@ -6,11 +6,14 @@ require 'conjur/has_attributes'
|
|
|
6
6
|
require 'conjur/escape'
|
|
7
7
|
require 'conjur/log'
|
|
8
8
|
require 'conjur/log_source'
|
|
9
|
+
require 'conjur/standard_methods'
|
|
10
|
+
require 'conjur/token_cache'
|
|
9
11
|
|
|
10
12
|
module Conjur
|
|
11
13
|
class API
|
|
12
14
|
include Escape
|
|
13
15
|
include LogSource
|
|
16
|
+
include StandardMethods
|
|
14
17
|
|
|
15
18
|
class << self
|
|
16
19
|
def new_from_key(username, api_key)
|
|
@@ -26,25 +29,29 @@ module Conjur
|
|
|
26
29
|
@username = username
|
|
27
30
|
@api_key = api_key
|
|
28
31
|
@token = token
|
|
32
|
+
TokenCache.store(@token) if token
|
|
33
|
+
|
|
29
34
|
raise "Expecting ( username and api_key ) or token" unless ( username && api_key ) || token
|
|
30
35
|
end
|
|
31
36
|
|
|
32
|
-
attr_reader :api_key, :username
|
|
37
|
+
attr_reader :api_key, :username
|
|
33
38
|
|
|
34
39
|
def username
|
|
35
|
-
@username || token['data']
|
|
40
|
+
@username || @token['data']
|
|
36
41
|
end
|
|
37
42
|
|
|
38
43
|
def host
|
|
39
44
|
self.class.host
|
|
40
45
|
end
|
|
41
46
|
|
|
47
|
+
def token
|
|
48
|
+
TokenCache.fetch(username, api_key)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Authenticate the username and api_key to obtain a request token.
|
|
52
|
+
# Tokens are cached by username for a short period of time.
|
|
42
53
|
def credentials
|
|
43
|
-
|
|
44
|
-
{ headers: { authorization: "Token token=\"#{Base64.strict_encode64 token.to_json}\"" }, username: username }
|
|
45
|
-
else
|
|
46
|
-
{ user: username, password: api_key }
|
|
47
|
-
end
|
|
54
|
+
{ headers: { authorization: "Token token=\"#{Base64.strict_encode64 token.to_json}\"" }, username: username }
|
|
48
55
|
end
|
|
49
56
|
end
|
|
50
57
|
end
|
data/lib/conjur/group.rb
CHANGED
data/lib/conjur/resource.rb
CHANGED
|
@@ -23,7 +23,7 @@ module Conjur
|
|
|
23
23
|
|
|
24
24
|
# Lists roles that have a specified permission on the resource.
|
|
25
25
|
def permitted_roles(permission, options = {})
|
|
26
|
-
JSON.parse RestClient::Resource.new(Conjur::Authz::API.host, self.options)["
|
|
26
|
+
JSON.parse RestClient::Resource.new(Conjur::Authz::API.host, self.options)["roles/allowed_to/#{permission}/#{path_escape kind}/#{path_escape identifier}"].get(options)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# Changes the owner of a resource
|
data/lib/conjur/role.rb
CHANGED
|
@@ -14,7 +14,7 @@ module Conjur
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def all(options = {})
|
|
17
|
-
JSON.parse(self["
|
|
17
|
+
JSON.parse(self["all"].get(options)).collect do |id|
|
|
18
18
|
Role.new("#{Conjur::Authz::API.host}/roles/#{path_escape id}", self.options)
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -29,7 +29,7 @@ module Conjur
|
|
|
29
29
|
logger << " and extended options #{options.to_json}"
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
|
-
self["
|
|
32
|
+
self["members/#{path_escape member}?admin_option=#{query_escape admin_option}"].put(options)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def revoke_from(member, options = {})
|
|
@@ -39,11 +39,11 @@ module Conjur
|
|
|
39
39
|
logger << " with options #{options.to_json}"
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
|
-
self["
|
|
42
|
+
self["members/#{path_escape member}"].delete(options)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def permitted?(resource_kind, resource_id, privilege, options = {})
|
|
46
|
-
self["
|
|
46
|
+
self["permitted?resource_kind=#{query_escape resource_kind}&resource_id=#{query_escape resource_id}&privilege=#{query_escape privilege}"].get(options)
|
|
47
47
|
true
|
|
48
48
|
rescue RestClient::ResourceNotFound
|
|
49
49
|
false
|
data/lib/conjur/secret.rb
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Conjur
|
|
2
|
+
module StandardMethods
|
|
3
|
+
require 'active_support/core_ext'
|
|
4
|
+
|
|
5
|
+
protected
|
|
6
|
+
|
|
7
|
+
def standard_create(host, type, id = nil, options = nil)
|
|
8
|
+
log do |logger|
|
|
9
|
+
logger << "Creating #{type} #{id}"
|
|
10
|
+
unless options.blank?
|
|
11
|
+
logger << " with options #{options.inspect}"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
options ||= {}
|
|
15
|
+
options[:id] = id if id
|
|
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
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def standard_list(host, type, options)
|
|
28
|
+
JSON.parse(RestClient::Resource.new(host, credentials)[type.to_s.pluralize].get(options)).collect do |json|
|
|
29
|
+
send(type, json['id']).tap do |obj|
|
|
30
|
+
obj.attributes = json
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def standard_show(host, type, id)
|
|
36
|
+
"Conjur::#{type.to_s.classify}".constantize.new(host, credentials)[ [type.to_s.pluralize, path_escape(id)].join('/') ]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Conjur
|
|
2
|
+
# Cache API tokens. The cache key is the authentication hostname and the username.
|
|
3
|
+
# Tokens are cached for a short period of time; long enough to save on server trips
|
|
4
|
+
# but not long enough to worry about tokens expiring.
|
|
5
|
+
class TokenCache
|
|
6
|
+
@@tokens = Hash.new
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
def fetch(username, api_key)
|
|
10
|
+
key = [ Conjur::Authn::API.host, username ]
|
|
11
|
+
token = @@tokens[key]
|
|
12
|
+
if token.nil? || expired?(token)
|
|
13
|
+
if username && api_key
|
|
14
|
+
store(token = Conjur::API.authenticate(username, api_key))
|
|
15
|
+
elsif token.nil?
|
|
16
|
+
raise "Token is nil and no api_key is available to create it"
|
|
17
|
+
else
|
|
18
|
+
$stderr.puts "Token is expired and no api_key is available to renew it"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
token
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def store(token)
|
|
25
|
+
username = token['data']
|
|
26
|
+
raise "No data in token" unless username
|
|
27
|
+
raise "Expecting string username in token" unless username.is_a?(String)
|
|
28
|
+
key = [ Conjur::Authn::API.host, username ]
|
|
29
|
+
@@tokens[key] = token
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
protected
|
|
33
|
+
|
|
34
|
+
# Expire tokens after 1 minute, even though they are valid for longer.
|
|
35
|
+
def expired?(token, expiry = 1 * 60)
|
|
36
|
+
Time.parse(token["timestamp"]) + expiry < Time.now
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/spec/lib/api_spec.rb
CHANGED
|
@@ -60,11 +60,6 @@ describe Conjur::API do
|
|
|
60
60
|
let(:api) { Conjur::Authz::API }
|
|
61
61
|
it_should_behave_like "API endpoint"
|
|
62
62
|
end
|
|
63
|
-
context "of das service" do
|
|
64
|
-
let(:port_offset) { 200 }
|
|
65
|
-
let(:api) { Conjur::DAS::API }
|
|
66
|
-
it_should_behave_like "API endpoint"
|
|
67
|
-
end
|
|
68
63
|
context "of core service" do
|
|
69
64
|
let(:port_offset) { 300 }
|
|
70
65
|
let(:api) { Conjur::Core::API }
|
|
@@ -83,16 +78,37 @@ describe Conjur::API do
|
|
|
83
78
|
end
|
|
84
79
|
context "credential handling" do
|
|
85
80
|
let(:login) { "bob" }
|
|
81
|
+
let(:token) { { 'data' => login, 'timestamp' => (Time.now + elapsed ).to_s } }
|
|
82
|
+
let(:elapsed) { 0 }
|
|
83
|
+
before {
|
|
84
|
+
Conjur::TokenCache.class_variable_set("@@tokens", Hash.new)
|
|
85
|
+
}
|
|
86
86
|
subject { api }
|
|
87
87
|
context "from token" do
|
|
88
|
-
let(:token) { { 'data' => login } }
|
|
89
88
|
let(:api) { Conjur::API.new_from_token(token) }
|
|
90
|
-
|
|
89
|
+
context "expired" do
|
|
90
|
+
before {
|
|
91
|
+
Conjur::TokenCache.stub(:expired?).and_return true
|
|
92
|
+
}
|
|
93
|
+
it "should raise an error" do
|
|
94
|
+
$stderr.should_receive(:puts).with("Token is expired and no api_key is available to renew it")
|
|
95
|
+
|
|
96
|
+
api.credentials
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
context "not expired" do
|
|
100
|
+
its(:credentials) { should == { headers: { authorization: "Token token=\"#{Base64.strict_encode64(token.to_json)}\"" }, username: login } }
|
|
101
|
+
end
|
|
91
102
|
end
|
|
92
103
|
context "from api key" do
|
|
93
104
|
let(:api_key) { "theapikey" }
|
|
94
105
|
let(:api) { Conjur::API.new_from_key(login, api_key) }
|
|
95
|
-
|
|
106
|
+
it("should authenticate to get a token") do
|
|
107
|
+
Conjur::API.should_receive(:authenticate).with(login, api_key).and_return token
|
|
108
|
+
|
|
109
|
+
api.instance_variable_get("@token").should == nil
|
|
110
|
+
api.credentials.should == { headers: { authorization: "Token token=\"#{Base64.strict_encode64(token.to_json)}\"" }, username: login }
|
|
111
|
+
end
|
|
96
112
|
end
|
|
97
113
|
end
|
|
98
114
|
end
|
data/spec/lib/resource_spec.rb
CHANGED
|
@@ -3,32 +3,6 @@ require 'spec_helper'
|
|
|
3
3
|
require 'conjur/api'
|
|
4
4
|
|
|
5
5
|
describe Conjur::Resource do
|
|
6
|
-
let(:user) { 'admin' }
|
|
7
|
-
let(:api_key) { '^6feWZpr' }
|
|
8
|
-
|
|
9
|
-
def conjur_api
|
|
10
|
-
Conjur::API.new_from_key(user, api_key)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.it_creates_with code
|
|
14
|
-
it "should create with status #{code}" do
|
|
15
|
-
resource = conjur_api.resource("spec", identifier)
|
|
16
|
-
resource.create
|
|
17
|
-
resource.should exist
|
|
18
|
-
conjur_api.resource("spec", identifier).kind.should == "spec"
|
|
19
|
-
conjur_api.resource("spec", identifier).identifier.should == identifier
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def self.it_fails_with code
|
|
24
|
-
it "should fail with status #{code}" do
|
|
25
|
-
expect { conjur_api.resource("spec", identifier).create }.to raise_error { |error|
|
|
26
|
-
error.should be_a(RestClient::Exception)
|
|
27
|
-
error.http_code.should == code
|
|
28
|
-
}
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
6
|
let(:uuid) { "ddd1f59a-494d-48fb-b045-0374c4a6eef9" }
|
|
33
7
|
|
|
34
8
|
context "identifier" do
|
|
@@ -60,25 +34,4 @@ describe Conjur::Resource do
|
|
|
60
34
|
end
|
|
61
35
|
end
|
|
62
36
|
end
|
|
63
|
-
context "#create" do
|
|
64
|
-
context "with uuid identifier" do
|
|
65
|
-
use_vcr_cassette
|
|
66
|
-
let(:identifier) { uuid }
|
|
67
|
-
it_creates_with 204
|
|
68
|
-
it "is findable" do
|
|
69
|
-
conjur_api.resource("spec", identifier).create
|
|
70
|
-
conjur_api.resource("spec", identifier).should exist
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
context "with path-like identifier" do
|
|
74
|
-
use_vcr_cassette
|
|
75
|
-
let(:identifier) { [ uuid, "xxx" ].join("/") }
|
|
76
|
-
it_creates_with 204
|
|
77
|
-
end
|
|
78
|
-
context "with un-encoded path-like identifier" do
|
|
79
|
-
use_vcr_cassette
|
|
80
|
-
let(:identifier) { [ uuid, "+?!!?+/xxx" ].join("/") }
|
|
81
|
-
it_creates_with 204
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
37
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -11,19 +11,11 @@ Spork.prefork do
|
|
|
11
11
|
# Allows loading of an environment config based on the environment
|
|
12
12
|
require 'rspec'
|
|
13
13
|
require 'webmock/rspec'
|
|
14
|
-
require 'vcr'
|
|
15
14
|
require 'securerandom'
|
|
16
15
|
|
|
17
16
|
# Uncomment the next line to use webrat's matchers
|
|
18
17
|
#require 'webrat/integrations/rspec-rails'
|
|
19
18
|
|
|
20
|
-
VCR.configure do |c|
|
|
21
|
-
c.cassette_library_dir = 'spec/vcr_cassettes'
|
|
22
|
-
c.hook_into :webmock
|
|
23
|
-
c.default_cassette_options = { :record => :new_episodes }
|
|
24
|
-
# c.ignore_localhost = true
|
|
25
|
-
end
|
|
26
|
-
|
|
27
19
|
RSpec.configure do |config|
|
|
28
20
|
# If you're not using ActiveRecord you should remove these
|
|
29
21
|
# lines, delete config/database.yml and disable :active_record
|
|
@@ -62,8 +54,6 @@ Spork.prefork do
|
|
|
62
54
|
# == Notes
|
|
63
55
|
#
|
|
64
56
|
# For more information take a look at Spec::Runner::Configuration and Spec::Runner
|
|
65
|
-
|
|
66
|
-
config.extend VCR::RSpec::Macros
|
|
67
57
|
end
|
|
68
58
|
end
|
|
69
59
|
|
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.0.
|
|
4
|
+
version: 2.0.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-14 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: rest-client
|
|
@@ -108,22 +108,6 @@ dependencies:
|
|
|
108
108
|
- - ! '>='
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
110
|
version: '0'
|
|
111
|
-
- !ruby/object:Gem::Dependency
|
|
112
|
-
name: vcr
|
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
|
114
|
-
none: false
|
|
115
|
-
requirements:
|
|
116
|
-
- - ! '>='
|
|
117
|
-
- !ruby/object:Gem::Version
|
|
118
|
-
version: '0'
|
|
119
|
-
type: :development
|
|
120
|
-
prerelease: false
|
|
121
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
122
|
-
none: false
|
|
123
|
-
requirements:
|
|
124
|
-
- - ! '>='
|
|
125
|
-
- !ruby/object:Gem::Version
|
|
126
|
-
version: '0'
|
|
127
111
|
- !ruby/object:Gem::Dependency
|
|
128
112
|
name: webmock
|
|
129
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -209,10 +193,11 @@ files:
|
|
|
209
193
|
- lib/conjur/resource.rb
|
|
210
194
|
- lib/conjur/role.rb
|
|
211
195
|
- lib/conjur/secret.rb
|
|
196
|
+
- lib/conjur/standard_methods.rb
|
|
197
|
+
- lib/conjur/token_cache.rb
|
|
212
198
|
- lib/conjur/user.rb
|
|
213
199
|
- lib/conjur/variable.rb
|
|
214
200
|
- spec/lib/api_spec.rb
|
|
215
|
-
- spec/lib/das_spec.rb
|
|
216
201
|
- spec/lib/resource_spec.rb
|
|
217
202
|
- spec/lib/role_spec.rb
|
|
218
203
|
- spec/lib/user_spec.rb
|
|
@@ -234,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
234
219
|
version: '0'
|
|
235
220
|
segments:
|
|
236
221
|
- 0
|
|
237
|
-
hash:
|
|
222
|
+
hash: 3809342943954328390
|
|
238
223
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
239
224
|
none: false
|
|
240
225
|
requirements:
|
|
@@ -243,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
243
228
|
version: '0'
|
|
244
229
|
segments:
|
|
245
230
|
- 0
|
|
246
|
-
hash:
|
|
231
|
+
hash: 3809342943954328390
|
|
247
232
|
requirements: []
|
|
248
233
|
rubyforge_project:
|
|
249
234
|
rubygems_version: 1.8.24
|
|
@@ -256,7 +241,6 @@ test_files:
|
|
|
256
241
|
- features/ping_as_server.feature
|
|
257
242
|
- features/ping_as_user.feature
|
|
258
243
|
- spec/lib/api_spec.rb
|
|
259
|
-
- spec/lib/das_spec.rb
|
|
260
244
|
- spec/lib/resource_spec.rb
|
|
261
245
|
- spec/lib/role_spec.rb
|
|
262
246
|
- spec/lib/user_spec.rb
|
data/spec/lib/das_spec.rb
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
require 'conjur/api'
|
|
4
|
-
|
|
5
|
-
describe Conjur::API do
|
|
6
|
-
context "data_access_service_url" do
|
|
7
|
-
let(:account) { "the-account" }
|
|
8
|
-
let(:path) { "upload" }
|
|
9
|
-
subject { Conjur::API.data_access_service_url(account, path, params) }
|
|
10
|
-
context "to test environment" do
|
|
11
|
-
before(:each) do
|
|
12
|
-
Conjur.stub(:env).and_return "development"
|
|
13
|
-
end
|
|
14
|
-
context "with empty params" do
|
|
15
|
-
let(:params) { {} }
|
|
16
|
-
it { should == "http://localhost:5200/data/the-account/inscitiv/upload" }
|
|
17
|
-
end
|
|
18
|
-
context "with params" do
|
|
19
|
-
let(:params) { { "foo" => "b/r" } }
|
|
20
|
-
it { should == "http://localhost:5200/data/the-account/inscitiv/upload?foo=b%2Fr" }
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
context "to production environment" do
|
|
24
|
-
before(:each) do
|
|
25
|
-
Conjur.stub(:env).and_return "production"
|
|
26
|
-
end
|
|
27
|
-
context "with empty params" do
|
|
28
|
-
let(:params) { {} }
|
|
29
|
-
it { should == "https://das-v2-conjur.herokuapp.com/data/the-account/inscitiv/upload" }
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|