Class: Diplomat::Acl
- Inherits:
-
RestClient
- Object
- RestClient
- Diplomat::Acl
- Includes:
- ApiOptions
- Defined in:
- lib/diplomat/acl.rb
Overview
Methods for interacting with the Consul ACL API endpoint
Instance Attribute Summary collapse
-
#acl ⇒ Object
readonly
Returns the value of attribute acl.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#create(value) ⇒ Hash
Create an Acl definition.
-
#destroy(id) ⇒ Bool
Destroy an ACl token by its id.
-
#info(id, options = nil, not_found = :reject, found = :return) ⇒ Hash
Get Acl info by ID rubocop:disable PerceivedComplexity, MethodLength, CyclomaticComplexity, AbcSize.
-
#list ⇒ List
List all Acls.
-
#update(value) ⇒ Hash
Update an Acl definition, create if not present.
Methods included from ApiOptions
#check_acl_token, #use_cas, #use_consistency, #valid_transaction_verbs, #valid_value_transactions
Methods inherited from RestClient
access_method?, #concat_url, #initialize, method_missing, respond_to?, respond_to_missing?, #use_named_parameter
Constructor Details
This class inherits a constructor from Diplomat::RestClient
Instance Attribute Details
#acl ⇒ Object (readonly)
Returns the value of attribute acl.
7 8 9 |
# File 'lib/diplomat/acl.rb', line 7 def acl @acl end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/diplomat/acl.rb', line 7 def id @id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/diplomat/acl.rb', line 7 def type @type end |
Instance Method Details
#create(value) ⇒ Hash
Create an Acl definition
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/diplomat/acl.rb', line 70 def create(value) @raw = @conn.put do |req| url = ['/v1/acl/create'] url += check_acl_token url += use_cas(@options) req.url concat_url url req.body = value.to_json end parse_body end |
#destroy(id) ⇒ Bool
Destroy an ACl token by its id
84 85 86 87 88 89 90 |
# File 'lib/diplomat/acl.rb', line 84 def destroy(id) @id = id url = ["/v1/acl/destroy/#{@id}"] url << check_acl_token @raw = @conn.put concat_url url @raw.body.chomp == 'true' end |
#info(id, options = nil, not_found = :reject, found = :return) ⇒ Hash
Get Acl info by ID rubocop:disable PerceivedComplexity, MethodLength, CyclomaticComplexity, AbcSize
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/diplomat/acl.rb', line 13 def info(id, = nil, not_found = :reject, found = :return) @id = id @options = url = ["/v1/acl/info/#{id}"] url << check_acl_token url << use_consistency() raw = @conn_no_err.get concat_url url if raw.status == 200 && raw.body.chomp != 'null' case found when :reject raise Diplomat::AclAlreadyExists, id when :return @raw = raw return parse_body end elsif raw.status == 200 && raw.body.chomp == 'null' case not_found when :reject raise Diplomat::AclNotFound, id when :return return nil end else raise Diplomat::UnknownStatus, "status #{raw.status}: #{raw.body}" end end |
#list ⇒ List
List all Acls
44 45 46 47 48 49 |
# File 'lib/diplomat/acl.rb', line 44 def list url = ['/v1/acl/list'] url += check_acl_token @raw = @conn_no_err.get concat_url url parse_body end |
#update(value) ⇒ Hash
Update an Acl definition, create if not present
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/diplomat/acl.rb', line 54 def update(value) raise Diplomat::IdParameterRequired unless value['ID'] @raw = @conn.put do |req| url = ['/v1/acl/update'] url += check_acl_token url += use_cas(@options) req.url concat_url url req.body = value.to_json end parse_body end |