Azure / azure-cli

Azure Command-Line Interface
MIT License
4.03k stars 3.01k forks source link

Helper command `az util create-guid` #25359

Open jiasli opened 1 year ago

jiasli commented 1 year ago

Is your feature request related to a problem? Please describe.

az role assignment create now supports bring-your-own role assignment name with the newly introduced --name argument (https://github.com/Azure/azure-cli/pull/24324). APIs such as Role Assignments - Create requires a GUID as the resource name, but there is no cross-platform way to generate a GUID.

PowerShell: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/new-guid?view=powershell-7.3

> (New-Guid).Guid
ac5259e1-38ae-4e06-8cfc-6e8c186e583c

Bash: https://manpages.ubuntu.com/manpages/jammy/man1/uuidgen.1.html

$ uuidgen
582efc62-c990-4f02-a273-52e9d535721b

Other commands also create or use GUIDs:

Describe the solution you'd like

Helper command az util create-guid to create a GUID that can be consumed by other commands.

yonzhan commented 1 year ago

Helper command implementation

jiasli commented 1 year ago

As discussed, it is user's responsibility to know how to generate GUID in different platforms. It shouldn't be part of Azure CLI's functionality.

Another cross-platform solution is to utilize python to generate a GUID:

python -c "import uuid; print(uuid.uuid4())"