from azure.identity import DefaultAzureCredential
from azure.mgmt.subscription import SubscriptionClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-subscription
# USAGE
python get_subscription.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = SubscriptionClient(
credential=DefaultAzureCredential(),
)
response = client.subscriptions.get(
subscription_id="83aa47df-e3e9-49ff-877b-94304bf3d3ad",
)
print(response)
# x-ms-original-file: specification/subscription/resource-manager/Microsoft.Subscription/stable/2016-06-01/examples/getSubscription.json
if __name__ == "__main__":
main()
package armsubscription_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/7a2ac91de424f271cf91cc8009f3fe9ee8249086/specification/subscription/resource-manager/Microsoft.Subscription/stable/2016-06-01/examples/getSubscription.json
func ExampleSubscriptionsClient_Get() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armsubscription.NewClientFactory(cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewSubscriptionsClient().Get(ctx, "83aa47df-e3e9-49ff-877b-94304bf3d3ad", nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.Subscription = armsubscription.Subscription{
// AuthorizationSource: to.Ptr("Legacy"),
// DisplayName: to.Ptr("Subscription2"),
// ID: to.Ptr("/subscriptions/83aa47df-e3e9-49ff-877b-94304bf3d3ad"),
// State: to.Ptr(armsubscription.SubscriptionStateEnabled),
// SubscriptionID: to.Ptr("83aa47df-e3e9-49ff-877b-94304bf3d3ad"),
// SubscriptionPolicies: &armsubscription.Policies{
// LocationPlacementID: to.Ptr("Internal_2014-09-01"),
// QuotaID: to.Ptr("Internal_2014-09-01"),
// SpendingLimit: to.Ptr(armsubscription.SpendingLimitOff),
// },
// }
}
The subscription state. Possible values are Enabled, Warned, PastDue, Disabled, and Deleted.
spendingLimit
Enumeration
The subscription spending limit.
Value
Description
CurrentPeriodOff
Off
On
Subscription
Object
Subscription information.
Name
Type
Description
authorizationSource
string
The authorization source of the request. Valid values are one or more combinations of Legacy, RoleBased, Bypassed, Direct and Management. For example, 'Legacy, RoleBased'.
displayName
string
The subscription display name.
id
string
The fully qualified ID for the subscription. For example, /subscriptions/00000000-0000-0000-0000-000000000000.
The tenant ID. For example, 00000000-0000-0000-0000-000000000000.
SubscriptionPolicies
Object
Subscription policies.
Name
Type
Description
locationPlacementId
string
The subscription ___location placement ID. The ID indicates which regions are visible for a subscription. For example, a subscription with a ___location placement Id of Public_2014-09-01 has access to Azure public regions.