Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import ssl
import sys
import uuid
import base64

from six.moves.urllib.request import urlopen # pylint: disable=import-error
from six.moves.urllib.parse import urlparse # pylint: disable=import-error
Expand Down Expand Up @@ -1356,7 +1357,10 @@ def create_policy_assignment(cmd, policy=None, policy_set_definition=None,
identity = _build_identities_info(cmd, assign_identity)
assignment.identity = identity

createdAssignment = policy_client.policy_assignments.create(scope, name or uuid.uuid4(), assignment)
if name is None:
name = (base64.urlsafe_b64encode(uuid.uuid4().bytes).decode())[:-2]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uuid4 [](start = 46, length = 5)

why not just cut the uuid?

Copy link
Contributor Author

@zhoxing-ms zhoxing-ms Mar 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the name generated by using Python's uuid.uuid4() is 36 characters, which exceeds the limit of 24 characters required by server. So I used Base64 to compress the UUID to generate a unique random name with a length of 22. This solution can ensure the uniqueness of random names without increasing the repetition probability of the original UUID as an automatic name.

Copy link
Collaborator

@yonzhan yonzhan Mar 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got.


createdAssignment = policy_client.policy_assignments.create(scope, name, assignment)

# Create the identity's role assignment if requested
if assign_identity is not None and identity_scope:
Expand Down
Loading