Create generate_self_signed_jwt.py#1414
Open
riathakkar wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
Open
Create generate_self_signed_jwt.py#1414riathakkar wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
riathakkar wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
Conversation
dazuma
suggested changes
May 3, 2024
Contributor
dazuma
left a comment
There was a problem hiding this comment.
Do you have tests for this file?
Contributor
There was a problem hiding this comment.
This needs to be .rb not .py.
| require "googleauth" | ||
| require "google/cloud/iam_credentials/v1" | ||
| require "jwt" | ||
|
|
Contributor
There was a problem hiding this comment.
Should there be region tags in this file?
| require "google/cloud/iam_credentials/v1" | ||
| require "jwt" | ||
|
|
||
| def generate_jwt_payload(service_account_email, resource_url) |
Contributor
There was a problem hiding this comment.
Please remove the parentheses where possible.
| }.to_json | ||
| end | ||
|
|
||
| def sign_jwt(target_sa, resource_url) |
| def sign_jwt(target_sa, resource_url) | ||
| scope = "https://www.googleapis.com/auth/iam" | ||
| credentials = Google::Auth.get_application_default([scope]) | ||
| iam_client = Google::Cloud::IamCredentials::V1::IAMCredentials::Client.new(credentials: credentials) |
| end | ||
|
|
||
| def sign_jwt_with_key_file(credential_key_file_path, resource_url) | ||
| key_data = JSON.parse(File.read(credential_key_file_path)) |
Contributor
There was a problem hiding this comment.
Remove parentheses on this line and the line above it
| private_key_id = key_data["private_key_id"] | ||
| service_account_email = key_data["client_email"] | ||
|
|
||
| payload = generate_jwt_payload(service_account_email, resource_url) |
|
|
||
| JWT.encode( | ||
| payload, | ||
| OpenSSL::PKey::RSA.new(private_key), |
Contributor
There was a problem hiding this comment.
Do you need to require "openssl" for this to work?
| iam_client = Google::Cloud::IamCredentials::V1::IAMCredentials::Client.new(credentials: credentials) | ||
|
|
||
| response = iam_client.sign_jwt( | ||
| name: iam_client.service_account_path('-', target_sa), |
Contributor
There was a problem hiding this comment.
Please use double quotes for strings.
|
|
||
| require "googleauth" | ||
| require "google/cloud/iam_credentials/v1" | ||
| require "jwt" |
Contributor
There was a problem hiding this comment.
The JWT and IAM Credentials client gems probably need to be added to the Gemfile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Upload sample script for IAP public documentation update.
This will be documented the IAP public documentation
Note: It's a good idea to open an issue first for discussion.
Checklist
bundle exec rubocop