class Contentful::Scheduler::Auth
Attributes
webhook[R]
Public Class Methods
new(webhook)
click to toggle source
# File lib/contentful/scheduler/auth.rb, line 6 def initialize(webhook) @webhook = webhook end
Public Instance Methods
auth()
click to toggle source
# File lib/contentful/scheduler/auth.rb, line 10 def auth return true if auth_config.nil? return verify_key_value_config if key_value_config? return verify_lambda_config if lambda_config? false end
Private Instance Methods
auth_config()
click to toggle source
# File lib/contentful/scheduler/auth.rb, line 52 def auth_config ::Contentful::Scheduler.config .fetch(:spaces, {}) .fetch(space_id, {}) .fetch(:auth, nil) end
key_value_config?()
click to toggle source
# File lib/contentful/scheduler/auth.rb, line 21 def key_value_config? auth_config.key?(:key) && auth_config.key?(:valid_tokens) end
lambda_config?()
click to toggle source
# File lib/contentful/scheduler/auth.rb, line 36 def lambda_config? auth_config.key?(:key) && auth_config.key?(:validation) end
space_id()
click to toggle source
# File lib/contentful/scheduler/auth.rb, line 59 def space_id webhook.space_id end
verify_key_value_config()
click to toggle source
# File lib/contentful/scheduler/auth.rb, line 25 def verify_key_value_config value = webhook.raw_headers[auth_config[:key]] return false if value.nil? valid_tokens = auth_config[:valid_tokens] return valid_tokens.include?(value) if valid_tokens.is_a?(::Array) valid_tokens == value end
verify_lambda_config()
click to toggle source
# File lib/contentful/scheduler/auth.rb, line 40 def verify_lambda_config value = webhook.raw_headers[auth_config[:key]] return false if value.nil? validation = auth_config[:validation] return false unless validation.is_a?(::Proc) validation[value] end