conjur-api 4.31.0 → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +1 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +22 -3
  5. data/Dockerfile +12 -3
  6. data/Gemfile +3 -3
  7. data/Jenkinsfile +69 -0
  8. data/LICENSE.md +195 -0
  9. data/README.md +16 -0
  10. data/Rakefile +34 -18
  11. data/ci/wait_for_server.sh +10 -0
  12. data/conjur-api.gemspec +6 -14
  13. data/dev/docker-compose.yml +23 -0
  14. data/dev/empty.yml +2 -0
  15. data/dev/start.sh +15 -0
  16. data/dev/stop.sh +6 -0
  17. data/docker-compose.yml +27 -0
  18. data/features/exists.feature +37 -0
  19. data/features/group.feature +11 -0
  20. data/features/host.feature +20 -0
  21. data/features/host_factory_create_host.feature +28 -0
  22. data/features/host_factory_token.feature +63 -0
  23. data/features/load_policy.feature +61 -0
  24. data/features/members.feature +51 -0
  25. data/features/new_api.feature +36 -0
  26. data/features/permitted.feature +43 -0
  27. data/features/permitted_roles.feature +30 -0
  28. data/features/public_keys.feature +11 -0
  29. data/features/resource_fields.feature +53 -0
  30. data/features/role_fields.feature +15 -0
  31. data/features/rotate_api_key.feature +13 -0
  32. data/features/step_definitions/api_steps.rb +4 -54
  33. data/features/step_definitions/policy_steps.rb +35 -0
  34. data/features/step_definitions/result_steps.rb +7 -0
  35. data/features/support/env.rb +14 -5
  36. data/features/support/hooks.rb +3 -0
  37. data/features/support/world.rb +5 -6
  38. data/features/update_password.feature +14 -0
  39. data/features/user.feature +17 -0
  40. data/features/variable_fields.feature +20 -0
  41. data/features/variable_value.feature +67 -0
  42. data/lib/conjur/acts_as_resource.rb +95 -65
  43. data/lib/conjur/acts_as_role.rb +102 -51
  44. data/lib/conjur/{audit-api.rb → acts_as_rolsource.rb} +10 -14
  45. data/lib/conjur/acts_as_user.rb +13 -22
  46. data/lib/conjur/api/authn.rb +37 -72
  47. data/lib/conjur/api/host_factories.rb +35 -55
  48. data/lib/conjur/api/policies.rb +56 -0
  49. data/lib/conjur/api/pubkeys.rb +36 -160
  50. data/lib/conjur/api/resources.rb +32 -116
  51. data/lib/conjur/api/roles.rb +28 -105
  52. data/lib/conjur/api/variables.rb +22 -91
  53. data/lib/conjur/api.rb +19 -46
  54. data/lib/conjur/base.rb +21 -132
  55. data/lib/conjur/base_object.rb +57 -0
  56. data/lib/conjur/{authn-api.rb → build_object.rb} +23 -11
  57. data/lib/conjur/cast.rb +12 -17
  58. data/lib/conjur/cert_utils.rb +1 -1
  59. data/lib/conjur/cidr.rb +1 -1
  60. data/lib/conjur/configuration.rb +13 -91
  61. data/lib/conjur/escape.rb +1 -2
  62. data/lib/conjur/group.rb +9 -65
  63. data/lib/conjur/has_attributes.rb +22 -59
  64. data/lib/conjur/host.rb +5 -35
  65. data/lib/conjur/host_factory.rb +40 -40
  66. data/lib/conjur/host_factory_token.rb +38 -23
  67. data/lib/conjur/id.rb +63 -0
  68. data/lib/conjur/layer.rb +5 -80
  69. data/lib/conjur/log.rb +1 -1
  70. data/lib/conjur/log_source.rb +1 -1
  71. data/lib/conjur/{secret.rb → policy.rb} +11 -14
  72. data/lib/conjur/{api/secrets.rb → policy_load_result.rb} +35 -22
  73. data/lib/conjur/query_string.rb +2 -1
  74. data/lib/conjur/resource.rb +5 -299
  75. data/lib/conjur/role.rb +5 -317
  76. data/lib/conjur/role_grant.rb +20 -28
  77. data/lib/conjur/user.rb +5 -63
  78. data/lib/conjur/variable.rb +31 -76
  79. data/lib/conjur/{authz-api.rb → webservice.rb} +8 -16
  80. data/lib/conjur-api/version.rb +2 -2
  81. data/publish.sh +7 -0
  82. data/spec/api_spec.rb +208 -0
  83. data/spec/cast_spec.rb +21 -0
  84. data/spec/{lib/cert_utils_spec.rb → cert_utils_spec.rb} +0 -0
  85. data/spec/{lib/cidr_spec.rb → cidr_spec.rb} +0 -0
  86. data/spec/{lib/configuration_spec.rb → configuration_spec.rb} +40 -140
  87. data/spec/{lib/has_attributes_spec.rb → has_attributes_spec.rb} +6 -2
  88. data/spec/{lib/log_source_spec.rb → log_source_spec.rb} +0 -0
  89. data/spec/{lib/log_spec.rb → log_spec.rb} +0 -0
  90. data/spec/roles_spec.rb +24 -0
  91. data/spec/spec_helper.rb +63 -78
  92. data/spec/ssl_spec.rb +3 -5
  93. data/spec/vendor/rest_client_spec.rb +0 -54
  94. data/test.sh +40 -0
  95. metadata +122 -281
  96. data/.kateproject +0 -5
  97. data/LICENSE +0 -22
  98. data/ci/test.sh +0 -9
  99. data/features/audit_resources.feature +0 -15
  100. data/features/audit_roles.feature +0 -15
  101. data/features/bootstrap.feature +0 -31
  102. data/features/step_definitions/cli_steps.rb +0 -5
  103. data/jenkins.sh +0 -27
  104. data/lib/conjur/acts_as_asset.rb +0 -88
  105. data/lib/conjur/annotations.rb +0 -186
  106. data/lib/conjur/api/audit.rb +0 -138
  107. data/lib/conjur/api/deputies.rb +0 -57
  108. data/lib/conjur/api/groups.rb +0 -111
  109. data/lib/conjur/api/hosts.rb +0 -109
  110. data/lib/conjur/api/info.rb +0 -126
  111. data/lib/conjur/api/layers.rb +0 -62
  112. data/lib/conjur/api/ldapsync.rb +0 -115
  113. data/lib/conjur/api/users.rb +0 -106
  114. data/lib/conjur/bootstrap.rb +0 -161
  115. data/lib/conjur/build_from_response.rb +0 -49
  116. data/lib/conjur/core-api.rb +0 -74
  117. data/lib/conjur/deputy.rb +0 -55
  118. data/lib/conjur/env.rb +0 -54
  119. data/lib/conjur/event_source.rb +0 -101
  120. data/lib/conjur/exists.rb +0 -60
  121. data/lib/conjur/graph.rb +0 -295
  122. data/lib/conjur/has_id.rb +0 -43
  123. data/lib/conjur/has_identifier.rb +0 -36
  124. data/lib/conjur/has_owner.rb +0 -51
  125. data/lib/conjur/host-factory-api.rb +0 -38
  126. data/lib/conjur/layer-api.rb +0 -13
  127. data/lib/conjur/ldap_sync_job.rb +0 -89
  128. data/lib/conjur/path_based.rb +0 -86
  129. data/lib/conjur/pubkeys-api.rb +0 -50
  130. data/lib/conjur/standard_methods.rb +0 -91
  131. data/reqspeed.rb +0 -20
  132. data/spec/api/authn_spec.rb +0 -81
  133. data/spec/api/graph_spec.rb +0 -117
  134. data/spec/api/groups_spec.rb +0 -40
  135. data/spec/api/hosts_spec.rb +0 -36
  136. data/spec/api/info_spec.rb +0 -89
  137. data/spec/api/layer_spec.rb +0 -18
  138. data/spec/api/ldapsync_spec.rb +0 -44
  139. data/spec/api/pubkeys_spec.rb +0 -66
  140. data/spec/api/resources_spec.rb +0 -92
  141. data/spec/api/roles_spec.rb +0 -100
  142. data/spec/api/secrets_spec.rb +0 -16
  143. data/spec/api/users_spec.rb +0 -71
  144. data/spec/api/variables_spec.rb +0 -112
  145. data/spec/cas_rest_client.rb +0 -17
  146. data/spec/cidr_helper.rb +0 -24
  147. data/spec/lib/acts_as_user_spec.rb +0 -27
  148. data/spec/lib/annotations_spec.rb +0 -109
  149. data/spec/lib/api_spec.rb +0 -480
  150. data/spec/lib/asset_spec.rb +0 -80
  151. data/spec/lib/audit_spec.rb +0 -155
  152. data/spec/lib/build_from_response_spec.rb +0 -49
  153. data/spec/lib/deputy_spec.rb +0 -25
  154. data/spec/lib/exists_spec.rb +0 -24
  155. data/spec/lib/group_spec.rb +0 -18
  156. data/spec/lib/host_spec.rb +0 -31
  157. data/spec/lib/resource_spec.rb +0 -240
  158. data/spec/lib/role_grant_spec.rb +0 -13
  159. data/spec/lib/role_spec.rb +0 -231
  160. data/spec/lib/standard_methods_spec.rb +0 -66
  161. data/spec/lib/user_spec.rb +0 -77
  162. data/spec/standard_methods_helper.rb +0 -41
  163. data/spec/variable_spec.rb +0 -101
  164. data/spec/vcr_cassettes/Conjur_Resource/_create/with_path-like_identifier.yml +0 -87
  165. data/spec/vcr_cassettes/Conjur_Resource/_create/with_un-encoded_path-like_identifier.yml +0 -87
  166. data/spec/vcr_cassettes/Conjur_Resource/_create/with_uuid_identifier.yml +0 -87
