1 // Copyright (C) The Azure-Samples Authors. All rights reserved.
3 // SPDX-License-Identifier: MIT
5 // Largely borrowed from
6 // https://github.com/Azure-Samples/azure-sdk-for-go-samples/tree/master/internal/config
14 "github.com/Azure/go-autorest/autorest/azure"
22 cloudName string = "AzurePublicCloud"
24 environment *azure.Environment
27 // ClientID is the OAuth client ID.
28 func ClientID() string {
32 // ClientSecret is the OAuth client secret.
33 func ClientSecret() string {
37 // TenantID is the AAD tenant to which this client belongs.
38 func TenantID() string {
42 // SubscriptionID is a target subscription for Azure resources.
43 func SubscriptionID() string {
47 // UseDeviceFlow specifies if interactive auth should be used. Interactive
48 // auth uses the OAuth Device Flow grant type.
49 func UseDeviceFlow() bool {
53 // Environment returns an `azure.Environment{...}` for the current cloud.
54 func Environment() *azure.Environment {
55 if environment != nil {
58 env, err := azure.EnvironmentFromName(cloudName)
60 // TODO: move to initialization of var
62 "invalid cloud name '%s' specified, cannot continue\n", cloudName))
68 // ParseEnvironment loads the Azure environment variables for authentication
69 func ParseEnvironment() error {
70 // these must be provided by environment
72 clientID = os.Getenv("AZURE_CLIENT_ID")
75 clientSecret = os.Getenv("AZURE_CLIENT_SECRET")
78 tenantID = os.Getenv("AZURE_TENANT_ID")
80 // subscriptionID (ARM)
81 subscriptionID = os.Getenv("AZURE_SUBSCRIPTION_ID")