Class: Muchkeys::KeyValidator
- Inherits:
-
Object
- Object
- Muchkeys::KeyValidator
- Defined in:
- lib/muchkeys/key_validator.rb
Instance Attribute Summary collapse
-
#app_client ⇒ Object
Returns the value of attribute app_client.
Instance Method Summary collapse
-
#initialize(app_client) ⇒ KeyValidator
constructor
A new instance of KeyValidator.
- #is_secret?(keyname) ⇒ Boolean
- #secret_key_has_namespace?(keyname) ⇒ Boolean
- #secret_key_namespace(keyname) ⇒ Object
-
#valid?(keyname) ⇒ Boolean
(also: #valid_key_name?)
key should pass validation rules.
Constructor Details
#initialize(app_client) ⇒ KeyValidator
Returns a new instance of KeyValidator.
6 7 8 |
# File 'lib/muchkeys/key_validator.rb', line 6 def initialize(app_client) @app_client = app_client end |
Instance Attribute Details
#app_client ⇒ Object
Returns the value of attribute app_client.
3 4 5 |
# File 'lib/muchkeys/key_validator.rb', line 3 def app_client @app_client end |
Instance Method Details
#is_secret?(keyname) ⇒ Boolean
37 38 39 |
# File 'lib/muchkeys/key_validator.rb', line 37 def is_secret?(keyname) keyname.match(/^secret/) != nil end |
#secret_key_has_namespace?(keyname) ⇒ Boolean
27 28 29 30 31 32 33 34 35 |
# File 'lib/muchkeys/key_validator.rb', line 27 def secret_key_has_namespace?(keyname) if is_secret?(keyname) namespace = secret_key_namespace(keyname) exists?(namespace) else # a plain key passes, it doesn't need a namespace true end end |
#secret_key_namespace(keyname) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/muchkeys/key_validator.rb', line 18 def secret_key_namespace(keyname) match = keyname.match(/^secrets\/(.*?)\/.*/) if match match[1] else "" end end |
#valid?(keyname) ⇒ Boolean Also known as: valid_key_name?
key should pass validation rules
12 13 14 15 |
# File 'lib/muchkeys/key_validator.rb', line 12 def valid?(keyname) exists?(keyname) && secret_key_has_namespace?(keyname) end |