Class: Diplomat::Acl

Inherits:
RestClient show all
Defined in:
lib/diplomat/acl.rb

Overview

Methods for interacting with the Consul ACL API endpoint

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aclObject (readonly)

Returns the value of attribute acl.



7
8
9
# File 'lib/diplomat/acl.rb', line 7

def acl
  @acl
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/diplomat/acl.rb', line 7

def id
  @id
end

#typeObject (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, options = {}) ⇒ Hash

Create an Acl definition

Parameters:

  • value (Hash)

    Acl definition, ID field is mandatory

  • options (Hash) (defaults to: {})

    options parameter hash

Returns:

  • (Hash)

    The result Acl



67
68
69
70
71
# File 'lib/diplomat/acl.rb', line 67

def create(value, options = {})
  custom_params = use_cas(@options)
  @raw = send_put_request(@conn, ['/v1/acl/create'], options, value, custom_params)
  parse_body
end

#destroy(id, options = {}) ⇒ Bool

Destroy an ACl token by its id

Parameters:

  • ID (String)

    the Acl ID

  • options (Hash) (defaults to: {})

    options parameter hash

Returns:

  • (Bool)

    true if operation succeeded



77
78
79
80
81
# File 'lib/diplomat/acl.rb', line 77

def destroy(id, options = {})
  @id = id
  @raw = send_put_request(@conn, ["/v1/acl/destroy/#{@id}"], options, nil)
  @raw.body.chomp == 'true'
end

#info(id, options = {}, not_found = :reject, found = :return) ⇒ Hash

Get Acl info by ID rubocop:disable Metrics/PerceivedComplexity

Parameters:

  • id (String)

    ID of the Acl to get

  • options (Hash) (defaults to: {})

    options parameter hash

Returns:

  • (Hash)


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
# File 'lib/diplomat/acl.rb', line 14

def info(id, options = {}, not_found = :reject, found = :return)
  @id = id
  @options = options
  custom_params = []
  custom_params << use_consistency(options)

  raw = send_get_request(@conn_no_err, ["/v1/acl/info/#{id}"], options, custom_params)

  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(options = {}) ⇒ List

List all Acls

Parameters:

  • options (Hash) (defaults to: {})

    options parameter hash

Returns:

  • (List)

    list of [Hash] of Acls



46
47
48
49
# File 'lib/diplomat/acl.rb', line 46

def list(options = {})
  @raw = send_get_request(@conn_no_err, ['/v1/acl/list'], options)
  parse_body
end

#update(value, options = {}) ⇒ Hash

Update an Acl definition, create if not present

Parameters:

  • value (Hash)

    Acl definition, ID field is mandatory

  • options (Hash) (defaults to: {})

    options parameter hash

Returns:

  • (Hash)

    The result Acl

Raises:



55
56
57
58
59
60
61
# File 'lib/diplomat/acl.rb', line 55

def update(value, options = {})
  raise Diplomat::IdParameterRequired unless value['ID'] || value[:ID]

  custom_params = use_cas(@options)
  @raw = send_put_request(@conn, ['/v1/acl/update'], options, value, custom_params)
  parse_body
end