data/lib/conjur/base.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2013-2016 Conjur Inc
2
+ # Copyright 2013-2017 Conjur Inc
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
5
  # this software and associated documentation files (the "Software"), to deal in
@@ -19,19 +19,16 @@
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
21
  require 'rest-client'
22
+ require 'active_support'
23
+ require 'active_support/core_ext'
22
24
  require 'json'
23
25
  require 'base64'
24
26
 
25
27
  require 'conjur/query_string'
26
- require 'conjur/exists'
27
28
  require 'conjur/has_attributes'
28
- require 'conjur/has_owner'
29
- require 'conjur/path_based'
30
29
  require 'conjur/escape'
31
30
  require 'conjur/log'
32
31
  require 'conjur/log_source'
33
- require 'conjur/standard_methods'
34
- require 'conjur/cast'
35
32
 
36
33
  module Conjur
37
34
  # NOTE: You have to put all 'class level' api docs here, because YARD is stoopid :-(
@@ -40,55 +37,8 @@ module Conjur
40
37
  class API
41
38
  include Escape
42
39
  include LogSource
43
- include StandardMethods
44
- include Cast
45
40
 
46
41
  class << self
47
- # @api private
48
- # Parse a role id into [ account, 'roles', kind, id ]
49
- def parse_role_id(id)
50
- id = id.role if id.respond_to?(:role)
51
- if id.is_a?(Role)
52
- [ id.account, 'roles', id.kind, id.identifier ]
53
- elsif id.respond_to?(:role_kind)
54
- [ Conjur::Core::API.conjur_account, 'roles', id.role_kind, id.identifier ]
55
- else
56
- parse_id id, 'roles'
57
- end
58
- end
59
-
60
- # @api private
61
- # Parse a resource id into [ account, 'resources', kind, id ]
62
- def parse_resource_id(id)
63
- id = id.resource if id.respond_to?(:resource)
64
- if id.is_a?(Resource)
65
- [ id.account, 'resources', id.kind, id.identifier ]
66
- elsif id.respond_to?(:resource_kind)
67
- [ Conjur::Core::API.conjur_account, 'resources', id.resource_kind, id.resource_id ]
68
- else
69
- parse_id id, 'resources'
70
- end
71
- end
72
-
73
- # @api private
74
- # Converts flat id into path components, with mixed-in "super-kind"
75
- # (not that kind which is part of id)
76
- # NOTE: name is a bit confusing, as result of 'parse' is just recombined
77
- # representation of parts, not an object of higher abstraction level
78
- def parse_id(id, kind)
79
- # Structured IDs (hashes) are no more supported
80
- raise "Unexpected class #{id.class} for #{id}" unless id.is_a?(String)
81
- paths = path_escape(id).split(':')
82
- if paths.size < 2
83
- raise "Expecting at least two tokens in #{id}"
84
- elsif paths.size == 2
85
- paths.unshift Conjur::Core::API.conjur_account
86
- end
87
- # I would strongly recommend to encapsulate this into object
88
- [ paths[0], kind, paths[1], paths[2..-1].join(':') ]
89
- end
90
-
91
-
92
42
  # Create a new {Conjur::API} instance from a username and a password or api key.
