Azure / static-web-apps-cli

Azure Static Web Apps CLI ✨
https://aka.ms/swa/cli-local-development
MIT License
596 stars 117 forks source link

[Bug] CLI assumes the AZURE_LOGIN_CONFIG file has subscriptions in it #890

Open rhuanbarreto opened 2 days ago

rhuanbarreto commented 2 days ago

I'm using the latest version 2.0.1

Describe the bug CLI is failing to deploy when reading the contents of my AZURE_LOGIN_CONFIG file. Logs below:

✖ Cannot read properties of undefined (reading 'find')
✔ Successfully logged into Azure!
Found an existing Azure config file, getting Tenant and Subscription Id from /home/vsts/.azure/azureProfile.json

This is the content of my azureProfile.json:

{"installationId": "redacteduuid"}

I could track down the error to be on this statement:

https://github.com/Azure/static-web-apps-cli/blob/5f440e3068be7d53e052fae17e58dcc5c8b108e5/src/cli/commands/login/login.ts#L165

And the line before coerces the configuration to an interface:

https://github.com/Azure/static-web-apps-cli/blob/5f440e3068be7d53e052fae17e58dcc5c8b108e5/src/cli/commands/login/login.ts#L164

Which resolves to this interface:

https://github.com/Azure/static-web-apps-cli/blob/5f440e3068be7d53e052fae17e58dcc5c8b108e5/src/swa.d.ts#L443-L446

Which is not true. My azureProfile.json doesn't have the subscriptions key. Therefore the failure.

To Reproduce Steps to reproduce the behavior:

  1. Make a pipeline in Azure Dev Ops
  2. Use a service principal logging in with client ID and client secret in an AzureCLI@2 task
  3. Inside of an AzureCLI@2 task, run the SWA CLI commands via an inline script
  4. See error. The command will not fail despite the failure which makes debugging very hard once CI will never fail.

Expected behavior

Expected to have the command working fine.

rhuanbarreto commented 1 day ago

I managed to solve the problem by setting the "Use global Azure CLI configuration" option in the pipeline step. But this still doesn't solve the bug. The CLI must check for the existence of the subscriptions key.