Module: Rox::Core::Helpers::ApiKey
- Included in:
- Core, StateSender, Server::RoxOptions
- Defined in:
- lib/rox/core/helpers/api_key.rb
Constant Summary collapse
- MONGO_API_KEY_PATTERN =
/^[a-f\d]{24}$/
- UUID_API_KEY_PATTERN =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
Instance Method Summary collapse
Instance Method Details
#is_cbp?(api_key) ⇒ Boolean
9 10 11 12 13 |
# File 'lib/rox/core/helpers/api_key.rb', line 9 def is_cbp?(api_key) validate_api_key(api_key) && UUID_API_KEY_PATTERN.match?(api_key) rescue ArgumentError false end |
#validate_api_key(api_key) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/rox/core/helpers/api_key.rb', line 15 def validate_api_key(api_key) if api_key&.strip&.empty? raise ArgumentError, 'Blank Rollout api key - must be specified' elsif !MONGO_API_KEY_PATTERN.match(api_key) && !UUID_API_KEY_PATTERN.match(api_key) raise ArgumentError, 'Illegal Rollout api key' else true end end |