-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Code adjustments to ensure that snippets for docs have all necessary info #2386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Updating personal fork
Ensures that variable definitions are captured in the region tags, so they'll show up in the documentation
Moved the variable definitions inside the functions so they would be captured by the region tags
'iam', 'v1', credentials=credentials) | ||
# [END iam_create_key] | ||
# [END iam_list_keys] | ||
# [END iam_delete_key] | ||
|
||
|
||
# [START iam_create_key] | ||
def create_key(service_account_email): | ||
"""Creates a key for a service account.""" | ||
|
||
# pylint: disable=no-member |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this disable=no-member directive is required anymore. Could you please delete it (in all cases) and re-run lint and see if an error occurs? If deleting it does cause an error to occur, we can re-add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
|
||
|
||
# [START iam_create_key] | ||
def create_key(service_account_email): | ||
"""Creates a key for a service account.""" | ||
|
||
# pylint: disable=no-member | ||
credentials = service_account.Credentials.from_service_account_file( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems strange that we have to define this at all since Cloud Client libraries handle this automatically. Are we certain that discovery is the right library to use and that discovery can't be coaxed to do this automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's my understanding that the user needs to create the credentials themselves so they can access the service account connected to their project. But really, my context for that is just this doc: https://cloud.google.com/iam/docs/quickstart-client-libraries#client-libraries-usage-python. Is that still relevant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping it would have a Cloud library somewhere but maybe it doesn't. At any rate, we can assume that's accurate for now. Thanks.
For some reason the CI is only running lint, not the actual tests. I will try to run them locally before approving. |
iam/api-client/service_accounts.py
Outdated
service_account['displayName'] = new_display_name | ||
service_account = service.projects().serviceAccounts().update( | ||
my_service_account['displayName'] = new_display_name | ||
my_service_account = service.projects().serviceAccounts().update( | ||
name=resource, body=service_account).execute() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is throwing an error in the test suite I ran manually and I believe it is because you need to rename "body=service_account" to "body=my_service_account". It's alarming that this test didn't run in CI, it must be disabled for some reason.
iam/api-client/service_accounts.py
Outdated
name=resource, body=service_account).execute() | ||
|
||
print('Updated display name for {} to: {}'.format( | ||
service_account['email'], service_account['displayName'])) | ||
return service_account | ||
service_account['email'], my_service_account['displayName'])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem here, need to rename service_account['email'] to my_service_account
I'm working on the following two docs:
https://cloud.google.com/iam/docs/creating-managing-service-accounts
https://cloud.google.com/iam/docs/creating-managing-service-account-keys
The python code snippets for these docs don't always capture the variables and imports necessary to run the code. To fix this, I made the following changes:
-Moved variable definitions to ensure that they would be captured in each code snippet
-Added additional region tags around imports
I may need help with linting--I couldn't figure out how to get Nox to work on my machine.