93
43
  #
94
44
  # @example Create an API with valid credentials
@@ -103,16 +53,15 @@ module Conjur
103
53
  # @param [String] username the username to use when making authenticated requests.
104
54
  # @param [String] api_key the api key or password for `username`
105
55
  # @param [String] remote_ip the optional IP address to be recorded in the audit record.
56
+ # @param [String] account The organization account.
106
57
  # @return [Conjur::API] an api that will authenticate with the given username and api key.
107
- def new_from_key(username, api_key, remote_ip = nil)
108
- self.new.init_from_key username, api_key, remote_ip
58
+ def new_from_key username, api_key, remote_ip: nil, account: Conjur.configuration.account
59
+ self.new.init_from_key username, api_key, remote_ip: remote_ip, account: account
109
60
  end
110
61
 
111
-
112
- # Create a new {Conjur::API} instance from a token issued by the
113
- # {http://developer.conjur.net/reference/services/authentication Conjur authentication service}
62
+ # Create a new {Conjur::API} instance from an access token.
114
63
  #
115
- # Generally, you will have a Conjur identitiy (username and api key), and create an {Conjur::API} instance
64
+ # Generally, you will have a Conjur identitiy (username and API key), and create an {Conjur::API} instance
116
65
  # for the identity using {.new_from_key}. This method is useful when you are performing authorization checks
