Cloud name usage is mixing case sensitive and case insensitive
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
**Related command**
az cloud
**Describe the bug**
In the `C:\Users\\.azure\clouds.config` file, there can be two versions of a cloud name with different casings, e.g., "mycloud" and "MyCloud".
In this code, whenever you set the cloud with "az cloud set", it always sets it to the first cloud that matches it in the for-loop because it sets the cloud name to lower case before doing a comparison:
https://github.com/Azure/azure-cli/blob/953a006139961b6e4882a39c97a4c8bda1891582/src/azure-cli-core/azure/cli/core/cloud.py#L504
But when you register a cloud, you can register a "mycloud", which is different from "mYcLoUd", and different from "MyCloud", and etc.
https://github.com/Azure/azure-cli/blob/3a793a0ae1caa9a361cc626d70a6b3eec359b4d9/src/azure-cli/azure/cli/command_modules/cloud/custom.py#L43
So, when you do "az cloud set", you always set the cloud of whatever cloud name that was retrieved **first** in the for-loop. "az cloud set" seems to assume case doesn't matter, but "az cloud register" assumes case does matter. Other cloud setting/deleting/unregistering code may need to be investigated to see what the code is doing with cloud name casing
**To Reproduce**
This was reproduced using an on-premises environment (Azure Stack Hub).
1. Register an environment using a name like "MyCloud".
2. Register another environment using same name but different cases, e.g. "mycloud".
3. Run "az cloud set -n mycloud" and it will always set the cloud to "MyCloud", and never "mycloud".
4. Check `C:\Users\\.azure\clouds.config` and you will see both "MyCloud" and "mycloud" configurations, each can be different depending on how you set them up.
**Expected behavior**
You should be able to either set a specific cloud using **only case sensitive** cloud name or **only case insensitive** cloud name, but not a mix of both, otherwise it leads to buggy behavior.
**Environment summary**
```
PS C:\Users\Administrator> az --version
azure-cli 2.45.0 *
core 2.45.0 *
telemetry 1.0.8
Extensions:
connectedk8s 1.3.4
Dependencies:
msal 1.20.0
azure-mgmt-resource 21.1.0b1
Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe'
Extensions directory 'C:\Users\Administrator\.azure\cliextensions'
Python (Windows) 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:37:59) [MSC v.1933 32 bit (Intel)]
Legal docs and information: aka.ms/AzureCliLegal
```
Contributor guide
Assessment
This issue has not been assessed yet.