conjur-api 4.3.0 → 4.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,6 @@
20
20
  #
21
21
  module Conjur
22
22
  class API
23
- VERSION = "4.3.0"
23
+ VERSION = "4.4.0"
24
24
  end
25
25
  end
@@ -18,6 +18,7 @@
18
18
  # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
+ require 'conjur/configuration'
21
22
  require 'conjur/env'
22
23
  require 'conjur/base'
23
24
  require 'conjur/build_from_response'
@@ -0,0 +1,33 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ require 'conjur/deputy'
22
+
23
+ module Conjur
24
+ class API
25
+ def create_deputy options
26
+ standard_create Conjur::Core::API.host, :deputy, nil, options
27
+ end
28
+
29
+ def deputy id
30
+ standard_show Conjur::Core::API.host, :deputy, id
31
+ end
32
+ end
33
+ end
@@ -34,5 +34,15 @@ module Conjur
34
34
  path = [ paths[0], 'resources', paths[1], paths[2..-1].join(':') ].flatten.join('/')
35
35
  Resource.new(Conjur::Authz::API.host, credentials)[path]
36
36
  end
37
+
38
+ # Return all visible resources.
39
+ # In opts you should pass an account to filter by, and optionally a kind.
40
+ def resources opts = {}
41
+ Resource.all({ host: Conjur::Authz::API.host, credentials: credentials }.merge opts).map do |result|
42
+ resource(result['id']).tap do |r|
43
+ r.attributes = result
44
+ end
45
+ end
46
+ end
37
47
  end
38
48
  end
@@ -24,16 +24,7 @@ module Conjur
24
24
  class API < Conjur::API
25
25
  class << self
26
26
  def host
27
- ENV['CONJUR_AUDIT_URL'] || default_host
28
- end
29
-
30
- def default_host
31
- case Conjur.env
32
- when 'test', 'development'
33
- "http://localhost:#{Conjur.service_base_port + 300}"
34
- else
35
- "https://audit-#{Conjur.stack}-conjur.herokuapp.com"
36
- end
27
+ Conjur.configuration.audit_url
37
28
  end
38
29
  end
39
30
  end
@@ -23,16 +23,7 @@ module Conjur
23
23
  class API < Conjur::API
24
24
  class << self
25
25
  def host
26
- ENV['CONJUR_AUTHN_URL'] || default_host
27
- end
28
-
29
- def default_host
30
- case Conjur.env
31
- when 'test', 'development'
32
- "http://localhost:#{Conjur.service_base_port}"
33
- else
34
- "https://authn-#{Conjur.account}-conjur.herokuapp.com"
35
- end
26
+ Conjur.configuration.authn_url
36
27
  end
37
28
  end
38
29
  end
@@ -23,16 +23,7 @@ module Conjur
23
23
  class API < Conjur::API
24
24
  class << self
25
25
  def host
26
- ENV['CONJUR_AUTHZ_URL'] || default_host
27
- end
28
-
29
- def default_host
30
- case Conjur.env
31
- when 'test', 'development'
32
- "http://localhost:#{Conjur.service_base_port + 100}"
33
- else
34
- "https://authz-#{Conjur.stack}-conjur.herokuapp.com"
35
- end
26
+ Conjur.configuration.authz_url
36
27
  end
37
28
  end
38
29
  end