117
66
  # given a token. For example, a Conjur gateway that requires you to prove that you can 'read' a resource named
118
67
  # 'super-secret' might get the token from a request header, create an {Conjur::API} instance with this method,
@@ -134,8 +83,8 @@ module Conjur
134
83
  # @param [Hash] token the authentication token as parsed JSON to use when making authenticated requests
135
84
  # @param [String] remote_ip the optional IP address to be recorded in the audit record.
136
85
  # @return [Conjur::API] an api that will authenticate with the token
137
- def new_from_token(token, remote_ip = nil)
138
- self.new.init_from_token token, remote_ip
86
+ def new_from_token token, remote_ip: nil
87
+ self.new.init_from_token token, remote_ip: remote_ip
139
88
  end
140
89
 
141
90
  # Create a new {Conjur::API} instance from a file containing a token issued by the
@@ -149,18 +98,9 @@ module Conjur
149
98
  # @param [String] token_file the file path containing an authentication token as parsed JSON.
150
99
  # @param [String] remote_ip the optional IP address to be recorded in the audit record.
151
100
  # @return [Conjur::API] an api that will authenticate with the tokens provided in the file.
152
- def new_from_token_file(token_file, remote_ip = nil)
153
- self.new.init_from_token_file token_file, remote_ip
154
- end
155
-
156
- def encode_audit_ids(ids)
157
- ids.collect{|id| CGI::escape(id)}.join('&')
158
- end
159
-
160
- def decode_audit_ids(ids)
161
- ids.split('&').collect{|id| CGI::unescape(id)}
101
+ def new_from_token_file token_file, remote_ip: nil
102
+ self.new.init_from_token_file token_file, remote_ip: remote_ip
162
103
  end
