module MuchKeys class KeyValidator class << self # key should pass validation rules def valid? keyname exists?(keyname) && secret_key_has_namespace?(keyname) end def secret_key_namespace keyname match = keyname.match(/^secrets\/(.*?)\/.*/) if match match[1] else "" end end 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 def is_secret? keyname keyname.match(/^secret/) != nil end private def exists? keyname !keyname.nil? && !keyname.empty? end end end end