Class: Diplomat::Role
- Inherits:
-
RestClient
- Object
- RestClient
- Diplomat::Role
- Defined in:
- lib/diplomat/role.rb
Overview
Methods for interacting with the Consul ACL Role 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, options = {}) ⇒ Hash
Create a new ACL role.
-
#delete(id, options = {}) ⇒ Bool
Delete an ACL role by its UUID.
-
#list(options = {}) ⇒ List
List all the ACL roles.
-
#read(id, options = {}, not_found = :reject, found = :return) ⇒ Hash
Read ACL role with the given UUID rubocop:disable Metrics/PerceivedComplexity.
-
#read_name(name, options = {}, not_found = :reject, found = :return) ⇒ Hash
Read ACL role with the given name rubocop:disable Metrics/PerceivedComplexity.
-
#update(value, options = {}) ⇒ Hash
Update an existing ACL role.
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/role.rb', line 7 def acl @acl end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/diplomat/role.rb', line 7 def id @id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/diplomat/role.rb', line 7 def type @type end |
Instance Method Details
#create(value, options = {}) ⇒ Hash
Create a new ACL role
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/diplomat/role.rb', line 123 def create(value, = {}) blacklist = ['ID', 'iD', 'Id', :ID, :iD, :Id] & value.keys raise Diplomat::RoleMalformed, 'ID should not be specified' unless blacklist.empty? id = value[:Name] || value['Name'] raise Diplomat::NameParameterRequired if id.nil? custom_params = use_cas(@options) @raw = send_put_request(@conn, ['/v1/acl/role'], , value, custom_params) # rubocop:disable Style/GuardClause if @raw.status == 200 return parse_body elsif @raw.status == 500 && @raw.body.chomp.include?('already exists') raise Diplomat::RoleAlreadyExists, @raw.body else raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}" end end |
#delete(id, options = {}) ⇒ Bool
Delete an ACL role by its UUID
148 149 150 151 |
# File 'lib/diplomat/role.rb', line 148 def delete(id, = {}) @raw = send_delete_request(@conn, ["/v1/acl/role/#{id}"], , nil) @raw.body.chomp == 'true' end |
#list(options = {}) ⇒ List
List all the ACL roles
90 91 92 93 94 95 |
# File 'lib/diplomat/role.rb', line 90 def list( = {}) @raw = send_get_request(@conn_no_err, ['/v1/acl/roles'], ) raise Diplomat::AclNotFound if @raw.status == 403 parse_body end |
#read(id, options = {}, not_found = :reject, found = :return) ⇒ Hash
Read ACL role with the given UUID 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 39 40 41 42 43 44 45 |
# File 'lib/diplomat/role.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/role/#{id}"], , custom_params) if @raw.status == 200 && @raw.body.chomp != 'null' case found when :reject raise Diplomat::RoleNotFound, id when :return return parse_body end elsif @raw.status == 404 case not_found when :reject raise Diplomat::RoleNotFound, id when :return return nil 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 |
#read_name(name, options = {}, not_found = :reject, found = :return) ⇒ Hash
Read ACL role with the given name rubocop:disable Metrics/PerceivedComplexity
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/diplomat/role.rb', line 53 def read_name(name, = {}, not_found = :reject, found = :return) @options = custom_params = [] custom_params << use_consistency() @raw = send_get_request(@conn_no_err, ["/v1/acl/role/name/#{name}"], , custom_params) if @raw.status == 200 && @raw.body.chomp != 'null' case found when :reject raise Diplomat::RoleNotFound, name when :return return parse_body end elsif @raw.status == 404 case not_found when :reject raise Diplomat::RoleNotFound, name when :return return nil end elsif @raw.status == 403 case not_found when :reject raise Diplomat::AclNotFound, name when :return return nil end else raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}" end end |
#update(value, options = {}) ⇒ Hash
Update an existing ACL role
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/diplomat/role.rb', line 101 def update(value, = {}) id = value[:ID] || value['ID'] raise Diplomat::IdParameterRequired if id.nil? role_name = value[:Name] || value['Name'] raise Diplomat::NameParameterRequired if role_name.nil? custom_params = use_cas(@options) @raw = send_put_request(@conn, ["/v1/acl/role/#{id}"], , value, custom_params) if @raw.status == 200 parse_body elsif @raw.status == 400 raise Diplomat::RoleMalformed, @raw.body else raise Diplomat::UnknownStatus, "status #{@raw.status}: #{@raw.body}" end end |