class Riffer::Providers::GoogleCloud::Client
Riffer.config.google_cloud.client accepts any object implementing post and post_stream (see Riffer::HTTP::Client); this class is the default, not a required base. Paths are relative to the client’s v1/projects/{project_id}/locations/{location} resource.
Constants
- AUTH_LOCK
-
googleauth’s metadata-server lookups (GCE, Cloud Run, GKE) go through a process-wide google-cloud-env cache that detects reentrancy by Thread, so two fibers inside it at once raise ThreadError. Every googleauth call that can reach it holds this lock; Ruby’s Mutex is fiber-aware, so waiters yield to the scheduler instead of blocking the thread.
- SCOPE
-
@rbs @project_id: String @rbs @location: String @rbs @credentials: untyped @rbs @base_url: String @rbs self.@application_default_credentials: untyped
- VALID_LOCATION_PATTERN
- VALID_PROJECT_ID_PATTERN
-
Both are interpolated into the endpoint’s host or path.
Public Class Methods
Source
# File lib/riffer/providers/google_cloud/client.rb, line 30 def self.application_default_credentials AUTH_LOCK.synchronize do @application_default_credentials ||= begin Riffer::Helpers::Dependencies.depends_on("googleauth") Google::Auth.get_application_default([SCOPE]) end end end
Memoized process-wide so every client shares one token cache.
Source
# File lib/riffer/providers/google_cloud/client.rb, line 41 def self.base_url_for(location:) case location when "global" then "https://aiplatform.googleapis.com" when "us", "eu" then "https://aiplatform.#{location}.rep.googleapis.com" else "https://#{location}-aiplatform.googleapis.com" end end
Source
# File lib/riffer/providers/google_cloud/client.rb, line 51 def self.from_config(config) project_id = config.project_id raise Riffer::ArgumentError, "Riffer.config.google_cloud.project_id must be set" unless project_id new(project_id: project_id, location: config.location, credentials: config.credentials) end
Source
# File lib/riffer/providers/google_cloud/client.rb, line 62 def initialize(project_id:, location:, credentials: nil, base_url: nil, headers: {}, connection: nil) validate!(project_id, VALID_PROJECT_ID_PATTERN, "project_id") validate!(location, VALID_LOCATION_PATTERN, "location") super(headers: headers, connection: connection) @project_id = project_id @location = location @credentials = credentials @base_url = (base_url || self.class.base_url_for(location: location)).chomp("/") end
credentials is a googleauth credentials object (anything responding to updater_proc); nil resolves Application Default Credentials.
Riffer::HTTP::Client::new