163
-
164
104
  end
165
105
 
166
106
  #@!attribute [r] api_key
@@ -173,37 +113,14 @@ module Conjur
173
113
  # An optional IP address to be recorded in the audit record for any actions performed by this API instance.
174
114
  attr_reader :remote_ip
175
115
 
176
- #@!attribute [rw] privilege
177
- # The optional global privilege (e.g. 'elevate' or 'reveal') which should be attempted on the request.
178
- attr_accessor :privilege
179
-
180
- #@!attribute [rw] audit_roles
181
- # An array of role ids that should be included in any audit
182
- # records generated by requsts made by this instance of the api.
183
- attr_accessor :audit_roles
184
-
185
- #@!attribute [rw] audit_resources
186
- # An array of resource ids that should be included in any audit
187
- # records generated by requsts made by this instance of the api.
188
- attr_accessor :audit_resources
189
-
190
116
  # The name of the user as which this api instance is authenticated. This is available whether the api
191
117
  # instance was created from credentials or an authentication token.
192
118
  #
193
119
  # @return [String] the login of the current user.
194
120
  def username
195
- @username || @token['data']
121
+ @username || token['data']
196
122
  end
197
123
 
198
- # Perform all commands in Conjur::Bootstrap::Command.
199
- def bootstrap listener
200
- Conjur::Bootstrap::Command.constants.map{|c| Conjur::Bootstrap::Command.const_get(c)}.each do |cls|
201
- next unless cls.is_a?(Class)
202
- next unless cls.superclass == Conjur::Bootstrap::Command::Base
203
- cls.new(self, listener).perform
204
- end
205
- end
206
-
207
124
  # @api private
208
125
  # used to delegate to host providing subclasses.
209
126
  # @return [String] the host
@@ -227,43 +144,14 @@ module Conjur
227
144
  #
228
145
  # @return [Hash] the options.
229
146
  # @raise [RestClient::Unauthorized] if fetching the token fails.
230
- # @see {#token}
231
147
  def credentials
232
148
  headers = {}.tap do |h|
233
149
  h[:authorization] = "Token token=\"#{Base64.strict_encode64 token.to_json}\""
234
- h[:x_conjur_privilege] = @privilege if @privilege
235
150
  h[:x_forwarded_for] = @remote_ip if @remote_ip
236
- h[:conjur_audit_roles] = Conjur::API.encode_audit_ids(@audit_roles) if @audit_roles
237
- h[:conjur_audit_resources] = Conjur::API.encode_audit_ids(@audit_resources) if @audit_resources
238
151
  end
239
152
  { headers: headers, username: username }
240
153
  end
241
154
 
242
- # Return a new API object with the specified X-Conjur-Privilege.
243
- #
244
- # @return The API instance.
245
- def with_privilege privilege
246
- self.clone.tap do |api|
247
- api.privilege = privilege
248
- end
249
- end
250
-
251
- def with_audit_roles role_ids
252
- role_ids = Array(role_ids)
253
- self.clone.tap do |api|
254
- # Ensure that all role ids are fully qualified
255
- api.audit_roles = role_ids.collect { |id| api.role(id).roleid }
256
- end
257
- end
258
-
259
- def with_audit_resources resource_ids
260
- resource_ids = Array(resource_ids)
261
- self.clone.tap do |api|
262
- # Ensure that all resource ids are fully qualified
263
- api.audit_resources = resource_ids.collect { |id| api.resource(id).resourceid }
264
- end
265
- end
266
-
267
155
  module MonotonicTime
268
156
  def monotonic_time
269
157
  Process.clock_gettime Process::CLOCK_MONOTONIC
@@ -297,16 +185,17 @@ module Conjur
297
185
  class APIKeyAuthenticator
298
186
  include TokenExpiration
299
187
 
