Class: RailsCloudTasks::Credentials
- Inherits:
-
Object
- Object
- RailsCloudTasks::Credentials
- Defined in:
- lib/rails_cloud_tasks/credentials.rb
Constant Summary collapse
- DEFAULT_SCOPES =
['https://www.googleapis.com/auth/cloud-platform'].freeze
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#iam_credential ⇒ Object
readonly
Returns the value of attribute iam_credential.
-
#request_options ⇒ Object
readonly
Returns the value of attribute request_options.
-
#token_request ⇒ Object
readonly
Returns the value of attribute token_request.
Instance Method Summary collapse
- #generate(impersonate_account = nil, scopes = []) ⇒ Object
-
#initialize(request_options: Google::Apis::RequestOptions.new, iam_credential: Google::Apis::IamcredentialsV1::IAMCredentialsService.new, token_request: Google::Apis::IamcredentialsV1::GenerateAccessTokenRequest, auth: Google::Auth) ⇒ Credentials
constructor
A new instance of Credentials.
Constructor Details
#initialize(request_options: Google::Apis::RequestOptions.new, iam_credential: Google::Apis::IamcredentialsV1::IAMCredentialsService.new, token_request: Google::Apis::IamcredentialsV1::GenerateAccessTokenRequest, auth: Google::Auth) ⇒ Credentials
Returns a new instance of Credentials.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rails_cloud_tasks/credentials.rb', line 9 def initialize( request_options: Google::Apis::RequestOptions.new, iam_credential: Google::Apis::IamcredentialsV1::IAMCredentialsService.new, token_request: Google::Apis::IamcredentialsV1::GenerateAccessTokenRequest, auth: Google::Auth ) @auth = auth @request_options = @iam_credential = iam_credential @token_request = token_request end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
7 8 9 |
# File 'lib/rails_cloud_tasks/credentials.rb', line 7 def auth @auth end |
#iam_credential ⇒ Object (readonly)
Returns the value of attribute iam_credential.
7 8 9 |
# File 'lib/rails_cloud_tasks/credentials.rb', line 7 def iam_credential @iam_credential end |
#request_options ⇒ Object (readonly)
Returns the value of attribute request_options.
7 8 9 |
# File 'lib/rails_cloud_tasks/credentials.rb', line 7 def @request_options end |
#token_request ⇒ Object (readonly)
Returns the value of attribute token_request.
7 8 9 |
# File 'lib/rails_cloud_tasks/credentials.rb', line 7 def token_request @token_request end |
Instance Method Details
#generate(impersonate_account = nil, scopes = []) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rails_cloud_tasks/credentials.rb', line 21 def generate(impersonate_account = nil, scopes = []) current_scopes = DEFAULT_SCOPES + scopes = auth.get_application_default(current_scopes).dup . = if impersonate_account iam_credential.generate_service_account_access_token( "projects/-/serviceAccounts/#{impersonate_account}", token_request.new(scope: current_scopes, lifetime: '3600s'), options: ) end . end |