-
Notifications
You must be signed in to change notification settings - Fork 249
Support configuring the author email address for git. #1128
Changes from 1 commit
c560e82
feb6999
9cee4d3
b841495
65b864f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,13 +34,15 @@ | |
'flags': create.flags, | ||
'run': create.run, | ||
'require-zone': True, | ||
'require-email': True, | ||
}, | ||
'connect': { | ||
'help': 'Connect to an existing Datalab instance', | ||
'description': connect.description, | ||
'flags': connect.flags, | ||
'run': connect.run, | ||
'require-zone': True, | ||
'require-email': False, | ||
}, | ||
'list': { | ||
'help': 'List the existing Datalab instances in a project', | ||
|
@@ -49,20 +51,23 @@ | |
'flags': list.flags, | ||
'run': list.run, | ||
'require-zone': False, | ||
'require-email': False, | ||
}, | ||
'stop': { | ||
'help': 'Stop an existing Datalab instance', | ||
'description': stop.description, | ||
'flags': stop.flags, | ||
'run': stop.run, | ||
'require-zone': True, | ||
'require-email': False, | ||
}, | ||
'delete': { | ||
'help': 'Delete an existing Datalab instance', | ||
'description': delete.description, | ||
'flags': delete.flags, | ||
'run': delete.run, | ||
'require-zone': True, | ||
'require-email': False, | ||
}, | ||
} | ||
|
||
|
@@ -93,6 +98,10 @@ | |
environment variable CLOUDSDK_COMPUTE_ZONE. | ||
""") | ||
|
||
_EMAIL_HELP = ("""The email address associated with the instance. | ||
|
||
This should represent the user of Datalab.""") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should add something about using the email for git here, otherwise it's not clear why this is suddenly required |
||
|
||
|
||
try: | ||
with open(os.devnull, 'w') as dn: | ||
|
@@ -128,6 +137,19 @@ def gcloud_compute( | |
cmd, stdin=stdin, stdout=stdout, stderr=stderr) | ||
|
||
|
||
def get_email_address(): | ||
"""Get the email address of the user's active gcloud account. | ||
|
||
Returns: | ||
|
||
Raises: | ||
subprocess.CalledProcessError: If the gcloud command fails | ||
""" | ||
return subprocess.check_output([ | ||
gcloud_cmd, 'auth', 'list', '--quiet', '--format', | ||
'value(account)', '--filter', 'status:ACTIVE']) | ||
|
||
|
||
def run(): | ||
"""Run the command line tool.""" | ||
parser = argparse.ArgumentParser( | ||
|
@@ -170,6 +192,12 @@ def run(): | |
dest='zone', | ||
default=None, | ||
help=_ZONE_HELP) | ||
if command_config['require-email']: | ||
subcommand_parser.add_argument( | ||
'--email', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A question:
Thought:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a temporary solution I am using to test the changes to the Docker image. This change isn't ready for review yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, this is ready for review now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think my comment still holds ... about this being worded as email in the flags, as opposed to git-user or something that indicates use. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, the '--email' flag is now gone. |
||
dest='email', | ||
default=get_email_address(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be a required argument instead of using service account? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wouldn't default to a service account unless the user runs |
||
help=_EMAIL_HELP) | ||
|
||
args = parser.parse_args() | ||
try: | ||
|
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.
Should this fail instead of using the service account for git, which is a bad config in this case?
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 don't agree that using the service account is a bad config.
It may be ugly, but it is technically correct. Additionally, advanced users may create descriptively named service accounts for which the service account is actually the best email address to use.
More importantly, we don't expect that case to actually happen.
Users will usually use the CLI to create Datalab instances running in GCE VMs, and that tool will set the right environment variable.
That means the case where this will happen is for someone running Datalab locally, and in that case their gcloud credentials should be the right email address to use.