Class: Spikard::ApiKeyConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/spikard/config.rb

Overview

API key authentication configuration.

Validates API keys from request headers. Keys are matched exactly.

Examples:

api_key = ApiKeyConfig.new(
  keys: ['key-1', 'key-2', 'key-3'],
  header_name: 'X-API-Key'
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keys:, header_name: 'X-API-Key') ⇒ ApiKeyConfig

Returns a new instance of ApiKeyConfig.

Parameters:

  • keys (Array<String>)

    List of valid API keys

  • header_name (String) (defaults to: 'X-API-Key')

    HTTP header name to check for API key (default: “X-API-Key”)



104
105
106
107
# File 'lib/spikard/config.rb', line 104

def initialize(keys:, header_name: 'X-API-Key')
  @keys = keys
  @header_name = header_name
end

Instance Attribute Details

#header_nameObject

Returns the value of attribute header_name.



100
101
102
# File 'lib/spikard/config.rb', line 100

def header_name
  @header_name
end

#keysObject

Returns the value of attribute keys.



100
101
102
# File 'lib/spikard/config.rb', line 100

def keys
  @keys
end