Class: Fastlane::FirebaseTestLab::Credential

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/firebase_test_lab/helper/credential.rb

Instance Method Summary collapse

Constructor Details

#initialize(key_file_path: nil) ⇒ Credential

Returns a new instance of Credential.



6
7
8
# File 'lib/fastlane/plugin/firebase_test_lab/helper/credential.rb', line 6

def initialize(key_file_path: nil)
  @key_file_path = key_file_path
end

Instance Method Details

#get_google_credential(scopes) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fastlane/plugin/firebase_test_lab/helper/credential.rb', line 10

def get_google_credential(scopes)
  unless @key_file_path
    begin
      return Google::Auth.get_application_default(scopes)
    rescue => ex
      UI.abort_with_message!("Failed reading application default credential. Either the Oauth credential should be provided or Google Application Default Credential should be configured: #{ex.message}")
    end
  end

  File.open(File.expand_path(@key_file_path), "r") do |file|
    options = {
      json_key_io: file,
      scope: scopes
    }
    begin
      return Google::Auth::ServiceAccountCredentials.make_creds(options)
    rescue => ex
      UI.abort_with_message!("Failed reading OAuth credential: #{ex.message}")
    end
  end
end