Azure / cli

Automate your GitHub workflows using Azure CLI scripts
MIT License
133 stars 54 forks source link

Set user agent for Azure/CLI action #122

Closed MoChilia closed 1 year ago

MoChilia commented 1 year ago

This pr will configure the user agent for Azure/CLI action, allowing us to label the user agent as GITHUBACTIONS/AzureCLIAction for ARM. This will help us identify the CLI commands being executed within the Azure/CLI action.

jiasli commented 1 year ago

Could you give an example of what the final User-Agent looks like?

MoChilia commented 1 year ago

Could you give an example of what the final User-Agent looks like?

If there is no AZURE_HTTP_USER_AGENT set before in the environment, we will set AZURE_HTTP_USER_AGENT like

GITHUBACTIONS/AzureCLIAction_3065f147ad3329c9480c20a58c1fc01e8a5b354d9233e27605224fb717484b2f

If AZURE_HTTP_USER_AGENT exists, it will look like

{my_azure_http_user_agent}+GITHUBACTIONS/AzureCLIAction_3065f147ad3329c9480c20a58c1fc01e8a5b354d9233e27605224fb717484b2f

And when running azure cli commands, azure cli core appends AZURE_HTTP_USER_AGENT set by azure/cli action to the User-Agent. See https://github.com/Azure/azure-cli/blob/b6ebd6fac6342c1112c2bb03927509d39263cdee/src/azure-cli-core/azure/cli/core/util.py#L898-L900.

Finally, we will see the user agent record in ARM like

AZURECLI/2.53.1 (DOCKER) azsdk-python-azure-mgmt-web/7.0.0 Python/3.10.13 (Linux-6.2.0-1015-azure-x86_64-with) GITHUBACTIONS/AzureCLIAction_3065f147ad3329c9480c20a58c1fc01e8a5b354d9233e27605224fb717484b2f

And if AZURE_HTTP_USER_AGENT has been set before, it will look like

AZURECLI/2.53.1 (DOCKER) azsdk-python-azure-mgmt-web/7.0.0 Python/3.10.13 (Linux-6.2.0-1015-azure-x86_64-with) {my_azure_http_user_agent}+GITHUBACTIONS/AzureCLIAction_3065f147ad3329c9480c20a58c1fc01e8a5b354d9233e27605224fb717484b2f

The plus sign in ${prefix}+ is literal, this pattern follows azure/login action: https://github.com/Azure/login/blob/e3b217c21b731d452b8d09e42a53fbbc6014b83c/src/main.ts#L13 and azure/powershell action: https://github.com/Azure/powershell/blob/cf0065bbca339333985d4281b0f249261221cd34/src/main.ts#L19.