Skip to content

Commit

Permalink
[UX/Core] Remove dots in user name (#3528)
Browse files Browse the repository at this point in the history
* Remove dots in user name

* truncate and format
  • Loading branch information
Michaelvll authored May 9, 2024
1 parent 7f30ce5 commit caca2ad
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sky/utils/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,15 +606,19 @@ def validate_schema(obj, schema, err_msg_prefix='', skip_none=True):


def get_cleaned_username(username: str = '') -> str:
"""Cleans the username. Dots and underscores are allowed, as we will
"""Cleans the username. Underscores are allowed, as we will
handle it when mapping to the cluster_name_on_cloud in
common_utils.make_cluster_name_on_cloud.
Clean up includes:
1. Making all characters lowercase
2. Removing any non-alphanumeric characters (excluding hyphens)
2. Removing any non-alphanumeric characters (excluding hyphens and
underscores)
3. Removing any numbers and/or hyphens at the start of the username.
4. Removing any hyphens at the end of the username
5. Truncate the username to 63 characters, as requested by GCP labels
Dots are removed due to: https://cloud.google.com/compute/docs/labeling-resources#requirements # pylint: disable=line-too-long
e.g. 1SkY-PiLot2- becomes sky-pilot2
Expand All @@ -623,9 +627,10 @@ def get_cleaned_username(username: str = '') -> str:
"""
username = username or getpass.getuser()
username = username.lower()
username = re.sub(r'[^a-z0-9-._]', '', username)
username = re.sub(r'[^a-z0-9-_]', '', username)
username = re.sub(r'^[0-9-]+', '', username)
username = re.sub(r'-$', '', username)
username = username[:63]
return username


Expand Down

0 comments on commit caca2ad

Please sign in to comment.