300
- attr_reader :username, :api_key
188
+ attr_reader :account, :username, :api_key
301
189
 
302
- def initialize username, api_key
190
+ def initialize account, username, api_key
191
+ @account = account
303
192
  @username = username
304
193
  @api_key = api_key
305
194
  update_token_born
306
195
  end
307
196
 
308
197
  def refresh_token
309
- Conjur::API.authenticate(username, api_key).tap do
198
+ Conjur::API.authenticate(username, api_key, account: account).tap do
310
199
  update_token_born
311
200
  end
312
201
  end
@@ -366,22 +255,22 @@ module Conjur
366
255
  end
367
256
  end
368
257
 
369
- def init_from_key username, api_key, remote_ip = nil
258
+ def init_from_key username, api_key, remote_ip: nil, account: Conjur.configuration.account
370
259
  @username = username
371
260
  @api_key = api_key
372
261
  @remote_ip = remote_ip
373
- @authenticator = APIKeyAuthenticator.new(username, api_key)
262
+ @authenticator = APIKeyAuthenticator.new(account, username, api_key)
374
263
  self
375
264
  end
376
265
 
377
- def init_from_token token, remote_ip = nil
266
+ def init_from_token token, remote_ip: nil
378
267
  @token = token
379
268
  @remote_ip = remote_ip
380
269
  @authenticator = UnableAuthenticator.new
381
270
  self
382
271
  end
383
272
 
384
- def init_from_token_file token_file, remote_ip = nil
273
+ def init_from_token_file token_file, remote_ip: nil
385
274
  @remote_ip = remote_ip
386
275
  @authenticator = TokenFileAuthenticator.new(token_file)
387
276
  self
@@ -0,0 +1,57 @@
1
+ #
2
+ # Copyright 2013-2017 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/cast'
22
+
23
+ module Conjur
24
+ class BaseObject
25
+ include Cast
26
+ include QueryString
27
+ include LogSource
28
+ include BuildObject
29
+
30
+ attr_reader :id, :credentials
31
+
32
+ def initialize id, credentials
33
+ @id = cast_to_id(id)
34
+ @credentials = credentials
35
+ end
36
+
37
+ def as_json options={}
38
+ {
39
+ id: id.to_s
40
+ }
41
+ end
42
+
43
+ def account; id.account; end
44
+ def kind; id.kind; end
45
+ def identifier; id.identifier; end
46
+
47
+ def username
48
+ credentials[:username] or raise "No username found in credentials"
49
+ end
50
+
51
+ protected
52
+
53
+ def core_resource
54
+ RestClient::Resource.new(Conjur.configuration.core_url, credentials)
55
+ end
56
+ end
57
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2013 Conjur Inc
2
+ # Copyright 2013-2017 Conjur Inc
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
5
  # this software and associated documentation files (the "Software"), to deal in
@@ -18,20 +18,32 @@
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/cast'
22
+
21
23
  module Conjur
22
- module Authn
23
- class API < Conjur::API
24
- class << self
24
+ module BuildObject
25
+ def self.included base
26
+ base.module_eval do
27
+ extend Cast
28
+ extend ClassMethods
29
+ end
30
+ end
25
31
 
26
- # The URL for the audit service
27
- #
28
- # @return [String] the audit service url.
29
- def host
30
- Conjur.configuration.authn_url
32
+ module ClassMethods
33
+ def build_object id, credentials, default_class:
34
+ id = cast_to_id(id)
35
+ class_name = id.kind.classify.to_sym
36
+ cls = if Conjur.constants.member?(class_name)
37
+ Conjur.const_get(class_name)
38
+ else
39
+ default_class
31
40
  end
41
+ cls.new(id, credentials)
32
42
  end
33
43
  end
44
+
45
+ def build_object id, default_class: Resource
46
+ self.class.build_object id, credentials, default_class: default_class
47
+ end
34
48
  end
35
49
  end
