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,111 +0,0 @@
1
- # Copyright (C) 2013-2015 Conjur Inc.
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the "Software"), to deal in
5
- # the Software without restriction, including without limitation the rights to
6
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
- # the Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
- #
20
- require 'conjur/group'
21
-
22
- module Conjur
23
-
24
-
25
- class API
26
- # @!group Directory: Groups
27
-
28
- # List all Conjur groups visible to the current role. This method does not
29
- # support advanced query options. If you want those, use `#resources` with
30
- # the `:kind` option set to `'group'`.
31
- #
32
- # @example
33
- # api.groups.count # => 163 (yikes!)
34
- #
35
- # @param options [Hash] included for compatibility. Do not use this parameter!
36
- # @return [Array<Conjur::Group>]
37
- def groups(options={})
38
- standard_list Conjur::Core::API.host, :group, options
39
- end
40
-
41
- # Create a new group with the given identifier.
42
- #
43
- # Groups can be created with a gidnumber attribute, which is used when mapping LDAP/ActiveDirectory groups
44
- # to Conjur groups, and when performing PAM authentication to assign a unix GID.
45
- #
46
- #
47
- # @example
48
- # group = api.create_group 'cats'
49
- # puts group.attributes
50
- # # Output
51
- # {"id"=>"cats",
52
- # "userid"=>"admin",
53
- # "ownerid"=>"conjur:user:admin",
54
- # "gidnumber"=>nil,
55
- # "roleid"=>"conjur:group:cats",
56
- # "resource_identifier"=>"conjur:group:cats"}
57
- #
58
- # @example Create a group with a GID number.
59
- # group = api.create_group 'dogs', gidnumber: 1337
60
- # puts group.attributes['gidnumber']
61
- # # Output
62
- # 1337
63
- #
64
- # @param [String] id the identifier for this group
65
- # @param [Hash] options options for group creation
66
- # @option options [FixNum] :gidnumber gidnumber to assign to this group (if not present, the
67
- # group will *not* have a gidnumber, in contrast to Conjur {Conjur::User} instances).
68
- # @return [Conjur::Group] the group created.
69
- def create_group(id, options = {})
70
- standard_create Conjur::Core::API.host, :group, id, options
71
- end
72
-
73
-
74
- # Fetch a group with the given id. Note that the id is *unqualified* -- it must not contain
75
- # `account` or `id` parts. For example,
76
- #
77
- # @example
78
- # group = api.create_group 'fish'
79
- # right = api.group 'fish'
80
- # wrong = api.group 'conjur:group:fish'
81
- # right.exists? # => true
82
- # wrong.exists? # => false
83
- #
84
- # @param [String] id the identifier of the group
85
- # @return [Conjur::Group] the group, which may or may not exist (you must check this using the {Conjur::Exists#exists?})
86
- # method.
87
- def group id
88
- standard_show Conjur::Core::API.host, :group, id
89
- end
90
-
91
- # Find groups by GID. Note that gidnumbers are *not* unique for groups.
92
- #
93
- # @example
94
- # dogs = api.create_group 'dogs', gidnumber: 42
95
- # cats = api.create_group 'cats', gidnumber: 42
96
- # api.find_groups gidnumber: 42
97
- # # => ['cats', 'dogs']
98
- #
99
- # @example
100
- # groups = api.find_groups(gidnumber: 42).map{|id| api.group(id)}
101
- # groups.map(&:class) # => [Conjur::Group, Conjur::Group]
102
- #
103
- # @param [Hash] options search criteria
104
- # @option options [Integer] :gidnumber GID number
105
- # @return [Array<String>] group names matching the criteria
106
- def find_groups options
107
- JSON.parse(RestClient::Resource.new(Conjur::Core::API.host, credentials)["groups/search?#{options.to_query}"].get)
108
- end
109
- #@!endgroup
110
- end
111
- end
@@ -1,109 +0,0 @@
1
- #
2
- # Copyright (C) 2013-2015 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/host'
22
-
23
- module Conjur
24
-
25
- class API
26
- class << self
27
- # @api private
28
- # deprecated
29
- def enroll_host(url)
30
- if Conjur.log
31
- Conjur.log << "Enrolling host with URL #{url}\n"
32
- end
33
- require 'uri'
34
- url = URI.parse(url) if url.is_a?(String)
35
- response = Net::HTTP.get_response url
36
- raise "Host enrollment failed with status #{response.code} : #{response.body}" unless response.code.to_i == 200
37
- mime_type = response['Content-Type']
38
- body = response.body
39
- [ mime_type, body ]
40
- end
41
- end
42
-
43
- #@!group Directory: Hosts
44
-
45
- # Create a new `host` asset.
46
- #
47
- # By default this method will create a host with a random id. However, you may create a host with a
48
- # specific name by passing an `:id` option.
49
- #
50
- # ### Permissions
51
- #
52
- # * Any Conjur role may perform this method without an `:ownerid` option. The new hosts owner will be the current role.
53
- # * If you pass an ``:ownerid` option, you must be a member of the given role.
54
- #
55
- # @example
56
- # # Create a host with a random id
57
- # anon = api.create_host
58
- # anon.id # => "wyzg17"
59
- #
60
- # # Create a host with a given id
61
- # foo = api.create_host id: 'foo'
62
- # foo.id # => "foo"
63
- #
64
- # # Trying to create a new host named foo fails
65
- # foo2 = api.create_host id: 'foo' # raises RestClient::Conflict
66
- #
67
- # # Create a host owned by user 'alice' (assuming we're authenticated as
68
- # # a role of which alice is a member).
69
- # alice_host = api.create_host id: "host-for-alice", ownerid: 'conjur:user:ailce'
70
- # alice_host.ownerid # => "conjur:user:alice"
71
- #
72
- # @param [Hash,nil] options options for the new host
73
- # @option options [String] :id the id for the new host
74
- # @option options [String] :ownerid set the new hosts owner to this role
75
- # @return [Conjur::Host] the created host
76
- # @raise RestClient::Conflict when id is given and a host with that id already exists.
77
- # @raise RestClient::Forbidden when ownerid is given and the owner role does not exist, or you are not
78
- # a member of the owner role.
79
- #
80
- def create_host options = nil
81
- options = options.merge \
82
- cidr: [*options[:cidr]].map(&CIDR.method(:validate)).map(&:to_s) if options[:cidr]
83
- standard_create Conjur::Core::API.host, :host, nil, options
84
- end
85
-
86
- # Get a host by its *unqualified id*.
87
- #
88
- # Like other Conjur methods, this will return a {Conjur::Host} whether
89
- # or not the record is found, and you must use the {Conjur::Exists#exists?} method
90
- # to check this.
91
- #
92
- # @example
93
- # api.create_host id: 'foo'
94
- # foo = api.host "foo" # => returns a Conjur::Host
95
- # puts foo.resourceid # => "conjur:host:foo"
96
- # puts foo.id # => "foo"
97
- # mistake = api.host "doesnotexist" # => Also returns a Conjur::Host
98
- # foo.exists? # => true
99
- # mistake.exists? # => false
100
- #
101
- # @param [String] id the unqualified id of the host
102
- # @return [Conjur::Host] an object representing the host, which may or may not exist.
103
- def host id
104
- standard_show Conjur::Core::API.host, :host, id
105
- end
106
-
107
- #@!endgroup
108
- end
109
- end
@@ -1,126 +0,0 @@
1
- # Copyright (C) 2013-2016 Conjur Inc.
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- # this software and associated documentation files (the "Software"), to deal in
5
- # the Software without restriction, including without limitation the rights to
6
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
- # the Software, and to permit persons to whom the Software is furnished to do so,
8
- # subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
- #
20
- require 'semantic'
21
- require 'semantic/core_ext'
22
- module Conjur
23
- class API
24
- class << self
25
-
26
- # Return the version of the given service presently running on the Conjur appliance.
27
- #
28
- # @example Check that the authn service is at least version 4.6
29
- # if api.service_version('authn') >= '4.6.0'.to_version
30
- # puts "Authn version is at least 4.6.0"
31
- # end
32
- #
33
- # This feature is useful for determining whether the Conjur appliance has a particular feature.
34
- #
35
- # If the given service does not exist, this method will raise an exception. To retrieve a list of
36
- # valid service names, you can use `Conjur::API.service_names`
37
- #
38
- # @param [String] service the name of the service.
39
- # @return [Semantic::Version] the version of the service.
40
- def service_version service
41
- if (service_info = appliance_info['services'][service]).nil?
42
- raise "Unknown service #{service} (services are #{service_names.join(', ')}."
43
- else
44
- # Pre-release versions are discarded, because they make testing harder:
45
- # 2.0.0-p598 :004 > Semantic::Version.new("4.5.0") <= Semantic::Version.new("4.5.0-1")
46
- # => false
47
- major, minor, patch, pre = service_info['version'].split(/[.-]/)[0..3]
48
- Semantic::Version.new "#{major}.#{minor}.#{patch}"
49
- end
50
- end
51
-
52
- # Return an Array of valid service names for your appliance.
53
- #
54
- # @return [Array<String>] the names of services on the appliance.
55
- def service_names
56
- appliance_info['services'].keys
57
- end
58
-
59
- # Return a Hash containing various information about the Conjur appliance.
60
- #
61
- # If the appliance does not support this feature, raise Conjur::FeatureNotAvailable.
62
- #
63
- # @note This feature requires Conjur appliance version 4.6 or above.
64
- #
65
- # @return [Hash] various information about the Conjur appliance.
66
- def appliance_info
67
- JSON.parse(RestClient::Resource.new(appliance_info_url).get.body)
68
- rescue RestClient::ResourceNotFound
69
- raise Conjur::FeatureNotAvailable.new('Your appliance does not support the /info URL needed by Conjur::API.appliance_info (you need 4.6 or later)')
70
- end
71
-
72
- # Return a Hash containing health information for this appliance, or for another host.
73
- #
74
- # If the `remote_host` argument is provided, the health of that appliance is reported from
75
- # the perspective of the appliance being queried (as specified by the `appliance_url` configuration
76
- # variable).
77
- #
78
- # @note When called without an argument, this method requires a Conjur server running version 4.5 or later.
79
- # When called with an argument, it requires 4.6 or later.
80
- #
81
- # @param [String, NilClass] remote_host a hostname for a remote host
82
- # @return [Hash] the appliance health information.
83
- def appliance_health remote_host=nil
84
- remote_host.nil? ? own_health : remote_health(remote_host)
85
- end
86
-
87
- private
88
-
89
-
90
- def remote_health host
91
- JSON.parse(RestClient::Resource.new(remote_health_url(host)).get.body)
92
- rescue RestClient::ResourceNotFound
93
- raise Conjur::FeatureNotAvailable.new('Your appliance does not support the /remote_health/:host URL needed by Conjur::API.appliance_health (you need 4.6 or later)')
94
- rescue RestClient::ExceptionWithResponse => ex
95
- JSON.parse(ex.response.body)
96
- end
97
-
98
-
99
- def own_health
100
- JSON.parse(RestClient::Resource.new(appliance_health_url).get.body)
101
- rescue RestClient::ResourceNotFound
102
- raise Conjur::FeatureNotAvailable.new('Your appliance does not support the /health URL needed by Conjur::API.appliance_health (you need 4.5 or later)')
103
- rescue RestClient::ExceptionWithResponse => ex
104
- JSON.parse(ex.response.body)
105
- end
106
-
107
- def remote_health_url host
108
- raw_appliance_url "/remote_health/#{fully_escape host}"
109
- end
110
-
111
- def appliance_health_url
112
- raw_appliance_url '/health'
113
- end
114
-
115
- def appliance_info_url
116
- raw_appliance_url '/info'
117
- end
118
-
119
- def raw_appliance_url path
120
- url = Conjur.configuration.appliance_url
121
- raise "Conjur connection is not configured" unless url
122
- url.gsub(%r{/api$}, path)
123
- end
124
- end
125
- end
126
- end
@@ -1,62 +0,0 @@
1
- require 'conjur/layer'
2
-
3
- module Conjur
4
- class API
5
- #@!group Directory: Layers
6
-
7
- # Create a new layer with the given id
8
- #
9
- # @example
10
- # # create a new layer named 'webservers'
11
- # webservers = api.create_layer 'webservices'
12
- #
13
- # # create layer is *not* idempotent
14
- # api.create_layer 'webservices' # raises RestClient::Conflict
15
- #
16
- # # create a layer owned by user 'alice'
17
- # api.create_layer 'webservices', ownerid: 'alice'
18
- # api.owner # => 'conjur:user:alice'
19
- #
20
- # @param [String] id an *unqualified* id for the layer.
21
- # @return [Conjur::Layer]
22
- def create_layer(id, options = {})
23
- standard_create Conjur::API.layer_asset_host, :layer, id, options
24
- end
25
-
26
- # Get all layers visible to the current role.
27
- #
28
- # The `options` parameter is only included for backwards
29
- # compatibility and has no effect. You should call this method
30
- # without arguments.
31
- #
32
- # @param [Hash] options deprecated, unused
33
- # @return [Array<Conjur::Layer>] all layers visible to the current role
34
- def layers options={}
35
- standard_list Conjur::API.layer_asset_host, :layer, options
36
- end
37
-
38
-
39
- # Get a layer by its *unqualified id*.
40
- #
41
- # Like other Conjur methods, this will return a {Conjur::Layer} whether
42
- # or not the record is found, and you must use the {Conjur::Exists#exists?} method
43
- # to check this.
44
- #
45
- # @example
46
- # api.create_layer id: 'foo'
47
- # foo = api.layer "foo" # => returns a Conjur::Layer
48
- # puts foo.resourceid # => "conjur:layer:foo"
49
- # puts foo.id # => "foo"
50
- # mistake = api.layer "doesnotexist" # => Also returns a Conjur::Layer
51
- # foo.exists? # => true
52
- # mistake.exists? # => false
53
- #
54
- # @param [String] id the unqualified id of the layer
55
- # @return [Conjur::Layer] an object representing the layer, which may or may not exist.
56
- def layer id
57
- standard_show Conjur::API.layer_asset_host, :layer, id
58
- end
59
-
60
- #@!endgroup
61
- end
62
- end
@@ -1,115 +0,0 @@
1
- #
2
- # Copyright (C) 2016 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/ldap_sync_job'
22
-
23
- module Conjur
24
- class API
25
- # @!group LDAP Sync Service
26
-
27
- # Fetch a Conjur policy that will bring Conjur into sync with the
28
- # LDAP server specified by a profile.
29
- #
30
- # @param [String] profile the name of the LDAP server profile
31
- # @param [Hash] options reserved for future use
32
- def ldap_sync_policy profile, options = {}
33
-
34
- headers = credentials.dup.tap {|h|
35
- h[:headers][:accept] = 'text/event-stream'
36
- }
37
-
38
- options = options.merge(:config_name => profile)
39
- url = Conjur.configuration.appliance_url + "/ldap-sync/policy?#{options.to_query}"
40
-
41
- # Even though we're using SSE to return the policy, fetch the
42
- # whole thing at once into a single response. Retrieving it in
43
- # chunks doesn't buy us much of anything except more complicated
44
- # client code.
45
- response = RestClient::Resource.new(url, headers).get
46
- JSON.parse(get_json("policy", response)).merge('events' => find_log_events(response))
47
- end
48
-
49
- # @api private
50
- # Get an LDAP sync profile.
51
-
52
- # @param [String] profile name
53
- # @param [Hash] options reserved
54
- def ldap_sync_show_profile(profile, options = {})
55
- url = Conjur.configuration.appliance_url
56
- resp = RestClient::Resource.new(url, credentials)['ldap-sync']['config'][profile].get(options)
57
- JSON.parse(resp.body)
58
- end
59
-
60
- # @api private
61
- # Update an LDAP sync profile.
62
- #
63
- # ### Note
64
- # DO NOT use this method and the UI to update an LDAP sync profile.
65
- #
66
- # @param [Hash] profile a hash containing the LDAP sync configuration
67
- # @param [Hash] options reserved
68
- def ldap_sync_update_profile(profile_name, profile, options = {})
69
- options[:json_config] = profile.to_json
70
- resp = RestClient::Resource.new(Conjur.configuration.appliance_url, credentials)['ldap-sync']['config'][profile_name].put(options.to_json, :content_type => 'application/json')
71
- JSON.parse(resp.body)
72
- end
73
-
74
- # @api private
75
- # Search using an LDAP sync profile
76
- #
77
- # @param [String] profile name
78
- # @param [Hash] options reserved
79
- def ldap_sync_search(profile, options = {})
80
- headers = credentials.dup.tap {|h|
81
- h[:headers][:accept] = 'text/event-stream'
82
- }
83
-
84
- response = RestClient::Resource.new(Conjur.configuration.appliance_url, headers)['ldap-sync']['search'].post(options.merge(:config_name => profile))
85
- JSON.parse(get_json("groups", response)).merge('events' => find_log_events(response))
86
- end
87
-
88
- # @!endgroup
89
-
90
- private
91
- def get_json(key, response)
92
- if response.headers[:content_type] == 'text/event-stream'
93
- find_event_by_key(key, response) || find_error_events(response)
94
- else
95
- %Q({"error": {"message": "Unexpected response from server: #{response.body}"}})
96
- end
97
- end
98
-
99
- def find_event_by_key(key, response)
100
- response.body.lines.find {|l| l =~ %r(^data: {"#{key}":) }.try(:[], 6..-1)
101
- end
102
-
103
- def find_log_events(response)
104
- find_events(response, 'log').collect { |e| JSON.parse(e)['log'] }
105
- end
106
-
107
- def find_error_events(response)
108
- find_events(response, "error").join("\n")
109
- end
110
-
111
- def find_events(response, key)
112
- response.body.lines.collect {|l| l.match(/^data: ({"#{key}":.*)/).try(:[], 1)}.compact
113
- end
114
- end
115
- end
@@ -1,106 +0,0 @@
1
- #
2
- # Copyright (C) 2013-2015 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/user'
22
- require 'conjur/cidr'
23
-
24
- module Conjur
25
- class API
26
- #@!group Directory: Users
27
-
28
- # Create a {http://developer.conjur.net/reference/services/directory/user Conjur User}. Conjur users
29
- # are identities for humans.
30
- #
31
- # When you create a user for the first time, the returned object will have an `api_key` field. You can then
32
- # use this to set a password for the user if you want to. Note that when the user is fetched later with the {#user}
33
- # method, it **will not have an api_key**. Use it or lose it.
34
- #
35
- # ### Permissions
36
- # Any authenticated role may call this method.
37
- #
38
- # @example Create a user 'alice' and set her password to 'frogger'
39
- # alice = api.create_user 'alice', password: 'frogger'
40
- #
41
- # # Now we can login as 'alice'.
42
- # alice_api = Conjur::API.new_from_key 'alice', 'frogger'
43
- # alice_api.current_role # => 'conjur:user:alice'
44
- #
45
- # @example Create a user and save her `api_key` for later use
46
- # alice = api.create_user 'alice' # note that we're not giving a password
47
- # save_api_key 'alice', alice.api_key
48
- #
49
- # @param [String] login the login for the new user
50
- # @param [Hash] options options for user creation
51
- # @option options [String] :acting_as Qualified id of a role to perform the action as
52
- # @option options [Array<String, IPAddr>] :cidr CIDR addresses of networks
53
- # the new user will be allower to login from
54
- # @option options [String, Integer] :uidnumber UID number to assign to the new user. If not given, one will be generated.
55
- # @option options [String] :password when present, the user will be given a password in addition to a randomly
56
- # generated api key.
57
- # @return [Conjur::User] an object representing the new user
58
- # @raise [RestClient::Conflict] If the user already exists, or a user with the given uidnumber exists.
59
- def create_user(login, options = {})
60
- options = options.merge \
61
- cidr: [*options[:cidr]].map(&CIDR.method(:validate)).map(&:to_s) if options[:cidr]
62
- standard_create Conjur::Core::API.host, :user, nil, options.merge(login: login)
63
- end
64
-
65
- # Return an object representing a user with the given login. The {Conjur::User} object returned
66
- # may or may not exist. You can check whether it exists with the {Conjur::Exists#exists?} method.
67
- #
68
- # The returned {Conjur::User} will *not* have an api_key.
69
- #
70
- # ### Permissions
71
- # Any authenticated role may call this method.
72
- #
73
- # @param [String] login the user's login
74
- # @return [Conjur::User] an object representing the user
75
- def user login
76
- standard_show Conjur::Core::API.host, :user, login
77
- end
78
-
79
- # @api private
80
- #
81
- # @note In the future, further options for search may be added, but presently this only supports uid search.
82
- #
83
- # Find users by uidnumber.
84
- #
85
- #
86
- # When a user is created it is assigned a uid number. When the uid number is not specified when creating the user,
87
- # a sequential uid number will be generated, starting at 1000. uidnumbers are used when synchronizing with LDAP directories
88
- # and to assign a UNIX user id number when using {http://developer.conjur.net/tutorials/ssh/conjur-ssh.html Conjur SSH login}.
89
- #
90
- # ### Note
91
- # Although users are uniquely identified by their uidnumber, the result of this method is an array of user ids for compatibility
92
- # reasons.
93
- #
94
- # ### Permissions
95
- # Only roles of which you are a member will be returned
96
- #
97
- # @param [Hash] options query to send
98
- # @option options [String, Integer] :uidnumber (required) the uidnumber to search for
99
- # @return [Array<String>] a one element array containing the users login.
100
- def find_users options
101
- JSON.parse( RestClient::Resource.new(Conjur::Core::API.host, credentials)["users/search?#{options.to_query}"].get )
102
- end
103
-
104
- #@!endgroup
105
- end
106
- end