diplomat 2.2.4 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/diplomat.rb +2 -1
- data/lib/diplomat/error.rb +10 -1
- data/lib/diplomat/kv.rb +4 -6
- data/lib/diplomat/lock.rb +2 -0
- data/lib/diplomat/policy.rb +112 -0
- data/lib/diplomat/rest_client.rb +43 -1
- data/lib/diplomat/role.rb +151 -0
- data/lib/diplomat/token.rb +133 -0
- data/lib/diplomat/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ee74cdd0ff09ba455fa1185856231070da1a7b5296bcec09db981a72cb0a235
|
4
|
+
data.tar.gz: 2fd779c20984bc5f394c9c5fb6aef1a30abfcc99bd74d1700044c6fe2cc1d4e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d9a9c7e1d7a2fdfdabb7139013da70e5dee028c18dcd2fa820ed5d235a34a26ac3a1b5108d7fab2d76be1bad370ed85a47b791b190104088be2a63287d76d58
|
7
|
+
data.tar.gz: 9daf8932e9bd5e2e74ad19cb91b070552805f1f249d553c2975899edc2f1ee27146b6207fb07867cbbb563b0b60b8768d68fc3d276902de28ce0b0a65885d662
|
data/lib/diplomat.rb
CHANGED
@@ -28,7 +28,8 @@ module Diplomat
|
|
28
28
|
|
29
29
|
require_libs 'configuration', 'rest_client', 'kv', 'datacenter', 'service',
|
30
30
|
'members', 'node', 'nodes', 'check', 'health', 'session', 'lock',
|
31
|
-
'error', 'event', 'acl', 'maintenance', 'query', 'agent', 'status'
|
31
|
+
'error', 'event', 'acl', 'maintenance', 'query', 'agent', 'status',
|
32
|
+
'policy', 'token', 'role'
|
32
33
|
self.configuration ||= Diplomat::Configuration.new
|
33
34
|
|
34
35
|
class << self
|
data/lib/diplomat/error.rb
CHANGED
@@ -2,7 +2,7 @@ module Diplomat
|
|
2
2
|
class KeyNotFound < StandardError; end
|
3
3
|
class PathNotFound < StandardError; end
|
4
4
|
class KeyAlreadyExists < StandardError; end
|
5
|
-
class AclNotFound <
|
5
|
+
class AclNotFound < PathNotFound; end
|
6
6
|
class AclAlreadyExists < StandardError; end
|
7
7
|
class EventNotFound < StandardError; end
|
8
8
|
class EventAlreadyExists < StandardError; end
|
@@ -10,6 +10,15 @@ module Diplomat
|
|
10
10
|
class QueryAlreadyExists < StandardError; end
|
11
11
|
class UnknownStatus < StandardError; end
|
12
12
|
class IdParameterRequired < StandardError; end
|
13
|
+
class NameParameterRequired < StandardError; end
|
13
14
|
class InvalidTransaction < StandardError; end
|
14
15
|
class DeprecatedArgument < StandardError; end
|
16
|
+
class PolicyNotFound < StandardError; end
|
17
|
+
class NameParameterRequired < StandardError; end
|
18
|
+
class PolicyMalformed < StandardError; end
|
19
|
+
class AccessorIdParameterRequired < StandardError; end
|
20
|
+
class TokenMalformed < StandardError; end
|
21
|
+
class PolicyAlreadyExists < StandardError; end
|
22
|
+
class RoleMalformed < StandardError; end
|
23
|
+
class RoleNotFound < StandardError; end
|
15
24
|
end
|
data/lib/diplomat/kv.rb
CHANGED
@@ -42,12 +42,8 @@ module Diplomat
|
|
42
42
|
# - W W - get the first or next value; wait until there is an update
|
43
43
|
# rubocop:disable PerceivedComplexity, MethodLength, LineLength, CyclomaticComplexity
|
44
44
|
def get(key, options = {}, not_found = :reject, found = :return)
|
45
|
-
|
46
|
-
|
47
|
-
else
|
48
|
-
key.freeze
|
49
|
-
end
|
50
|
-
@key = key_subst
|
45
|
+
key = normalize_key_for_uri(key)
|
46
|
+
@key = key
|
51
47
|
@options = options
|
52
48
|
custom_params = []
|
53
49
|
custom_params << recurse_get(@options)
|
@@ -111,6 +107,7 @@ module Diplomat
|
|
111
107
|
# @option options [String] :acquire Session to attach to key
|
112
108
|
# @return [Bool] Success or failure of the write (can fail in c-a-s mode)
|
113
109
|
def put(key, value, options = {})
|
110
|
+
key = normalize_key_for_uri(key)
|
114
111
|
@options = options
|
115
112
|
custom_params = []
|
116
113
|
custom_params << use_cas(@options)
|
@@ -132,6 +129,7 @@ module Diplomat
|
|
132
129
|
# @option options [Boolean] :recurse If to make recursive get or not
|
133
130
|
# @return [OpenStruct]
|
134
131
|
def delete(key, options = {})
|
132
|
+
key = normalize_key_for_uri(key)
|
135
133
|
@key = key
|
136
134
|
@options = options
|
137
135
|
custom_params = []
|
data/lib/diplomat/lock.rb
CHANGED
@@ -10,6 +10,7 @@ module Diplomat
|
|
10
10
|
# @param options [Hash] options parameter hash
|
11
11
|
# @return [Boolean] If the lock was acquired
|
12
12
|
def acquire(key, session, value = nil, options = {})
|
13
|
+
key = normalize_key_for_uri(key)
|
13
14
|
custom_params = []
|
14
15
|
custom_params << use_named_parameter('acquire', session)
|
15
16
|
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
@@ -42,6 +43,7 @@ module Diplomat
|
|
42
43
|
# @return [nil]
|
43
44
|
# rubocop:disable AbcSize
|
44
45
|
def release(key, session, options = {})
|
46
|
+
key = normalize_key_for_uri(key)
|
45
47
|
custom_params = []
|
46
48
|
custom_params << use_named_parameter('release', session)
|
47
49
|
custom_params << use_named_parameter('dc', options[:dc]) if options[:dc]
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Diplomat
|
2
|
+
# Methods for interacting with the Consul ACL Policy API endpoint
|
3
|
+
class Policy < Diplomat::RestClient
|
4
|
+
@access_methods = %i[list read create delete update]
|
5
|
+
attr_reader :id, :type, :acl
|
6
|
+
|
7
|
+
# Read ACL policy with the given UUID
|
8
|
+
# @param id [String] UUID of the ACL policy to read
|
9
|
+
# @param options [Hash] options parameter hash
|
10
|
+
# @return [Hash] existing ACL policy
|
11
|
+
# rubocop:disable PerceivedComplexity
|
12
|
+
def read(id, options = {}, not_found = :reject, found = :return)
|
13
|
+
@options = options
|
14
|
+
custom_params = []
|
15
|
+
custom_params << use_consistency(options)
|
16
|
+
|
17
|
+
@raw = send_get_request(@conn_no_err, ["/v1/acl/policy/#{id}"], options, custom_params)
|
18
|
+
|
19
|
+
if @raw.status == 200 && @raw.body.chomp != 'null'
|
20
|
+
case found
|
21
|
+
when :reject
|
22
|
+
raise Diplomat::PolicyNotFound, id
|
23
|
+
when :return
|
24
|
+
return parse_body
|
25
|
+
end
|
26
|
+
elsif @raw.status == 404
|
27
|
+
case not_found
|
28
|
+
when :reject
|
29
|
+
raise Diplomat::PolicyNotFound, id
|
30
|
+
when :return
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
elsif @raw.status == 403
|
34
|
+
case not_found
|
35
|
+
when :reject
|
36
|
+
raise Diplomat::AclNotFound, id
|
37
|
+
when :return
|
38
|
+
return nil
|
39
|
+
end
|
40
|
+
else
|
41
|
+
raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
# rubocop:enable PerceivedComplexity
|
45
|
+
|
46
|
+
# List all the ACL policies
|
47
|
+
# @param options [Hash] options parameter hash
|
48
|
+
# @return [List] list of [Hash] of ACL policies
|
49
|
+
def list(options = {})
|
50
|
+
@raw = send_get_request(@conn_no_err, ['/v1/acl/policies'], options)
|
51
|
+
raise Diplomat::AclNotFound if @raw.status == 403
|
52
|
+
|
53
|
+
parse_body
|
54
|
+
end
|
55
|
+
|
56
|
+
# Update an existing ACL policy
|
57
|
+
# @param value [Hash] ACL policy definition, ID and Name fields are mandatory
|
58
|
+
# @param options [Hash] options parameter hash
|
59
|
+
# @return [Hash] result ACL policy
|
60
|
+
def update(value, options = {})
|
61
|
+
id = value[:ID] || value['ID']
|
62
|
+
raise Diplomat::IdParameterRequired if id.nil?
|
63
|
+
|
64
|
+
policy_name = value[:Name] || value['Name']
|
65
|
+
raise Diplomat::NameParameterRequired if policy_name.nil?
|
66
|
+
|
67
|
+
custom_params = use_cas(@options)
|
68
|
+
@raw = send_put_request(@conn, ["/v1/acl/policy/#{id}"], options, value, custom_params)
|
69
|
+
if @raw.status == 200
|
70
|
+
parse_body
|
71
|
+
elsif @raw.status == 400
|
72
|
+
raise Diplomat::PolicyMalformed, @raw.body
|
73
|
+
else
|
74
|
+
raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Create a new ACL policy
|
79
|
+
# @param value [Hash] ACL policy definition, Name field is mandatory
|
80
|
+
# @param options [Hash] options parameter hash
|
81
|
+
# @return [Hash] new ACL policy
|
82
|
+
def create(value, options = {})
|
83
|
+
blacklist = ['ID', 'iD', 'Id', :ID, :iD, :Id] & value.keys
|
84
|
+
raise Diplomat::PolicyMalformed, 'ID should not be specified' unless blacklist.empty?
|
85
|
+
|
86
|
+
id = value[:Name] || value['Name']
|
87
|
+
raise Diplomat::NameParameterRequired if id.nil?
|
88
|
+
|
89
|
+
custom_params = use_cas(@options)
|
90
|
+
@raw = send_put_request(@conn, ['/v1/acl/policy'], options, value, custom_params)
|
91
|
+
|
92
|
+
# rubocop:disable GuardClause
|
93
|
+
if @raw.status == 200
|
94
|
+
return parse_body
|
95
|
+
elsif @raw.status == 500 && @raw.body.chomp.include?('already exists')
|
96
|
+
raise Diplomat::PolicyAlreadyExists, @raw.body
|
97
|
+
else
|
98
|
+
raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
# rubocop:enable GuardClause
|
102
|
+
|
103
|
+
# Delete an ACL policy by its UUID
|
104
|
+
# @param id [String] UUID of the ACL policy to delete
|
105
|
+
# @param options [Hash] options parameter hash
|
106
|
+
# @return [Bool]
|
107
|
+
def delete(id, options = {})
|
108
|
+
@raw = send_delete_request(@conn, ["/v1/acl/policy/#{id}"], options, nil)
|
109
|
+
@raw.body.chomp == 'true'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/lib/diplomat/rest_client.rb
CHANGED
@@ -82,6 +82,44 @@ module Diplomat
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
protected
|
86
|
+
|
87
|
+
# Turn the given key into something that the Consul API
|
88
|
+
# will consider its canonical form. If we don't do this,
|
89
|
+
# then the Consul API will return a HTTP 301 response directing
|
90
|
+
# us to the same action with a canonicalized key, and we'd
|
91
|
+
# have to waste time following that redirect.
|
92
|
+
def normalize_key_for_uri(key)
|
93
|
+
# The Consul docs suggest using slashes to organise keys
|
94
|
+
# (https://www.consul.io/docs/agent/kv.html#using-consul-kv).
|
95
|
+
#
|
96
|
+
# However, Consul (like many servers) does strange things with slashes,
|
97
|
+
# presumably to "paper over" users' errors in typing URLs.
|
98
|
+
# E.g. the key "/my/path" will end up in the URI path component
|
99
|
+
# "/v1/kv//my/path", which Consul will redirect (HTTP 301) to
|
100
|
+
# "/v1/kv/my/path" -- a very different URI!
|
101
|
+
#
|
102
|
+
# One solution might be to simply always URI-encode slashes
|
103
|
+
# (and all other non-URI-safe characters), but that appears to
|
104
|
+
# result in some other weirdness, e.g., keys being returned with
|
105
|
+
# URI-encoding in them in contexts totally unrelated to URIs.
|
106
|
+
# For examples, see these issues and follow the links:
|
107
|
+
#
|
108
|
+
# - https://github.com/hashicorp/consul/issues/889
|
109
|
+
# - https://github.com/hashicorp/consul/issues/1277
|
110
|
+
#
|
111
|
+
# For now it seems safest to simply assume that leading literal
|
112
|
+
# slashes on keys are benign mistakes, and strip them off.
|
113
|
+
# Hopefully the expected behaviour will be formalised/clarified
|
114
|
+
# in future versions of Consul, and we can introduce some stricter
|
115
|
+
# and more predictable handling of keys on this side.
|
116
|
+
if key.start_with? '/'
|
117
|
+
key[1..-1]
|
118
|
+
else
|
119
|
+
key.freeze
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
85
123
|
private
|
86
124
|
|
87
125
|
# Build the API Client
|
@@ -180,7 +218,7 @@ module Diplomat
|
|
180
218
|
headers = { 'X-Consul-Token' => configuration.acl_token } if configuration.acl_token
|
181
219
|
headers = { 'X-Consul-Token' => options[:token] } if options[:token]
|
182
220
|
|
183
|
-
# Parse options used as query params
|
221
|
+
# Parse consistency options used as query params
|
184
222
|
consistency = 'stale' if options[:stale]
|
185
223
|
consistency = 'leader' if options[:leader]
|
186
224
|
consistency = 'consistent' if options[:consistent]
|
@@ -204,6 +242,10 @@ module Diplomat
|
|
204
242
|
req.options.timeout = options[:timeout] if options[:timeout]
|
205
243
|
end
|
206
244
|
rescue Faraday::ClientError => e
|
245
|
+
resp = e.response
|
246
|
+
if resp
|
247
|
+
raise Diplomat::AclNotFound, e if resp[:status] == 403 && resp[:body] == 'ACL not found'
|
248
|
+
end
|
207
249
|
raise Diplomat::PathNotFound, e
|
208
250
|
end
|
209
251
|
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module Diplomat
|
2
|
+
# Methods for interacting with the Consul ACL Role API endpoint
|
3
|
+
class Role < Diplomat::RestClient
|
4
|
+
@access_methods = %i[list read read_name create delete update]
|
5
|
+
attr_reader :id, :type, :acl
|
6
|
+
|
7
|
+
# Read ACL role with the given UUID
|
8
|
+
# @param id [String] UUID or name of the ACL role to read
|
9
|
+
# @param options [Hash] options parameter hash
|
10
|
+
# @return [Hash] existing ACL role
|
11
|
+
# rubocop:disable PerceivedComplexity
|
12
|
+
def read(id, options = {}, not_found = :reject, found = :return)
|
13
|
+
@options = options
|
14
|
+
custom_params = []
|
15
|
+
custom_params << use_consistency(options)
|
16
|
+
|
17
|
+
@raw = send_get_request(@conn_no_err, ["/v1/acl/role/#{id}"], options, custom_params)
|
18
|
+
|
19
|
+
if @raw.status == 200 && @raw.body.chomp != 'null'
|
20
|
+
case found
|
21
|
+
when :reject
|
22
|
+
raise Diplomat::RoleNotFound, id
|
23
|
+
when :return
|
24
|
+
return parse_body
|
25
|
+
end
|
26
|
+
elsif @raw.status == 404
|
27
|
+
case not_found
|
28
|
+
when :reject
|
29
|
+
raise Diplomat::RoleNotFound, id
|
30
|
+
when :return
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
elsif @raw.status == 403
|
34
|
+
case not_found
|
35
|
+
when :reject
|
36
|
+
raise Diplomat::AclNotFound, id
|
37
|
+
when :return
|
38
|
+
return nil
|
39
|
+
end
|
40
|
+
else
|
41
|
+
raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
# rubocop:enable PerceivedComplexity
|
45
|
+
|
46
|
+
# Read ACL role with the given name
|
47
|
+
# @param name [String] name of the ACL role to read
|
48
|
+
# @param options [Hash] options parameter hash
|
49
|
+
# @return [Hash] existing ACL role
|
50
|
+
# rubocop:disable PerceivedComplexity
|
51
|
+
def read_name(name, options = {}, not_found = :reject, found = :return)
|
52
|
+
@options = options
|
53
|
+
custom_params = []
|
54
|
+
custom_params << use_consistency(options)
|
55
|
+
|
56
|
+
@raw = send_get_request(@conn_no_err, ["/v1/acl/role/name/#{name}"], options, custom_params)
|
57
|
+
|
58
|
+
if @raw.status == 200 && @raw.body.chomp != 'null'
|
59
|
+
case found
|
60
|
+
when :reject
|
61
|
+
raise Diplomat::RoleNotFound, name
|
62
|
+
when :return
|
63
|
+
return parse_body
|
64
|
+
end
|
65
|
+
elsif @raw.status == 404
|
66
|
+
case not_found
|
67
|
+
when :reject
|
68
|
+
raise Diplomat::RoleNotFound, name
|
69
|
+
when :return
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
elsif @raw.status == 403
|
73
|
+
case not_found
|
74
|
+
when :reject
|
75
|
+
raise Diplomat::AclNotFound, name
|
76
|
+
when :return
|
77
|
+
return nil
|
78
|
+
end
|
79
|
+
else
|
80
|
+
raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
# rubocop:enable PerceivedComplexity
|
84
|
+
|
85
|
+
# List all the ACL roles
|
86
|
+
# @param options [Hash] options parameter hash
|
87
|
+
# @return [List] list of [Hash] of ACL roles
|
88
|
+
def list(options = {})
|
89
|
+
@raw = send_get_request(@conn_no_err, ['/v1/acl/roles'], options)
|
90
|
+
raise Diplomat::AclNotFound if @raw.status == 403
|
91
|
+
|
92
|
+
parse_body
|
93
|
+
end
|
94
|
+
|
95
|
+
# Update an existing ACL role
|
96
|
+
# @param value [Hash] ACL role definition, ID and Name fields are mandatory
|
97
|
+
# @param options [Hash] options parameter hash
|
98
|
+
# @return [Hash] result ACL role
|
99
|
+
def update(value, options = {})
|
100
|
+
id = value[:ID] || value['ID']
|
101
|
+
raise Diplomat::IdParameterRequired if id.nil?
|
102
|
+
|
103
|
+
role_name = value[:Name] || value['Name']
|
104
|
+
raise Diplomat::NameParameterRequired if role_name.nil?
|
105
|
+
|
106
|
+
custom_params = use_cas(@options)
|
107
|
+
@raw = send_put_request(@conn, ["/v1/acl/role/#{id}"], options, value, custom_params)
|
108
|
+
if @raw.status == 200
|
109
|
+
parse_body
|
110
|
+
elsif @raw.status == 400
|
111
|
+
raise Diplomat::RoleMalformed, @raw.body
|
112
|
+
else
|
113
|
+
raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Create a new ACL role
|
118
|
+
# @param value [Hash] ACL role definition, Name field is mandatory
|
119
|
+
# @param options [Hash] options parameter hash
|
120
|
+
# @return [Hash] new ACL role
|
121
|
+
def create(value, options = {})
|
122
|
+
blacklist = ['ID', 'iD', 'Id', :ID, :iD, :Id] & value.keys
|
123
|
+
raise Diplomat::RoleMalformed, 'ID should not be specified' unless blacklist.empty?
|
124
|
+
|
125
|
+
id = value[:Name] || value['Name']
|
126
|
+
raise Diplomat::NameParameterRequired if id.nil?
|
127
|
+
|
128
|
+
custom_params = use_cas(@options)
|
129
|
+
@raw = send_put_request(@conn, ['/v1/acl/role'], options, value, custom_params)
|
130
|
+
|
131
|
+
# rubocop:disable GuardClause
|
132
|
+
if @raw.status == 200
|
133
|
+
return parse_body
|
134
|
+
elsif @raw.status == 500 && @raw.body.chomp.include?('already exists')
|
135
|
+
raise Diplomat::RoleAlreadyExists, @raw.body
|
136
|
+
else
|
137
|
+
raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
# rubocop:enable GuardClause
|
141
|
+
|
142
|
+
# Delete an ACL role by its UUID
|
143
|
+
# @param id [String] UUID of the ACL role to delete
|
144
|
+
# @param options [Hash] options parameter hash
|
145
|
+
# @return [Bool]
|
146
|
+
def delete(id, options = {})
|
147
|
+
@raw = send_delete_request(@conn, ["/v1/acl/role/#{id}"], options, nil)
|
148
|
+
@raw.body.chomp == 'true'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module Diplomat
|
2
|
+
# Methods for interacting with the Consul ACL Policy API endpoint
|
3
|
+
class Token < Diplomat::RestClient
|
4
|
+
@access_methods = %i[list read create delete update clone self]
|
5
|
+
attr_reader :id, :type, :acl
|
6
|
+
|
7
|
+
# Read ACL token with the given Accessor ID
|
8
|
+
# @param id [String] accessor ID of the ACL token to read
|
9
|
+
# @param options [Hash] options parameter hash
|
10
|
+
# @return [Hash] existing ACL token
|
11
|
+
# rubocop:disable PerceivedComplexity
|
12
|
+
def read(id, options = {}, not_found = :reject, found = :return)
|
13
|
+
@options = options
|
14
|
+
custom_params = []
|
15
|
+
custom_params << use_consistency(options)
|
16
|
+
|
17
|
+
@raw = send_get_request(@conn_no_err, ["/v1/acl/token/#{id}"], options, custom_params)
|
18
|
+
|
19
|
+
if @raw.status == 200 && @raw.body.chomp != 'null'
|
20
|
+
case found
|
21
|
+
when :reject
|
22
|
+
raise Diplomat::AclNotFound, id
|
23
|
+
when :return
|
24
|
+
return parse_body
|
25
|
+
end
|
26
|
+
elsif @raw.status == 403
|
27
|
+
case not_found
|
28
|
+
when :reject
|
29
|
+
raise Diplomat::AclNotFound, id
|
30
|
+
when :return
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
else
|
34
|
+
raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
# rubocop:enable PerceivedComplexity
|
38
|
+
|
39
|
+
# List all the ACL tokens
|
40
|
+
# @param policy [String] filters the token list matching the specific policy ID
|
41
|
+
# @param role [String] filters the token list matching the specific role ID
|
42
|
+
# @param authmethod [String] the token list matching the specific named auth method
|
43
|
+
# @param options [Hash] options parameter hash
|
44
|
+
# @return [List] list of [Hash] of ACL tokens
|
45
|
+
def list(policy = nil, role = nil, authmethod = nil, options = {})
|
46
|
+
custom_params = []
|
47
|
+
custom_params << use_named_parameter('policy', policy) if policy
|
48
|
+
custom_params << use_named_parameter('role', policy) if role
|
49
|
+
custom_params << use_named_parameter('authmethod', policy) if authmethod
|
50
|
+
@raw = send_get_request(@conn_no_err, ['/v1/acl/tokens'], options, custom_params)
|
51
|
+
raise Diplomat::AclNotFound if @raw.status == 403
|
52
|
+
|
53
|
+
parse_body
|
54
|
+
end
|
55
|
+
|
56
|
+
# Update an existing ACL token
|
57
|
+
# @param value [Hash] ACL token definition, AccessorID is mandatory
|
58
|
+
# @param options [Hash] options parameter hash
|
59
|
+
# @return [Hash] result ACL token
|
60
|
+
def update(value, options = {})
|
61
|
+
id = value[:AccessorID] || value['AccessorID']
|
62
|
+
raise Diplomat::AccessorIdParameterRequired if id.nil?
|
63
|
+
|
64
|
+
custom_params = use_cas(@options)
|
65
|
+
@raw = send_put_request(@conn, ["/v1/acl/token/#{id}"], options, value, custom_params)
|
66
|
+
if @raw.status == 200
|
67
|
+
parse_body
|
68
|
+
elsif @raw.status == 403
|
69
|
+
raise Diplomat::AclNotFound, id
|
70
|
+
elsif @raw.status == 400
|
71
|
+
raise Diplomat::TokenMalformed, @raw.body
|
72
|
+
else
|
73
|
+
raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Create a new ACL token
|
78
|
+
# @param value [Hash] ACL token definition
|
79
|
+
# @param options [Hash] options parameter hash
|
80
|
+
# @return [Hash] new ACL token
|
81
|
+
def create(value, options = {})
|
82
|
+
custom_params = use_cas(@options)
|
83
|
+
@raw = send_put_request(@conn, ['/v1/acl/token'], options, value, custom_params)
|
84
|
+
return parse_body if @raw.status == 200
|
85
|
+
|
86
|
+
raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
|
87
|
+
end
|
88
|
+
|
89
|
+
# Delete an existing ACL token
|
90
|
+
# @param id [String] UUID of the ACL token to delete
|
91
|
+
# @param options [Hash] options parameter hash
|
92
|
+
# @return [Bool]
|
93
|
+
def delete(id, options = {})
|
94
|
+
anonymous_token = '00000000-0000-0000-0000-000000000002'
|
95
|
+
raise Diplomat::NotPermitted, "status #{@raw.status}: #{@raw.body}" if id == anonymous_token
|
96
|
+
|
97
|
+
@raw = send_delete_request(@conn, ["/v1/acl/token/#{id}"], options, nil)
|
98
|
+
@raw.body.chomp == 'true'
|
99
|
+
end
|
100
|
+
|
101
|
+
# Clone an existing ACL token
|
102
|
+
# @param value [Hash] ACL token definition, AccessorID is mandatory
|
103
|
+
# @param options [Hash] options parameter hash
|
104
|
+
# @return [Hash] cloned ACL token
|
105
|
+
def clone(value, options = {})
|
106
|
+
id = value[:AccessorID] || value['AccessorID']
|
107
|
+
raise Diplomat::AccessorIdParameterRequired if id.nil?
|
108
|
+
|
109
|
+
custom_params = use_cas(@options)
|
110
|
+
@raw = send_put_request(@conn, ["/v1/acl/token/#{id}/clone"], options, value, custom_params)
|
111
|
+
if @raw.status == 200
|
112
|
+
parse_body
|
113
|
+
elsif @raw.status == 403
|
114
|
+
raise Diplomat::AclNotFound, id
|
115
|
+
else
|
116
|
+
raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Returns ACL token details matching X-Consul-Token header
|
121
|
+
# @param options [Hash] options parameter hash
|
122
|
+
# @return [Hash] ACL token
|
123
|
+
def self(options = {})
|
124
|
+
custom_params = use_cas(@options)
|
125
|
+
@raw = send_get_request(@conn, ['/v1/acl/token/self'], options, custom_params)
|
126
|
+
if @raw.status == 200
|
127
|
+
parse_body
|
128
|
+
elsif @raw.status == 403
|
129
|
+
raise Diplomat::AclNotFound, id
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
data/lib/diplomat/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diplomat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hamelink
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-06-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -149,14 +149,14 @@ dependencies:
|
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 0.67.0
|
153
153
|
type: :development
|
154
154
|
prerelease: false
|
155
155
|
version_requirements: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: 0.67.0
|
160
160
|
- !ruby/object:Gem::Dependency
|
161
161
|
name: webmock
|
162
162
|
requirement: !ruby/object:Gem::Requirement
|
@@ -233,11 +233,14 @@ files:
|
|
233
233
|
- lib/diplomat/members.rb
|
234
234
|
- lib/diplomat/node.rb
|
235
235
|
- lib/diplomat/nodes.rb
|
236
|
+
- lib/diplomat/policy.rb
|
236
237
|
- lib/diplomat/query.rb
|
237
238
|
- lib/diplomat/rest_client.rb
|
239
|
+
- lib/diplomat/role.rb
|
238
240
|
- lib/diplomat/service.rb
|
239
241
|
- lib/diplomat/session.rb
|
240
242
|
- lib/diplomat/status.rb
|
243
|
+
- lib/diplomat/token.rb
|
241
244
|
- lib/diplomat/version.rb
|
242
245
|
homepage: https://github.com/WeAreFarmGeek/diplomat
|
243
246
|
licenses:
|