Class: LanguageOperator::Agent::WebhookAuthenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/language_operator/agent/webhook_authenticator.rb

Overview

Executes webhook authentication checks

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject (readonly)

Returns the value of attribute logger.



14
15
16
# File 'lib/language_operator/agent/webhook_authenticator.rb', line 14

def logger
  @logger
end

Class Method Details

.authenticate(authentication, context) ⇒ Boolean

Authenticate a webhook request

Parameters:

Returns:

  • (Boolean)

    true if authenticated, false otherwise



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/language_operator/agent/webhook_authenticator.rb', line 22

def self.authenticate(authentication, context)
  return true unless authentication # No authentication required

  case authentication.type
  when :signature
    verify_signature(authentication.config, context)
  when :api_key
    verify_api_key(authentication.config, context)
  when :bearer_token
    verify_bearer_token(authentication.config, context)
  when :basic_auth
    verify_basic_auth(authentication.config, context)
  when :custom
    verify_custom(authentication.config, context)
  when :any_of
    verify_any_of(authentication.config, context)
  when :all_of
    verify_all_of(authentication.config, context)
  else
    false
  end
end

.validate(validations, context) ⇒ Array<String>

Execute validations

Parameters:

  • validations (Array<Hash>)

    Validation definitions

  • context (Hash)

    Request context

Returns:

  • (Array<String>)

    Validation errors (empty if valid)



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/language_operator/agent/webhook_authenticator.rb', line 177

def self.validate(validations, context)
  errors = []

  validations.each do |validation|
    case validation[:type]
    when :headers
      errors.concat(validate_headers(validation[:config], context))
    when :content_type
      errors.concat(validate_content_type(validation[:config], context))
    when :custom
      result = validation[:config].call(context)
      errors << result unless result == true
    end
  end

  errors.compact
end