Class: RooOnRails::Concerns::RequireApiKey::ClientApiKeys
- Inherits:
-
Object
- Object
- RooOnRails::Concerns::RequireApiKey::ClientApiKeys
- Includes:
- Singleton
- Defined in:
- lib/roo_on_rails/concerns/require_api_key.rb
Constant Summary collapse
- CLIENT_KEY_NAME_SUFFIX_REGEX =
/_CLIENT_KEY\Z/
Instance Method Summary collapse
-
#initialize ⇒ ClientApiKeys
constructor
A new instance of ClientApiKeys.
- #valid?(service_name, client_key) ⇒ Boolean
Constructor Details
#initialize ⇒ ClientApiKeys
Returns a new instance of ClientApiKeys.
77 78 79 80 81 82 |
# File 'lib/roo_on_rails/concerns/require_api_key.rb', line 77 def initialize @cache = ENV.select { |key| key =~ CLIENT_KEY_NAME_SUFFIX_REGEX } .map { |k, v| [service_name(k), parse_client_keys(v)] } .to_h .freeze end |
Instance Method Details
#valid?(service_name, client_key) ⇒ Boolean
84 85 86 87 88 89 90 |
# File 'lib/roo_on_rails/concerns/require_api_key.rb', line 84 def valid?(service_name, client_key) return false if service_name.to_s.empty? || client_key.to_s.empty? client_keys = @cache[normalize(service_name)] return false unless client_keys client_keys.include?(client_key) end |