Azure / Azure/azure-sdk-for-python
[Feature] Inject Endpoint URL as an Environment Variable
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 3.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 193
Description
**Is your feature request related to a problem? Please describe.**
When using a custom cloud, we explicitly have to inject the correct endpoint URL into the Management Clients. This leads to a lot of duplication, and also means awkward if/else statements when we do want to switch back to the Azure Public Cloud.
As an example, this is what the SQL client currently looks like:
https://github.com/Azure/azure-sdk-for-python/blob/9405eb109b754c831315bb3a78f1fdedafd41c0c/sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_configuration.py#L48
Which means that an implementation would always have to jump through hoops to configure this:
```
base_url = "customcloud.company.com"
kwargs = use_custom_cloud() ? {"base_url": base_url} : {}
client = SQLClient(**kwargs)
...
```
(Our implementation doesn't actually look like this - this is just simplified to make the point.)
**Describe the solution you'd like**
The ability to set a global environment variable that every client listens to.
```
AZURE_ENDPOINT_URL=http://customcloud.company.com
```
The Python clients we can use this if no explicit `base_url` is configured:
```
class SqlManagementClientConfiguration
def __init__(
...
base_url: Optional[str] = None,
):
self.base_url = base_url or os.environ.get("AZURE_ENDPOINT_URL") or "https://management.azure.com"
```
Contributor guide
Research direction
Start with sdk/sql/azure-mgmt-sql/azure/mgmt/sql/_configuration.py, especially the base_url handling referenced in the issue. Determine how a shared AZURE_ENDPOINT_URL fallback could apply across management clients without overriding an explicit base_url; done means clients use the environment value when no explicit endpoint is configured and otherwise retain current behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100