36
-
37
- require 'conjur/api/authn'
data/lib/conjur/cast.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2013 Conjur Inc
2
+ # Copyright 2013-2017 Conjur Inc
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
5
  # this software and associated documentation files (the "Software"), to deal in
@@ -18,29 +18,24 @@
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
+
21
22
  module Conjur
22
23
  module Cast
23
24
  protected
24
25
 
25
26
  # Convert a value to a role or resource identifier.
26
27
  #
27
- # @param [String, Array, #roleid, #resourceid] obj the value to cast
28
- # @param [Symbol] kind must be either `:roleid` or `:resourceid`
29
- def cast(obj, kind)
30
- case kind
31
- when :roleid, :resourceid
32
- if obj.is_a?(String)
33
- obj
34
- elsif obj.is_a?(Array)
35
- obj.join(':')
36
- elsif obj.respond_to?(kind)
37
- obj.send(kind)
38
- else
39
- raise "I don't know how to cast a #{obj.class} to a #{kind}"
40
- end
28
+ # @param obj the value to cast
29
+ def cast_to_id obj
30
+ result =if obj.is_a?(String) || obj.is_a?(Id)
31
+ obj
32
+ elsif obj.is_a?(Array)
33
+ obj.join(':')
41
34
  else
42
- raise "I don't know how to convert things to a #{kind}"
35
+ raise "I don't know how to cast a #{obj.class} to an id"
43
36
  end
37
+ result = Id.new(result) unless result.is_a?(Id)
38
+ result
44
39
  end
45
40
  end
46
- end
41
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2015 Conjur Inc
2
+ # Copyright 2013-2017 Conjur Inc
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
5
  # this software and associated documentation files (the "Software"), to deal in
data/lib/conjur/cidr.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2015 Conjur Inc
2
+ # Copyright 2013-2017 Conjur Inc
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
5
  # this software and associated documentation files (the "Software"), to deal in
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2013-2015 Conjur Inc
2
+ # Copyright 2013-2017 Conjur Inc
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
5
  # this software and associated documentation files (the "Software"), to deal in
@@ -287,53 +287,31 @@ module Conjur
287
287
  end
288
288
 
289
289
  # @!attribute authn_url
290
+ #
290
291
  # The url for the {http://developer.conjur.net/reference/services/authentication Conjur authentication service}.
291
292
  #
292
- # @note You should not generally set this value. Instead, Conjur will derive it from the
293
- # {Conjur::Configuration#account} and {Conjur::Configuration#appliance_url}
294
- # properties.
293
+ # By default, this will be built from the +appliance_url+. To use a custom authenticator,
294
+ # set this option in code or set `CONJUR_AUTHN_URL`.
295
+ #
295
296
  #
296
297
  # @return [String] the authentication service url
297
298
  add_option :authn_url do
298
- account_service_url 'authn', 0
299
- end
300
-
301
- # @!attribute authz_url
302
- # The url for the {http://developer.conjur.net/reference/services/authorization Conjur authorization service}.
303
- #
304
- # @note You should not generally set this value. Instead, Conjur will derive it from the
305
- # {Conjur::Configuration#account} and {Conjur::Configuration#appliance_url}
306
- # properties.
307
- #
308
- # @return [String] the authorization service url
309
- add_option :authz_url do
310
- global_service_url 'authz', 100
299
+ global_service_url 0, service_name: 'authn'
311
300
  end
312
301
 
313
302
  # @!attribute core_url
314
- # The url for the {http://developer.conjur.net/reference/services/directory Conjur core/directory service}.
303
+ #
304
+ # The url for the core Conjur services.
315
305
  #
316
306
  # @note You should not generally set this value. Instead, Conjur will derive it from the
317
307
  # {Conjur::Configuration#account} and {Conjur::Configuration#appliance_url}
318
308
  # properties.
319
309
  #
320
- # @return [String] the core/directory service url
310
+ # @return [String] the base service url
321
311
  add_option :core_url do
322
- default_service_url 'core', 200
312
+ global_service_url 0
323
313
  end
324
314
 