@@ -0,0 +1,166 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ module Conjur
22
+
23
+ class << self
24
+ def configuration
25
+ @config ||= Configuration.new
26
+ end
27
+
28
+ def configuration=(config)
29
+ @config = config
30
+ end
31
+ end
32
+
33
+ class Configuration
34
+ class << self
35
+ # @api private
36
+ def accepted_options
37
+ @options ||= Set.new
38
+ end
39
+
40
+ # @param [Symbol] name
41
+ # @param [Hash] options
42
+ # @option options [Boolean] :boolean (false) whether this option should have a '?' accessor
43
+ # @option options [Boolean, String] :env Environment variable for this option. Set to false
44
+ # to disallow environment based configuration. Default is VM2_OPTION_NAME.
45
+ # @option options [Proc, *] :default Default value or proc to provide it
46
+ # @option options [Boolean] :required (false) when true, raise an exception if the option is
47
+ # not set
48
+ # @option options [Boolean] :sticky (true) when false, default proc will be called every time,
49
+ # otherwise the proc's result will be cached
50
+ # @option options [Proc, #to_proc] :convert proc-ish to convert environment
51
+ # values to appropriate types
52
+ # @param [Proc] def_proc block to provide default values
53
+ # @api private
54
+ def add_option name, options = {}, &def_proc
55
+ accepted_options << name
56
+ allow_env = options[:env].nil? or options[:env]
57
+ sticky = options.member?(:sticky) ? options[:sticky] : true
58
+ env_var = options[:env] || "CONJUR_#{name.to_s.upcase}"
59
+ def_val = options[:default]
60
+ opt_name = name
61
+
62
+ def_proc ||= if def_val.respond_to?(:call)
63
+ def_val
64
+ elsif options[:required]
65
+ proc { raise "Missing required option #{opt_name}" }
66
+ else
67
+ proc { def_val }
68
+ end
69
+
70
+ convert = options[:convert] || ->(x){ x }
71
+ # Allow a Symbol, for example
72
+ convert = convert.to_proc if convert.respond_to?(:to_proc)
73
+
74
+ define_method("#{name}=") do |value|
75
+ set name, value
76
+ end
77
+
78
+ define_method(name) do
79
+ if supplied.member?(name)
80
+ supplied[name]
81
+ elsif allow_env && ENV.member?(env_var)
82
+ instance_exec(ENV[env_var], &convert)
83
+ else
84
+ value = instance_eval(&def_proc)
85
+ supplied[name] = value if sticky
86
+ value
87
+ end
88
+ end
89
+ alias_method("#{name}?", name) if options[:boolean]
90
+ end
91
+ end
92
+
93
+ def set(key, value)
94
+ if self.class.accepted_options.include?(key.to_sym)
95
+ supplied[key.to_sym] = value
96
+ end
97
+ end
98
+
99
+ add_option :authn_url do
100
+ account_service_url 'authn', 0
101
+ end
102
+
103
+ add_option :authz_url do
104
+ global_service_url 'authz', 100
105
+ end
106
+
107
+ add_option :core_url do
108
+ account_service_url 'core', 200
109
+ end
110
+
111
+ add_option :audit_url do
112
+ global_service_url 'audit', 300
113
+ end
114
+
115
+ add_option :service_url
116
+
117
+ add_option :service_base_port, default: 5000
118
+
119
+ add_option :account, required: true
120
+
121
+ add_option :env do
122
+ ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "production"
123
+ end
124
+
125
+ add_option :stack do
126
+ case env
127
+ when "production"
128
+ "v4"
129
+ else
130
+ env
131
+ end
132
+ end
133
+
134
+ private
135
+
136
+ def global_service_url(service_name, service_port_offset)
137
+ if service_url
138
+ URI.join(service_url, service_name).to_s
139
+ else
140
+ case env
141
+ when 'test', 'development'
142
+ "http://localhost:#{service_base_port + service_port_offset}"
143
+ else
144
+ "https://#{service_name}-#{stack}-conjur.herokuapp.com"
145
+ end
146
+ end
147
+ end
148
+
149
+ def account_service_url(service_name, service_port_offset)
150
+ if service_url
151
+ URI.join(service_url, "/#{service_name}/", account).to_s
152
+ else
153
+ case env
154
+ when 'test', 'development'
155
+ "http://localhost:#{service_base_port + service_port_offset}"
156
+ else
157
+ "https://#{service_name}-#{account}-conjur.herokuapp.com"
158
+ end
159
+ end
160
+ end
161
+
162
+ def supplied
163
+ @supplied ||= {}
164
+ end
165
+ end
166
+ end
@@ -30,6 +30,10 @@ module Conjur
30
30
  module Core
31
31
  class API < Conjur::API
32
32
  class << self
33
+ def host
34
+ Conjur.configuration.core_url
35
+ end
36
+
33
37
  def conjur_account
34
38
  info['account'] or raise "No account field in #{info.inspect}"
35
39
  end
@@ -37,24 +41,12 @@ module Conjur
37
41
  def info
38
42
  @info ||= JSON.parse RestClient::Resource.new(Conjur::Core::API.host)['info'].get
39
43
  end
40
-
41
- def host
42
- ENV['CONJUR_CORE_URL'] || default_host
43
- end
44
-
45
- def default_host
46
- case Conjur.env
47
- when 'test', 'development'
48
- "http://localhost:#{Conjur.service_base_port + 200}"
49
- else
50
- "https://core-#{Conjur.account}-conjur.herokuapp.com"
51
- end
52
- end
53
44
  end
