Module: Sensu::Settings::Validators::API

Included in:
Sensu::Settings::Validators
Defined in:
lib/sensu/settings/validators/api.rb

Instance Method Summary collapse

Instance Method Details

#validate_api(api) ⇒ Object

Validate a Sensu API definition. Validates: port, bind

Parameters:

  • api (Hash)

    sensu api definition.


50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sensu/settings/validators/api.rb', line 50

def validate_api(api)
  must_be_a_hash_if_set(api) ||
    invalid(api, "api must be a hash")
  if is_a_hash?(api)
    must_be_an_integer_if_set(api[:port]) ||
      invalid(api, "api port must be an integer")
    must_be_a_string_if_set(api[:bind]) ||
      invalid(api, "api bind must be a string")
    validate_api_authentication(api)
    validate_api_endpoints(api) if api[:endpoints]
  end
end

#validate_api_authentication(api) ⇒ Object

Validate API authentication. Validates: user, password

Parameters:

  • api (Hash)

    sensu api definition.


9
10
11
12
13
14
15
16
# File 'lib/sensu/settings/validators/api.rb', line 9

def validate_api_authentication(api)
  if either_are_set?(api[:user], api[:password])
    must_be_a_string(api[:user]) ||
      invalid(api, "api user must be a string")
    must_be_a_string(api[:password]) ||
      invalid(api, "api password must be a string")
  end
end

#validate_api_endpoints(api) ⇒ Object

Validate API endpoints. Validates: endpoints

Parameters:

  • api (Hash)

    sensu api definition.


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sensu/settings/validators/api.rb', line 22

def validate_api_endpoints(api)
  if is_an_array?(api[:endpoints])
    api[:endpoints].each do |endpoint|
      if is_a_hash?(endpoint)
        if endpoint[:url]
          must_be_a_string(endpoint[:url]) ||
            invalid(api, "api endpoint url must be a string")
        else
          must_be_a_string(endpoint[:host]) ||
            invalid(api, "api endpoint host must be a string")
          must_be_an_integer(endpoint[:port]) ||
            invalid(api, "api endpoint port must be an integer")
          must_be_boolean_if_set(endpoint[:ssl]) ||
            invalid(api, "api endpoint ssl must be a boolean")
        end
      else
        invalid(api, "api endpoints must each be a hash")
      end
    end
  else
    invalid(api, "api endpoints must be an array")
  end
end