Class: AuditEvents::GoogleCloud::Authentication
- Inherits:
-
Object
- Object
- AuditEvents::GoogleCloud::Authentication
- Defined in:
- lib/audit_events/google_cloud/authentication.rb
Instance Method Summary collapse
- #generate_access_token(client_email, private_key) ⇒ Object
-
#initialize(scope:) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(scope:) ⇒ Authentication
Returns a new instance of Authentication.
6 7 8 |
# File 'lib/audit_events/google_cloud/authentication.rb', line 6 def initialize(scope:) @scope = scope end |
Instance Method Details
#generate_access_token(client_email, private_key) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/audit_events/google_cloud/authentication.rb', line 10 def generate_access_token(client_email, private_key) credentials = Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: StringIO.new({ client_email: client_email, private_key: private_key }.to_json), scope: @scope ) credentials.fetch_access_token!["access_token"] rescue StandardError => e ::Gitlab::ErrorTracking.track_exception(e, client_email: client_email) nil end |