class Google::Auth::IDTokens::HttpKeySource
override {HttpKeySource#interpret_json} to parse the response.
A base key source that downloads keys from a URI. Subclasses should
#
def initialize uri, retry_interval: nil
-
retry_interval
(Integer, nil
) -- Override the retry interval in -
uri
(String, URI
) -- The URI from which to download keys.
def initialize uri, retry_interval: nil @uri = URI uri @retry_interval = retry_interval || DEFAULT_RETRY_INTERVAL @allow_refresh_at = Time.now @current_keys = [] @monitor = Monitor.new end
def interpret_json _data
def interpret_json _data nil end
def refresh_keys
-
(KeySourceError)
- if key retrieval failed.
Returns:
-
(Array
-)
def refresh_keys @monitor.synchronize do return @current_keys if Time.now < @allow_refresh_at @allow_refresh_at = Time.now + @retry_interval response = Net::HTTP.get_response uri raise KeySourceError, "Unable to retrieve data from #{uri}" unless response.is_a? Net::HTTPSuccess data = begin JSON.parse response.body rescue JSON::ParserError raise KeySourceError, "Unable to parse JSON" end @current_keys = Array(interpret_json(data)) end end