Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
merged 14 commits into from
Sep 11, 2019
Merged

Conversation

melaniedejong
Copy link
Collaborator

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.

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
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 9, 2019
Solved redundancy between global "service_account" and local variable "service_account" in create_service_account and rename_service_account by changing the name of the local variable to "my_service_account"
'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
Copy link
Member

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.

Copy link
Collaborator Author

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(
Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Member

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.

@andrewsg
Copy link
Member

For some reason the CI is only running lint, not the actual tests. I will try to run them locally before approving.

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()
Copy link
Member

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.

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']))
Copy link
Member

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

@andrewsg andrewsg merged commit ba1b681 into GoogleCloudPlatform:master Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.