Azure Service Linker Management Client Library for Python
The `azure-mgmt-servicelinker` library is the Microsoft Azure Service Linker Management Client Library for Python. It provides the tools to manage Azure Service Linkers, which connect Azure compute services to other Azure data services. The current stable version is 1.1.0. Azure SDKs typically follow a frequent release cadence, with minor releases quarterly or less, and patch releases as bug fixes become available.
Warnings
- breaking Version 1.0.0 introduced several breaking changes in model parameters. Specifically, `LinkerPatch` and `LinkerResource` no longer have the `target_id` parameter, `SecretAuthInfo` removed the `secret` parameter (replaced by `secret_info`), and `ValidateResult` saw changes in its `linker_status`, `name`, and `reason` parameters.
- deprecated Support for Python 2.7 in Azure SDK Python packages, including `azure-mgmt-servicelinker`, ended on January 1, 2022. Using Python 2.7 with this library is not supported and may lead to unpatched security vulnerabilities or unexpected behavior.
- gotcha The general `azure-mgmt` package is deprecated since version 5.0.0. Users should install service-specific packages like `azure-mgmt-servicelinker` for individual Azure management services. Installing the older `azure-mgmt` package will not provide the Service Linker client.
- gotcha For `DefaultAzureCredential` to work correctly in many scenarios (especially service principal authentication), critical environment variables like `AZURE_TENANT_ID`, `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, and `AZURE_SUBSCRIPTION_ID` must be configured. Incorrect or missing configuration is a common source of authentication errors.
Install
-
pip install azure-mgmt-servicelinker azure-identity
Imports
- ServiceLinkerManagementClient
from azure.mgmt.servicelinker import ServiceLinkerManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.servicelinker import ServiceLinkerManagementClient
# Set environment variables for authentication (replace with your actual values or use Azure CLI/VS Code login)
# AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID
# For local development, DefaultAzureCredential will try various methods, including environment variables,
# managed identity, Azure CLI, or Visual Studio Code login.
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") # Replace with your subscription ID
resource_uri = "subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Web/sites/test-app" # Example URI, replace as needed
# Authenticate using DefaultAzureCredential
credential = DefaultAzureCredential()
# Create a ServiceLinkerManagementClient
client = ServiceLinkerManagementClient(credential=credential, subscription_id=subscription_id)
# Example: List linkers for a given resource_uri
try:
print(f"Listing linkers for resource: {resource_uri}")
linkers = client.linkers.list(resource_uri=resource_uri)
for linker in linkers:
print(f" - Linker Name: {linker.name}, Target Service: {linker.target_service.id if linker.target_service else 'N/A'}")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure the resource_uri and subscription_id are correct and you have the necessary permissions.")
print("Also, verify your authentication environment variables (AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET) or local Azure login.")