54
45
  end
55
46
  end
56
47
  end
57
48
 
49
+ require 'conjur/api/deputies'
58
50
  require 'conjur/api/hosts'
59
51
  require 'conjur/api/secrets'
60
52
  require 'conjur/api/users'
@@ -0,0 +1,38 @@
1
+ #
2
+ # Copyright (C) 2013 Conjur Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ #
21
+ module Conjur
22
+ class Deputy < RestClient::Resource
23
+ include Exists
24
+ include HasId
25
+ include HasIdentifier
26
+ include HasAttributes
27
+ include ActsAsUser
28
+ include ActsAsResource
29
+
30
+ def login
31
+ [ self.class.name.split('::')[-1].downcase, id ].join('/')
32
+ end
33
+
34
+ def api_key
35
+ self.attributes['api_key']
36
+ end
37
+ end
38
+ end
@@ -22,23 +22,18 @@ module Conjur
22
22
  extend self
23
23
 
24
24
  def service_base_port
25
- (ENV['CONJUR_SERVICE_BASE_PORT'] || 5000 ).to_i
25
+ Conjur.configuration.service_base_port
26
26
  end
27
27
 
28
28
  def account
29
- ENV['CONJUR_ACCOUNT'] or raise "No CONJUR_ACCOUNT defined"
29
+ Conjur.configuration.account
30
30
  end
31
31
 
32
32
  def env
