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
@@ -1,161 +0,0 @@
1
- module Conjur
2
- module Bootstrap
3
- module Command
4
- Base = Struct.new(:api, :listener) do
5
- def echo msg
6
- listener.echo msg
7
- end
8
-
9
- def security_admin
10
- api.group("security_admin")
11
- end
12
-
13
- def auditors
14
- api.group("auditors")
15
- end
16
-
17
- def find_or_create_record record, owner = nil, &block
18
- if record.exists?
19
- echo "#{record.resource_kind.capitalize} '#{record.id}' already exists"
20
- record
21
- else
22
- echo "Creating #{record.resource_kind} '#{record.id}'"
23
- options = {}
24
- options[:ownerid] = owner.roleid if owner
25
- result = if block_given?
26
- yield record, options
27
- else
28
- api.send "create_#{record.resource_kind}", record.id, options
29
- end
30
- store_api_key result if result.attributes['api_key']
31
- result
32
- end
33
- end
34
-
35
- def find_or_create_resource resource, owner = nil
36
- if resource.exists?
37
- echo "#{resource.resource_kind.capitalize} '#{resource.identifier}' already exists"
38
- # v4.21.0 incorrectly assigned these resources to the admin user
39
- if resource.ownerid == "#{Conjur.configuration.account}:user:admin"
40
- echo "Giving '#{resource.identifier}' to the security_admin group"
41
- resource.give_to 'group:security_admin'
42
- end
43
- else
44
- echo "Creating #{resource.resource_kind} '#{resource.identifier}'"
45
- options = {}
46
- options[:acting_as] = owner.roleid if owner
47
- api.create_resource resource.resourceid, options
48
- end
49
- end
50
-
51
- def store_api_key user
52
- api.create_variable "text/plain",
53
- "conjur-api-key",
54
- id: "conjur/#{user.resource_kind.pluralize}/#{user.id}/api-key",
55
- value: user.api_key,
56
- ownerid: security_admin.role.roleid
57
- echo "The API of #{user.resource_kind} #{user.id} is stored in variable 'conjur/#{user.resource_kind.pluralize}/#{user.id}/api-key'. " +
58
- "You can retire the variable if you don't want to keep it there."
59
- end
60
-
61
- def permit resource, privilege, role
62
- if resource.permitted_roles(privilege).member?(role.roleid)
63
- echo "#{role.roleid} already has '#{privilege}' privilege on #{resource.resourceid}"
64
- else
65
- resource.permit privilege, role
66
- end
67
- end
68
- end
69
-
70
- class SecurityAdminGroup < Base
71
- def perform
72
- find_or_create_record security_admin
73
-
74
- security_admin.resource.give_to(security_admin) unless security_admin.resource.ownerid == security_admin.role.roleid
75
- end
76
- end
77
-
78
- class AuditorsGroup < Base
79
- def perform
80
- find_or_create_record auditors, security_admin
81
- end
82
- end
83
-
84
- class Pubkeys < Base
85
- def perform
86
- find_or_create_record key_managers, security_admin
87
-
88
- find_or_create_record pubkeys_layer, security_admin
89
- find_or_create_record pubkeys_host, security_admin do |record, options|
90
- api.create_host(id: record.id, ownerid: security_admin.roleid)
91
- end
92
- pubkeys_layer.add_host pubkeys_host unless pubkeys_layer.hosts.map(&:roleid).member?(pubkeys_host.roleid)
93
-
94
- find_or_create_resource pubkeys_service, security_admin
95
-
96
- permit pubkeys_service, 'update', key_managers
97
-
98
- # also permit security_admin to update public keys
99
- permit pubkeys_service, 'update', security_admin
100
- end
101
-
102
- def pubkeys_layer
103
- api.layer("pubkeys-1.0/public-keys")
104
- end
105
-
106
- def pubkeys_host
107
- api.host("conjur/pubkeys")
108
- end
109
-
110
- def pubkeys_service
111
- api.resource("service:pubkeys-1.0/public-keys")
112
- end
113
-
114
- def key_managers
115
- api.group("pubkeys-1.0/key-managers")
116
- end
117
- end
118
-
119
- class Attic < Base
120
- def perform
121
- find_or_create_record attic
122
- end
123
-
124
- def attic_user_name
125
- "attic"
126
- end
127
-
128
- def attic
129
- api.user(attic_user_name)
130
- end
131
- end
132
-
133
- # Create a set of hosts that have security_admin privilege.
134
- class SystemAccounts < Base
135
- def perform
136
- for hostname in %w(conjur/authn-tv conjur/expiration conjur/secrets-rotator conjur/policy-loader conjur/ldap-sync)
137
- find_or_create_resource api.resource("webservice:#{hostname}"), security_admin
138
- find_or_create_record api.host(hostname), security_admin do |record, options|
139
- api.create_host(id: record.id, ownerid: security_admin.roleid).tap do |host|
140
- host.role.revoke_from security_admin
141
- security_admin.add_member host
142
- end
143
- end
144
- end
145
- end
146
- end
147
-
148
- class GlobalPrivileges < Base
149
- def perform
150
- permit conjur_resource, 'elevate', security_admin
151
- permit conjur_resource, 'reveal', security_admin
152
- permit conjur_resource, 'reveal', auditors
153
- end
154
-
155
- def conjur_resource
156
- api.resource("!:!:conjur")
157
- end
158
- end
159
- end
160
- end
161
- end
@@ -1,49 +0,0 @@
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
- # @api private
23
- # This module is included by classes that can be built from JSON responses.
24
- module BuildFromResponse
25
- # @api private
26
- #
27
- # Build a Conjur asset from a REST response.
28
- #
29
- # @param [RestCliet::Response] response the response to build the object from
30
- # @param [Hash] credentials options as {Conjur::API#credentials} used to perform requests in methods on
31
- # the created asset.
32
- #
33
- # @return [Object] an object of this type
34
- def build_from_response(response, credentials)
35
- new(response.headers[:location], credentials).tap do |obj|
36
- obj.attributes = JSON.parse(response.body)
37
- if obj.respond_to?(:resource_kind)
38
- obj.log do |logger|
39
- logger << "Created #{obj.resource_kind} #{obj.resource_id}"
40
- end
41
- elsif obj.respond_to?(:id)
42
- obj.log do |logger|
43
- logger << "Created #{self.name} #{obj.id}"
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,74 +0,0 @@
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 API
23
- class << self
24
- # @api private
25
- #
26
- # Host for the core service. We don't really use this anymore.
27
- #
28
- # @return [String] the core asset host
29
- def core_asset_host
30
- ::Conjur::Core::API.host
31
- end
32
- end
33
- end
34
-
35
- module Core
36
- class API < Conjur::API
37
- class << self
38
- # @api private
39
- # @deprecated
40
- # The host for the Conjur directory service
41
- # @return [String] the host.
42
- def host
43
- Conjur.configuration.core_url
44
- end
45
-
46
- # Returns the account as determined by the conjur server.
47
- #
48
- # You should generally provide the account with {Conjur::Configuration#account}, but this method
49
- # can determine it by asking the server.
50
- #
51
- # You do not need any credentials to call this method.
52
- def conjur_account
53
- info['account'] or raise "No account field in #{info.inspect}"
54
- end
55
-
56
- # @api private
57
- #
58
- # Used to fetch an `info` hash from the server.
59
- #
60
- # @return [Hash] a hash containing an `'account'` field that specifies the current Conjur account.
61
- def info
62
- @info ||= JSON.parse RestClient::Resource.new(Conjur::Core::API.host)['info'].get
63
- end
64
- end
65
- end
66
- end
67
- end
68
-
69
- require 'conjur/api/deputies'
70
- require 'conjur/api/hosts'
71
- require 'conjur/api/secrets'
72
- require 'conjur/api/users'
73
- require 'conjur/api/groups'
74
- require 'conjur/api/variables'
data/lib/conjur/deputy.rb DELETED
@@ -1,55 +0,0 @@
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
- # A Deputy is an actor, typically representing a service. It is given a login and
23
- # an api key, just like {Conjur::Host}s and {Conjur::User}s, and can perform various
24
- # actions.
25
- #
26
- # You should not create instances of this class directly. Instead, you can get a {Conjur::Deputy}
27
- # instance with {Conjur::API#deputy} or {Conjur::API#create_deputy}.
28
- #
29
- # The deputies api is stable, but is primarily used internally.
30
- class Deputy < RestClient::Resource
31
- include Exists
32
- include HasId
33
- include HasIdentifier
34
- include HasAttributes
35
- include ActsAsUser
36
- include ActsAsResource
37
-
38
- # Login for the deputy. Of the form "deputy/<deputy-id>".
39
- #
40
- # @return [String] the login.
41
- def login
42
- [ self.class.name.split('::')[-1].downcase, id ].join('/')
43
- end
44
-
45
- # API Key that can be used to login as the deputy.
46
- #
47
- # This is only available if the {Conjur::Deputy} was returned
48
- # by {Conjur::API#create_deputy}.
49
- #
50
- # @return [String] the api key.
51
- def api_key
52
- self.attributes['api_key']
53
- end
54
- end
55
- end
data/lib/conjur/env.rb DELETED
@@ -1,54 +0,0 @@
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
- extend self
23
-
24
- # @deprecated
25
- # @api private
26
- # This method delegates to {Conjur::Configuration#service_base_port}
27
- #
28
- # @return [Integer] the service base port
29
- def service_base_port
30
- Conjur.configuration.service_base_port
31
- end
32
-
33
- # This method delegates to {Conjur::Configuration#account}
34
- #
35
- # @return [String] the value of `Conjur.configuration.account`
36
- def account
37
- Conjur.configuration.account
38
- end
39
-
40
- # This method delegates to {Conjur::Configuration#env}
41
- # @return [String] the value of `Conjur.configuration.env`
42
- def env
43
- Conjur.configuration.env
44
- end
45
-
46
- # @api private
47
- # @deprecated
48
- # This method delegates to {Conjur::Configuration#stack}
49
- #
50
- # @return [String] the value of `Conjur.configuration.stack`
51
- def stack
52
- Conjur.configuration.stack
53
- end
54
- end
@@ -1,101 +0,0 @@
1
- module Conjur
2
- # @api private
3
- # An EventSource instance is used to parse a stream in the format given by
4
- # the Server Sent Events standard: http://www.whatwg.org/specs/web-apps/current-work/#server-sent-events
5
- #
6
- # This class is used internally by the audit methods in follow mode.
7
- #
8
- class EventSource
9
- # @api private
10
- # Representation of a SSE event
11
- class Event < Struct.new(:data, :name, :id);
12
- end
13
-
14
- # @!attribute retry [r]
15
- # @return [Fixnum] the last retry field received, or nil if no retry fields
16
- # have been received.
17
- attr_reader :retry
18
-
19
- # @!attribute last_event_id [r]
20
- # @return [String] the id of the last fully received event, or nil if no
21
- # events have been received containing an id field.
22
- attr_reader :last_event_id
23
-
24
- # @!attribute json [rw]
25
- # @return [Boolean] (true) Whether to parse event's data field as JSON.
26
- attr_accessor :json
27
- alias json? json
28
-
29
- # @api private
30
- # Create an EventSource
31
- def initialize
32
- @json = true
33
- @on = {}
34
- @all = []
35
- @buffer = ""
36
- end
37
-
38
- # @api private
39
- # Feed a chunk of data to the EventSource and dispatch any fully received
40
- # events.
41
- # @param [String] chunk the data to parse
42
- # @return [void]
43
- def feed chunk
44
- @buffer << chunk
45
-
46
- while i = @buffer.index("\n\n")
47
- process_event @buffer.slice!(0..i)
48
- end
49
- end
50
-
51
- # Add a block to be called when events with an `'event'` field of `name` are received.
52
- #
53
- # @param [String, Symbol] name the name to listen for
54
- # @yieldparam [Conjur::EventSource::Event] the event
55
- def on name, &block
56
- (@on[name.to_sym] ||= []) << block
57
- end
58
-
59
- # Listens to all messages
60
- def message &block
61
- @all << block
62
- end
63
-
64
- protected
65
- def process_event s
66
- data, id, name = [], nil, nil
67
- s.lines.map(&:chomp).each do |line|
68
- field, value = case line
69
- when /^:/ then
70
- next # comment, do nothing
71
- when /^(.*?):(.*)$/ then
72
- [$1, $2]
73
- else
74
- [line, ''] # this is what the spec says, I swear!
75
- end
76
- # spec allows one optional space after the colon
77
- value = value[1..-1] if value.start_with? ' '
78
- case field
79
- when 'data' then
80
- data << value
81
- when 'id' then
82
- id = value
83
- when 'event' then
84
- name = value.to_sym
85
- when 'retry' then
86
- @retry = value.to_i
87
- end
88
- end
89
- @last_event_id = id
90
- dispatch_event(data.join("\n"), id, name) unless data.empty?
91
- end
92
-
93
- def dispatch_event data, id, name
94
- data = JSON.parse(data) if json?
95
- name = (name || :message).to_sym
96
- event = Event.new(data, name, id)
97
- ((@on[name] || []) + @all).each { |p| p.call event }
98
- end
99
-
100
- end
101
- end
data/lib/conjur/exists.rb DELETED
@@ -1,60 +0,0 @@
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
- # Provides an `exists?` method for things that may or may not exist.
23
- #
24
- #
25
- # Most conjur assets returned by `api.asset_name` methods (e.g., {Conjur::API#group}, {Conjur::API#user})
26
- # may or may not exist. The {Conjur::Exists#exists?} method lets you determine whether or not such assets
27
- # do in fact exist.
28
- module Exists
29
-
30
- # Check whether this asset exists by performing a HEAD request to its URL.
31
- #
32
- # This method will return false if the asset doesn't exist.
33
- #
34
- # @example
35
- # does_not_exist = api.user 'does-not-exist' # This returns without error.
36
- #
37
- # # this is wrong!
38
- # owner = does_not_exist.ownerid # raises RestClient::ResourceNotFound
39
- #
40
- # # this is right!
41
- # owner = if does_not_exist.exists?
42
- # does_not_exist.ownerid
43
- # else
44
- # nil # or some sensible default
45
- # end
46
- #
47
- # @param [Hash] options included for compatibility: **don't use this argument**!
48
- # @return [Boolean] does it exist?
49
- def exists?(options = {})
50
- begin
51
- self.head(options)
52
- true
53
- rescue RestClient::Forbidden
54
- true
55
- rescue RestClient::ResourceNotFound
56
- false
57
- end
58
- end
59
- end
60
- end