Top Level Namespace
Defined Under Namespace
Modules: Momento
Instance Method Summary collapse
Instance Method Details
#base64?(string) ⇒ Boolean
150 151 152 153 154 155 156 157 |
# File 'lib/momento/auth/credential_provider.rb', line 150 def base64?(string) return false if string.nil? || string.empty? Base64.strict_decode64(string) true rescue ArgumentError false end |
#v2_api_key?(api_key) ⇒ Boolean
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/momento/auth/credential_provider.rb', line 159 def v2_api_key?(api_key) false if base64?(api_key) key_parts = api_key.split('.') raise Momento::Error::InvalidArgumentError, 'Malformed legacy API key' if key_parts.size != 3 decoded_key = Base64.decode64(key_parts[1]) key_json = JSON.parse(decoded_key, symbolize_names: true) key_json[:t] == 'g' rescue ArgumentError, JSON::ParserError false end |