class Aws::InstanceProfileCredentials

def refresh

def refresh
  if @no_refresh_until && @no_refresh_until > Time.now
    warn_expired_credentials
    return
  end
  # Retry loading credentials up to 3 times is the instance metadata
  # service is responding but is returning invalid JSON documents
  # in response to the GET profile credentials call.
  begin
    retry_errors([Aws::Json::ParseError], max_retries: 3) do
      c = Aws::Json.load(get_credentials.to_s)
      if empty_credentials?(@credentials)
        @credentials = Credentials.new(
          c['AccessKeyId'],
          c['SecretAccessKey'],
          c['Token']
        )
        @expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
        if @expiration && @expiration < Time.now
          @no_refresh_until = Time.now + refresh_offset
          warn_expired_credentials
        end
      else
        #  credentials are already set, update them only if the new ones are not empty
        if !c['AccessKeyId'] || c['AccessKeyId'].empty?
          # error getting new credentials
          @no_refresh_until = Time.now + refresh_offset
          warn_expired_credentials
        else
          @credentials = Credentials.new(
            c['AccessKeyId'],
            c['SecretAccessKey'],
            c['Token']
          )
          @expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
          if @expiration && @expiration < Time.now
            @no_refresh_until = Time.now + refresh_offset
            warn_expired_credentials
          end
        end
      end
    end
  rescue Aws::Json::ParseError
    raise Aws::Errors::MetadataParserError
  end
end