33
- ENV['CONJUR_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development"
33
+ Conjur.configuration.env
34
34
  end
35
35
 
36
36
  def stack
37
- ENV['CONJUR_STACK'] || case env
38
- when "production"
39
- "v4"
40
- else
41
- env
42
- end
37
+ Conjur.configuration.stack
43
38
  end
44
39
  end
@@ -19,22 +19,7 @@
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
21
  module Conjur
22
- class Host < RestClient::Resource
23
- include Exists
24
- include HasId
25
- include HasIdentifier
26
- include HasAttributes
27
- include ActsAsUser
28
- include ActsAsResource
29
-
30
- def login
31
- [ 'host', id ].join('/')
32
- end
33
-
34
- def api_key
35
- self.attributes['api_key']
36
- end
37
-
22
+ class Host < Deputy
38
23
  def enrollment_url
39
24
  log do |logger|
40
25
  logger << "Fetching enrollment_url for #{id}"
@@ -103,7 +103,26 @@ module Conjur
103
103
  rescue RestClient::ResourceNotFound
104
104
  false
105
105
  end
106
-
106
+
107
+ # Returns all resources (optionally qualified by kind)
108
+ # visible to the user with given credentials.
109
+ # Options are:
110
+ # - host - authz url,
111
+ # - credentials,
112
+ # - account,
113
+ # - kind (optional).
114
+ def self.all opts = {}
115
+ host, credentials, account, kind = opts.values_at(*[:host, :credentials, :account, :kind])
116
+ fail ArgumentError, "host and account are required" unless [host, account].all?
117
+
118
+ credentials ||= {}
119
+
120
+ path = "#{account}/resources"
121
+ path += "/#{kind}" if kind
122
+ resource = RestClient::Resource.new(host, credentials)[path]
123
+ JSON.parse resource.get
124
+ end
125
+
107
126
  protected
108
127
 
109
128
  def eachable(item)
@@ -16,4 +16,25 @@ describe Conjur::API, api: :dummy do
16
16
  res.url.should == "#{authz_host}/some-account/resources/a-kind/the-id"
17
17
  end
18
18
  end
19
+
20
+ describe '.resources' do
21
+ let(:ids) { %w(acc:kind:foo acc:chunky:bar) }
22
+ let(:resources) {
23
+ ids.map do |id|
24
+ { 'id' => id }
25
+ end
26
+ }
27
+ it "lists all resources" do
28
+ expect(Conjur::Resource).to receive(:all)
29
+ .with(host: authz_host, credentials: api.credentials).and_return(resources)
30
+
31
+ expect(api.resources.map(&:url)).to eql(ids.map { |id| api.resource(id).url })
32
+ end
33
+ it "can filter by kind" do
34
+ expect(Conjur::Resource).to receive(:all)
35
+ .with(host: authz_host, credentials: api.credentials, kind: :chunky).and_return(resources)
36
+
37
+ expect(api.resources(kind: :chunky).map(&:url)).to eql(ids.map { |id| api.resource(id).url })
38
+ end
39
+ end
19
40
  end
@@ -1,33 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  shared_examples_for "API endpoint" do
4
+ before { Conjur.configuration = Conjur::Configuration.new }
4
5
  subject { api }
5
6
  let(:service_name) { api.name.split('::')[-2].downcase }
6
7
  context "in development" do
7
8
  before(:each) do
8
- Conjur.stub(:env).and_return "development"
9
+ Conjur::Configuration.any_instance.stub(:env).and_return "development"
9
10
  end
10
- its "default_host" do
11
- should == "http://localhost:#{Conjur.service_base_port + port_offset}"
11
+ its "host" do
12
+ should == "http://localhost:#{Conjur.configuration.service_base_port + port_offset}"
12
13
  end
13
14
  end
14
15
  context "'ci' account" do
15
16
  before {
16
- Conjur.stub(:account).and_return 'ci'
17
+ Conjur::Configuration.any_instance.stub(:account).and_return 'ci'
17
18
  }
18
19
  context "in stage" do
19
20
  before(:each) do
20
- Conjur.stub(:env).and_return "stage"
21
+ Conjur::Configuration.any_instance.stub(:env).and_return "stage"
21
22
  end
22
- its "default_host" do
23
+ its "host" do
23
24
  should == "https://#{service_name}-ci-conjur.herokuapp.com"
24
25
  end
25
26
  end
26
27
  context "in ci" do
27
28
  before(:each) do
28
- Conjur.stub(:env).and_return "ci"
29
+ Conjur::Configuration.any_instance.stub(:env).and_return "ci"
29
30
  end
30
- its "default_host" do
31
+ its "host" do
31
32
  should == "https://#{service_name}-ci-conjur.herokuapp.com"
32
33
  end
33
34
  end
@@ -111,6 +112,7 @@ describe Conjur::API do
111
112
  end
112
113
 
113
114
  context "host construction" do
115
+ before { Conjur.configuration = Conjur::Configuration.new }
114
116
  context "of authn service" do
115
117
  let(:port_offset) { 0 }
116
118
  let(:api) { Conjur::Authn::API }
@@ -122,15 +124,15 @@ describe Conjur::API do
122
124
  subject { api }
123
125
  context "'ci' account" do
124
126
  before {
125
- Conjur.stub(:account).and_return 'ci'
127
+ Conjur::Configuration.any_instance.stub(:account).and_return 'ci'
126
128
  }
127
129
  context "in stage" do
128
130
  before(:each) do
129
131
  # Looks at "ENV['CONJUR_STACK']" first, stub this out
130
132
  ENV.stub(:[]).with('CONJUR_STACK').and_return nil
131
- Conjur.stub(:env).and_return "stage"
133
+ Conjur::Configuration.any_instance.stub(:env).and_return "stage"
132
134
  end
133
- its "default_host" do
135
+ its "host" do
134
136
  should == "https://authz-stage-conjur.herokuapp.com"
135
137
  end
136
138
  end
@@ -138,36 +140,34 @@ describe Conjur::API do
138
140
  before(:each) do
139
141
  # Looks at "ENV['CONJUR_STACK']" first, stub this out
140
142
  ENV.stub(:[]).with('CONJUR_STACK').and_return nil
141
- Conjur.stub(:env).and_return "ci"
143
+ Conjur::Configuration.any_instance.stub(:env).and_return "ci"
142
144
  end
143
- its "default_host" do
145
+ its "host" do
144
146
  should == "https://authz-ci-conjur.herokuapp.com"
145
147
  end
146
148
  end
147
149
  context "when ENV['CONJUR_STACK'] is set to 'v12'" do
148
150
  before do
149
- ENV.stub(:[]).and_call_original
150
- ENV.stub(:[]).with('CONJUR_STACK').and_return 'v12'
151
- # If the "real" env is used ('test') then the URL is always localhost:<someport>
152
- Conjur.stub(:env).and_return "ci"
151
+ Conjur::Configuration.any_instance.stub(:stack).and_return "v12"
152
+ Conjur::Configuration.any_instance.stub(:env).and_return "ci"
153
153
  end
154
- its(:default_host){ should == "https://authz-v12-conjur.herokuapp.com"}
154
+ its(:host){ should == "https://authz-v12-conjur.herokuapp.com"}
155
155
  end
156
156
  end
157
157
  context "in production" do
158
158
  before(:each) do
159
- Conjur.stub(:env).and_return "production"
159
+ Conjur::Configuration.any_instance.stub(:env).and_return "production"
160
160
  end
161
- its "default_host" do
161
+ its "host" do
162
162
  should == "https://authz-v4-conjur.herokuapp.com"
163
163
  end
164
164
  end
165
165
  context "in named production version" do
166
166
  before(:each) do
167
- Conjur.stub(:env).and_return "production"
168
- Conjur.stub(:stack).and_return "waffle"
167
+ Conjur::Configuration.any_instance.stub(:env).and_return "production"
168
+ Conjur::Configuration.any_instance.stub(:stack).and_return "waffle"
169
169
  end
170
- its "default_host" do
170
+ its "host" do
171
171
  should == "https://authz-waffle-conjur.herokuapp.com"
172
172
  end
173
173
  end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conjur::Configuration do
4
+ before {
5
+ Conjur.configuration = Conjur::Configuration.new
6
+ }
7
+ subject { Conjur.configuration }
8
+ context "CONJUR_ENV unspecified" do
9
+ before(:all) {
10
+ ENV.delete('CONJUR_ENV')
11
+ }
12
+ after(:all) {
13
+ ENV['CONJUR_ENV'] = 'test'
14
+ }
15
+ context "default env" do
16
+ its(:env) { should == "production" }
17
+ end
18
+ context "default stack" do
19
+ its(:stack) { should == "v4" }
20
+ end
21
+ describe 'authn_url' do
22
+ before {
23
+ Conjur::Configuration.any_instance.stub(:account).and_return "the-account"
24
+ }
25
+ context "with service_url" do
26
+ before {
27
+ Conjur::Configuration.any_instance.stub(:service_url).and_return "http://example.com"
28
+ }
29
+ its(:authn_url) { should == "http://example.com/authn/the-account" }
30
+ end
31
+ context "without service_url" do
32
+ its(:authn_url) { should == "https://authn-the-account-conjur.herokuapp.com" }
33
+ end
34
+ end
35
+ describe 'authz_url' do
36
+ before {
37
+ Conjur::Configuration.any_instance.stub(:account).and_return "the-account"
38
+ }
39
+ context "with service_url" do
40
+ before {
41
+ Conjur::Configuration.any_instance.stub(:service_url).and_return "http://example.com"
42
+ }
43
+ its(:authz_url) { should == "http://example.com/authz" }
44
+ end
45
+ context "without service_url" do
46
+ its(:authz_url) { should == "https://authz-v4-conjur.herokuapp.com" }
47
+ context "with specific stack" do
48
+ before { Conjur::Configuration.any_instance.stub(:stack).and_return "the-stack" }
49
+ its(:authz_url) { should == "https://authz-the-stack-conjur.herokuapp.com" }
50
+ end
51
+ end
52
+ end
53
+ end
54
+ context "CONJUR_ENV = 'test'" do
55
+ its(:env) { should == "test" }
56
+ describe 'authn_url' do
57
+ before {
58
+ Conjur::Configuration.any_instance.stub(:account).and_return "the-account"
59
+ }
60
+ context "with service_url" do
61
+ before {
62
+ Conjur::Configuration.any_instance.stub(:service_url).and_return "http://example.com"
63
+ }
64
+ its(:authn_url) { should == "http://example.com/authn/the-account" }
65
+ end
66
+ context "without service_url" do
67
+ its(:authn_url) { should == "http://localhost:5000" }
68
+ end
69
+ end
70
+ describe 'authz_url' do
71
+ before {
72
+ Conjur::Configuration.any_instance.stub(:account).and_return "the-account"
73
+ }
74
+ context "with service_url" do
75
+ before {
76
+ Conjur::Configuration.any_instance.stub(:service_url).and_return "http://example.com"
77
+ }
78
+ its(:authz_url) { should == "http://example.com/authz" }
79
+ end
80
+ context "without service_url" do
81
+ its(:authz_url) { should == "http://localhost:5100" }
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Conjur::Deputy, api: :dummy do
4
+ subject { Conjur::Deputy.new 'http://example.com/deputies/my/hostname', nil }
5
+
6
+ its(:resource) { should be }
7
+ its(:login) { should == 'deputy/my/hostname' }
8
+
9
+ let(:api_key) { 'theapikey' }
10
+ before { subject.attributes = { 'api_key' => api_key } }
11
+ its(:api_key) { should == api_key }
12
+ end
@@ -6,10 +6,6 @@ describe Conjur::Host, api: :dummy do
6
6
  its(:resource) { should be }
7
7
  its(:login) { should == 'host/my/hostname' }
8
8
 
9
- let(:api_key) { 'theapikey' }
10
- before { subject.attributes = { 'api_key' => api_key } }
11
- its(:api_key) { should == api_key }
12
-
13
9
  it "fetches enrollment_url" do
14
10
  stub_request(:head, "http://example.com/hosts/my/hostname/enrollment_url").
15
11
  to_return(:status => 200, :headers => {location: 'foo'})
@@ -126,4 +126,37 @@ describe Conjur::Resource, api: :dummy, logging: :temp do
126
126
  subject.permitted? 'fry'
127
127
  end
128
128
  end
129
+
130
+ describe '.all' do
131
+ it "calls /account/resources" do
132
+ RestClient::Request.should_receive(:execute).with(
133
+ method: :get,
134
+ url: "http://authz.example.com/the-account/resources",
135
+ headers: {}
136
+ ).and_return '["foo", "bar"]'
137
+
138
+ expect(Conjur::Resource.all host: authz_host, account: account).to eql(%w(foo bar))
139
+ end
140
+
141
+ it "can filter by kind" do
142
+ RestClient::Request.should_receive(:execute).with(
143
+ method: :get,
144
+ url: "http://authz.example.com/the-account/resources/chunky",
145
+ headers: {}
146
+ ).and_return '["foo", "bar"]'
147
+
148
+ expect(Conjur::Resource.all host: authz_host, account: account, kind: :chunky)
149
+ .to eql(%w(foo bar))
150
+ end
151
+
152
+ it "uses the given authz url" do
153
+ RestClient::Request.should_receive(:execute).with(
154
+ method: :get,
155
+ url: "http://otherhost.example.com/the-account/resources",
156
+ headers: {}
157
+ ).and_return '["foo", "bar"]'
158
+
159
+ Conjur::Resource.all host: 'http://otherhost.example.com', account: account
160
+ end
161
+ end
129
162
  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: 4.3.0
4
+ version: 4.4.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: 2013-11-19 00:00:00.000000000 Z
13
+ date: 2013-12-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -217,6 +217,7 @@ files:
217
217
  - lib/conjur/api.rb
218
218
  - lib/conjur/api/audit.rb
219
219
  - lib/conjur/api/authn.rb
220
+ - lib/conjur/api/deputies.rb
220
221
  - lib/conjur/api/groups.rb
221
222
  - lib/conjur/api/hosts.rb
222
223
  - lib/conjur/api/resources.rb
@@ -229,7 +230,9 @@ files:
229
230
  - lib/conjur/authz-api.rb
230
231
  - lib/conjur/base.rb
231
232
  - lib/conjur/build_from_response.rb
233
+ - lib/conjur/configuration.rb
232
234
  - lib/conjur/core-api.rb
235
+ - lib/conjur/deputy.rb
233
236
  - lib/conjur/env.rb
234
237
  - lib/conjur/escape.rb
235
238
  - lib/conjur/exists.rb
@@ -262,6 +265,8 @@ files:
262
265
  - spec/lib/asset_spec.rb
263
266
  - spec/lib/audit_spec.rb
264
267
  - spec/lib/build_from_response_spec.rb
268
+ - spec/lib/configuration_spec.rb
269
+ - spec/lib/deputy_spec.rb
265
270
  - spec/lib/exists_spec.rb
266
271
  - spec/lib/host_spec.rb
267
272
  - spec/lib/log_source_spec.rb
@@ -299,7 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
299
304
  version: '0'
300
305
  segments:
301
306
  - 0
302
- hash: 1370688255515528538
307
+ hash: 3244723837953791122
303
308
  requirements: []
304
309
  rubyforge_project:
305
310
  rubygems_version: 1.8.25
@@ -324,6 +329,8 @@ test_files:
324
329
  - spec/lib/asset_spec.rb
325
330
  - spec/lib/audit_spec.rb
326
331
  - spec/lib/build_from_response_spec.rb
332
+ - spec/lib/configuration_spec.rb
333
+ - spec/lib/deputy_spec.rb
327
334
  - spec/lib/exists_spec.rb
328
335
  - spec/lib/host_spec.rb
329
336
  - spec/lib/log_source_spec.rb