Class: Diplomat::Token
- Inherits:
-
RestClient
- Object
- RestClient
- Diplomat::Token
- Defined in:
- lib/diplomat/token.rb
Overview
Methods for interacting with the Consul ACL Policy 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
-
#clone(value, options = {}) ⇒ Hash
Clone an existing ACL token.
-
#create(value, options = {}) ⇒ Hash
Create a new ACL token.
-
#delete(id, options = {}) ⇒ Bool
Delete an existing ACL token.
-
#list(policy = nil, role = nil, authmethod = nil, options = {}) ⇒ List
List all the ACL tokens.
-
#read(id, options = {}, not_found = :reject, found = :return) ⇒ Hash
Read ACL token with the given Accessor ID rubocop:disable Metrics/PerceivedComplexity.
-
#self(options = {}) ⇒ Hash
Returns ACL token details matching X-Consul-Token header.
-
#update(value, options = {}) ⇒ Hash
Update an existing ACL token.
Methods inherited from RestClient
access_method?, #concat_url, #configuration, #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/token.rb', line 7 def acl @acl end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/diplomat/token.rb', line 7 def id @id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/diplomat/token.rb', line 7 def type @type end |
Instance Method Details
#clone(value, options = {}) ⇒ Hash
Clone an existing ACL token
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/diplomat/token.rb', line 107 def clone(value, = {}) id = value[:AccessorID] || value['AccessorID'] raise Diplomat::AccessorIdParameterRequired if id.nil? custom_params = use_cas(@options) @raw = send_put_request(@conn, ["/v1/acl/token/#{id}/clone"], , value, custom_params) if @raw.status == 200 parse_body elsif @raw.status == 403 raise Diplomat::AclNotFound, id else raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}" end end |
#create(value, options = {}) ⇒ Hash
Create a new ACL token
83 84 85 86 87 88 89 |
# File 'lib/diplomat/token.rb', line 83 def create(value, = {}) custom_params = use_cas(@options) @raw = send_put_request(@conn, ['/v1/acl/token'], , value, custom_params) return parse_body if @raw.status == 200 raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}" end |
#delete(id, options = {}) ⇒ Bool
Delete an existing ACL token
95 96 97 98 99 100 101 |
# File 'lib/diplomat/token.rb', line 95 def delete(id, = {}) anonymous_token = '00000000-0000-0000-0000-000000000002' raise Diplomat::NotPermitted, "status #{@raw.status}: #{@raw.body}" if id == anonymous_token @raw = send_delete_request(@conn, ["/v1/acl/token/#{id}"], , nil) @raw.body.chomp == 'true' end |
#list(policy = nil, role = nil, authmethod = nil, options = {}) ⇒ List
List all the ACL tokens
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/diplomat/token.rb', line 47 def list(policy = nil, role = nil, authmethod = nil, = {}) custom_params = [] custom_params << use_named_parameter('policy', policy) if policy custom_params << use_named_parameter('role', policy) if role custom_params << use_named_parameter('authmethod', policy) if authmethod @raw = send_get_request(@conn_no_err, ['/v1/acl/tokens'], , custom_params) raise Diplomat::AclNotFound if @raw.status == 403 parse_body end |
#read(id, options = {}, not_found = :reject, found = :return) ⇒ Hash
Read ACL token with the given Accessor ID rubocop:disable Metrics/PerceivedComplexity
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 |
# File 'lib/diplomat/token.rb', line 14 def read(id, = {}, not_found = :reject, found = :return) @options = custom_params = [] custom_params << use_consistency() @raw = send_get_request(@conn_no_err, ["/v1/acl/token/#{id}"], , custom_params) if @raw.status == 200 && @raw.body.chomp != 'null' case found when :reject raise Diplomat::AclNotFound, id when :return return parse_body end elsif @raw.status == 403 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 |
#self(options = {}) ⇒ Hash
Returns ACL token details matching X-Consul-Token header
125 126 127 128 129 130 131 132 133 |
# File 'lib/diplomat/token.rb', line 125 def self( = {}) custom_params = use_cas(@options) @raw = send_get_request(@conn, ['/v1/acl/token/self'], , custom_params) if @raw.status == 200 parse_body elsif @raw.status == 403 raise Diplomat::AclNotFound, id end end |
#update(value, options = {}) ⇒ Hash
Update an existing ACL token
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/diplomat/token.rb', line 62 def update(value, = {}) id = value[:AccessorID] || value['AccessorID'] raise Diplomat::AccessorIdParameterRequired if id.nil? custom_params = use_cas(@options) @raw = send_put_request(@conn, ["/v1/acl/token/#{id}"], , value, custom_params) if @raw.status == 200 parse_body elsif @raw.status == 403 raise Diplomat::AclNotFound, id elsif @raw.status == 400 raise Diplomat::TokenMalformed, @raw.body else raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}" end end |