Class: Supply::AbstractGoogleServiceClient
- Inherits:
-
Object
- Object
- Supply::AbstractGoogleServiceClient
- Defined in:
- supply/lib/supply/client.rb
Direct Known Subclasses
Constant Summary collapse
- SCOPE =
nil
- SERVICE =
nil
Instance Attribute Summary collapse
-
#client ⇒ Object
Connecting with Google.
Class Method Summary collapse
- .make_from_config(params: nil) ⇒ Object
-
.service_account_authentication(params: nil) ⇒ Object
Supply authentication file.
Instance Method Summary collapse
-
#initialize(service_account_json: nil, params: nil) ⇒ AbstractGoogleServiceClient
constructor
Initializes the service and its auth_client using the specified information.
Constructor Details
#initialize(service_account_json: nil, params: nil) ⇒ AbstractGoogleServiceClient
Initializes the service and its auth_client using the specified information
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'supply/lib/supply/client.rb', line 47 def initialize(service_account_json: nil, params: nil) auth_client = Google::Auth::ServiceAccountCredentials.make_creds(json_key_io: service_account_json, scope: self.class::SCOPE) UI.verbose("Fetching a new access token from Google...") auth_client.fetch_access_token! if FastlaneCore::Env.truthy?("DEBUG") Google::Apis.logger.level = Logger::DEBUG end Google::Apis::ClientOptions.default.application_name = "fastlane (supply client)" Google::Apis::ClientOptions.default.application_version = Fastlane::VERSION Google::Apis::ClientOptions.default.read_timeout_sec = params[:timeout] Google::Apis::ClientOptions.default.open_timeout_sec = params[:timeout] Google::Apis::ClientOptions.default.send_timeout_sec = params[:timeout] Google::Apis::RequestOptions.default.retries = 5 service = self.class::SERVICE.new service. = auth_client if params[:root_url] # Google's client expects the root_url string to end with "/". params[:root_url] << '/' unless params[:root_url].end_with?('/') service.root_url = params[:root_url] end self.client = service end |
Instance Attribute Details
#client ⇒ Object
Connecting with Google
13 14 15 |
# File 'supply/lib/supply/client.rb', line 13 def client @client end |
Class Method Details
.make_from_config(params: nil) ⇒ Object
15 16 17 18 19 |
# File 'supply/lib/supply/client.rb', line 15 def self.make_from_config(params: nil) params ||= Supply.config service_account_data = self.service_account_authentication(params: params) return self.new(service_account_json: service_account_data, params: params) end |
.service_account_authentication(params: nil) ⇒ Object
Supply authentication file
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'supply/lib/supply/client.rb', line 22 def self.service_account_authentication(params: nil) unless params[:json_key] || params[:json_key_data] if UI.interactive? UI.important("To not be asked about this value, you can specify it using 'json_key'") json_key_path = UI.input("The service account json file used to authenticate with Google: ") json_key_path = File.(json_key_path) UI.user_error!("Could not find service account json file at path '#{json_key_path}'") unless File.exist?(json_key_path) params[:json_key] = json_key_path else UI.user_error!("Could not load Google authentication. Make sure it has been added as an environment variable in 'json_key' or 'json_key_data'") end end if params[:json_key] service_account_json = File.open(File.(params[:json_key])) elsif params[:json_key_data] service_account_json = StringIO.new(params[:json_key_data]) end service_account_json end |