325
- # @!attribute audit_url
326
- # The url for the {http://developer.conjur.net/reference/services/audit Conjur audit service}.
327
- #
328
- # @note You should not generally set this value. Instead, Conjur will derive it from the
329
- # {Conjur::Configuration#account} and {Conjur::Configuration#appliance_url}
330
- # properties.
331
- #
332
- # @return [String] the audit service url
333
- add_option :audit_url do
334
- global_service_url 'audit', 300
335
- end
336
-
337
315
  # @!attribute appliance_url
338
316
  # The url for your Conjur appliance.
339
317
  #
@@ -368,28 +346,6 @@ module Conjur
368
346
  # @return [String]
369
347
  add_option :account, required: true
370
348
 
371
-
372
- # @!attribute env
373
- #
374
- # The type of environment your program is running in (e.g., `development`, `production`, `test`).
375
- #
376
- # @deprecated
377
- #
378
- # @return [String] the environment name
379
- add_option :env do
380
- ENV['CONJUR_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "production"
381
- end
382
-
383
- # DEPRECATED SaaS option, do not doc comment!
384
- add_option :stack do
385
- case env
386
- when "production"
387
- "v4"
388
- else
389
- env
390
- end
391
- end
392
-
393
349
  # @!attribute cert_file
394
350
  #
395
351
  # Path to the certificate file to use when making secure connections to your Conjur appliance.
@@ -413,8 +369,6 @@ module Conjur
413
369
  # @see cert_file
414
370
  add_option :ssl_certificate
415
371
 
416
-
417
-
418
372
  # Add the certificate configured by the {#ssl_certificate} and {#cert_file} options to the certificate
419
373
  # store used by Conjur clients.
420
374
  #
@@ -440,44 +394,13 @@ module Conjur
440
394
 
441
395
  private
442
396
 
443
- def global_service_url(service_name, service_port_offset)
444
- if appliance_url
445
- URI.join(appliance_url + '/', service_name).to_s
446
- else
447
- case env
448
- when 'test', 'development', 'appliance'
449
- "http://localhost:#{service_base_port + service_port_offset}"
450
- else
451
- "https://#{herokuize service_name}-#{stack}-conjur.herokuapp.com"
452
- end
453
- end
454
- end
455
-
456
- def account_service_url(service_name, service_port_offset)
457
- if appliance_url
458
- URI.join(appliance_url + '/', service_name).to_s
459
- else
460
- case env
461
- when 'test', 'development', 'appliance'
462
- "http://localhost:#{service_base_port + service_port_offset}"
463
- else
464
- "https://#{herokuize service_name}-#{account}-conjur.herokuapp.com"
465
- end
466
- end
467
- end
468
-
469
- def default_service_url(service_name, service_port_offset)
397
+ def global_service_url service_port_offset, service_name: nil
470
398
  if appliance_url
471
- appliance_url
399
+ URI.join([appliance_url, service_name].compact.join('/')).to_s
472
400
  else
473
- account_service_url(service_name, service_port_offset)
401
+ "http://localhost:#{service_base_port + service_port_offset}"
474
402
  end
475
403
  end
476
-
477
- # Heroku: Name must start with a letter and can only contain lowercase letters, numbers, and dashes.
478
- def herokuize name
479
- name.downcase.gsub(/[^a-z0-9\-]/, '-')
480
- end
481
404
 
482
405
  def ensure_cert_readable!(path)
483
406
  # Try to open the file to make sure it exists and that it's
@@ -485,6 +408,5 @@ module Conjur
485
408
  # propagate.
486
409
  File.open(path) {}
487
410
  end
488
-
489
411
  end
490
412
  end
data/lib/conjur/escape.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2013 Conjur Inc
2
+ # Copyright (C) 2013-2017 Conjur Inc
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
5
  # this software and associated documentation files (the "Software"), to deal in
@@ -87,7 +87,6 @@ module Conjur
87
87
  end
88
88
 
89
89
  # @api private
90
- # :nodoc:
91
90
  def self.included(base)
92
91
  base.extend ClassMethods
93
92
  end