// NewServicePrincipalTokenFromCredentials creates a new ServicePrincipalToken using values of the // passed credentials map. func NewServicePrincipalTokenFromCredentials(c map[string]string, scope string) (*azure.ServicePrincipalToken, error) { oauthConfig, err := azure.PublicCloud.OAuthConfigForTenant(c["tenantID"]) if err != nil { panic(err) } return azure.NewServicePrincipalToken(*oauthConfig, c["clientID"], c["clientSecret"], scope) }
// NewServicePrincipalTokenFromCredentials creates a new ServicePrincipalToken using values of the // passed credentials map. func (c *DNSProvider) newServicePrincipalTokenFromCredentials(scope string) (*azure.ServicePrincipalToken, error) { oauthConfig, err := azure.PublicCloud.OAuthConfigForTenant(c.tenantId) if err != nil { panic(err) } return azure.NewServicePrincipalToken(*oauthConfig, c.clientId, c.clientSecret, scope) }
// NewServicePrincipalTokenFromCredentials creates a new ServicePrincipalToken using values of the // passed credentials map. func NewServicePrincipalTokenFromCredentials(c map[string]string, scope string) (*azure.ServicePrincipalToken, error) { oauthConfig, err := azure.PublicCloud.OAuthConfigForTenant(c["AZURE_TENANT_ID"]) if err != nil { panic(err) } return azure.NewServicePrincipalToken(*oauthConfig, c["AZURE_CLIENT_ID"], c["AZURE_CLIENT_SECRET"], scope) }
func getStorageAccountAccessKey(conf map[string]string, resourceGroupName, storageAccountName string) (string, error) { creds, err := getCredentialsFromConf(conf) if err != nil { return "", err } oauthConfig, err := azure.PublicCloud.OAuthConfigForTenant(creds.TenantID) if err != nil { return "", err } if oauthConfig == nil { return "", fmt.Errorf("Unable to configure OAuthConfig for tenant %s", creds.TenantID) } spt, err := azure.NewServicePrincipalToken(*oauthConfig, creds.ClientID, creds.ClientSecret, azure.PublicCloud.ResourceManagerEndpoint) if err != nil { return "", err } accountsClient := storage.NewAccountsClient(creds.SubscriptionID) accountsClient.Authorizer = spt keys, err := accountsClient.ListKeys(resourceGroupName, storageAccountName) if err != nil { return "", fmt.Errorf("Error retrieving keys for storage account %q: %s", storageAccountName, err) } if keys.Key1 == nil { return "", fmt.Errorf("Nil key returned for storage account %q", storageAccountName) } return *keys.Key1, nil }
// AuthToken returns a service principal token, suitable for authorizing // Resource Manager API requests, based on the supplied CloudSpec. func AuthToken(cloud environs.CloudSpec, sender autorest.Sender) (*azure.ServicePrincipalToken, error) { if authType := cloud.Credential.AuthType(); authType != clientCredentialsAuthType { // We currently only support a single auth-type for // non-interactive authentication. Interactive auth // is used only to generate a service-principal. return nil, errors.NotSupportedf("auth-type %q", authType) } credAttrs := cloud.Credential.Attributes() subscriptionId := credAttrs[credAttrSubscriptionId] appId := credAttrs[credAttrAppId] appPassword := credAttrs[credAttrAppPassword] client := subscriptions.Client{subscriptions.NewWithBaseURI(cloud.Endpoint)} client.Sender = sender oauthConfig, _, err := azureauth.OAuthConfig(client, cloud.Endpoint, subscriptionId) if err != nil { return nil, errors.Trace(err) } resource := azureauth.TokenResource(cloud.Endpoint) token, err := azure.NewServicePrincipalToken( *oauthConfig, appId, appPassword, resource, ) if err != nil { return nil, errors.Annotate(err, "constructing service principal token") } if sender != nil { token.SetSender(sender) } return token, nil }
func (b *Builder) createServicePrincipalToken() (*azure.ServicePrincipalToken, error) { spt, err := azure.NewServicePrincipalToken( b.config.ClientID, b.config.ClientSecret, b.config.TenantID, azure.AzureResourceManagerScope) return spt, err }
func (c *Config) NewClient() (*Client, error) { token, err := azure.NewServicePrincipalToken(c.ClientSecret, c.ClientSecret, c.TenantID, azure.AzureResourceManagerScope) if err != nil { return &Client{ servicePrincipalToken: token, resourceGroupsClient: resources.NewResourceGroupsClient(c.SubscriptionID), mutex: &sync.Mutex{}, }, nil } else { return nil, err } }
// ServicePrincipalAuth creates a new AuthFunc that authenticates to Azure // using the provided Service Principal Account credentials (client_id and // client_secret). func ServicePrincipalAuth(spID, spPassword string) AuthFunc { return func(oauthCfg azure.OAuthConfig, _, resource string) (*azure.ServicePrincipalToken, error) { spt, err := azure.NewServicePrincipalToken(oauthCfg, spID, spPassword, resource) if err != nil { return nil, err } // force Refresh() to get a token to be stored. if err := spt.Refresh(); err != nil { return nil, fmt.Errorf("Failed to get a token with service principal: %v", err) } return spt, nil } }
// Create an Azure cluster. func (clst *azureCluster) Connect(namespace string) error { if namespace == "" { return errors.New("namespace cannot be empty") } clst.namespace = namespace if err := clst.loadCredentials(); err != nil { return errors.New("failed to load Azure credentials") } oauthConfig, err := azure.PublicCloud.OAuthConfigForTenant(clst.tenantID) if err != nil { return errors.New("failed to configure OAuthConfig for tenant") } spt, err := azure.NewServicePrincipalToken(*oauthConfig, clst.clientID, clst.clientSecret, azure.PublicCloud.ResourceManagerEndpoint) if err != nil { return err } client := azureClient{} client.ifaceClient = network.NewInterfacesClient(clst.subscriptionID) client.ifaceClient.Authorizer = spt client.publicIPClient = network.NewPublicIPAddressesClient(clst.subscriptionID) client.publicIPClient.Authorizer = spt client.secGroupClient = network.NewSecurityGroupsClient(clst.subscriptionID) client.secGroupClient.Authorizer = spt client.secRulesClient = network.NewSecurityRulesClient(clst.subscriptionID) client.secRulesClient.Authorizer = spt client.vnetClient = network.NewVirtualNetworksClient(clst.subscriptionID) client.vnetClient.Authorizer = spt client.rgClient = resources.NewGroupsClient(clst.subscriptionID) client.rgClient.Authorizer = spt client.storageClient = storage.NewAccountsClient(clst.subscriptionID) client.storageClient.Authorizer = spt client.vmClient = compute.NewVirtualMachinesClient(clst.subscriptionID) client.vmClient.Authorizer = spt clst.azureClient = client return clst.configureResourceGroup() }
func (a *Authenticate) getServicePrincipalTokenWithResource(resource string) (*azure.ServicePrincipalToken, error) { oauthConfig, err := newOAuthConfigWithTenant(a.tenantID) if err != nil { return nil, err } spt, err := azure.NewServicePrincipalToken( *oauthConfig, a.clientID, a.clientSecret, resource) return spt, err }
func (b *Builder) createServicePrincipalToken() (*azure.ServicePrincipalToken, error) { oauthConfig, err := azure.PublicCloud.OAuthConfigForTenant(b.config.TenantID) if err != nil { return nil, err } spt, err := azure.NewServicePrincipalToken( *oauthConfig, b.config.ClientID, b.config.ClientSecret, azure.PublicCloud.ResourceManagerEndpoint) return spt, err }
// AuthenticateServicePrincipal uses given service principal credentials to return a // service principal token. Generated token is not stored in a cache file or refreshed. func AuthenticateServicePrincipal(env azure.Environment, subscriptionID, spID, spPassword string) (*azure.ServicePrincipalToken, error) { tenantID, err := loadOrFindTenantID(env, subscriptionID) if err != nil { return nil, err } oauthCfg, err := env.OAuthConfigForTenant(tenantID) if err != nil { return nil, fmt.Errorf("Failed to obtain oauth config for azure environment: %v", err) } spt, err := azure.NewServicePrincipalToken(*oauthCfg, spID, spPassword, getScope(env)) if err != nil { return nil, fmt.Errorf("Failed to create service principal token: %+v", err) } return spt, nil }
// createAzureClient is a helper function for creating an Azure compute client to ARM. func createAzureClient(cfg config.AzureSDConfig) (azureClient, error) { var c azureClient oauthConfig, err := azure.PublicCloud.OAuthConfigForTenant(cfg.TenantID) if err != nil { return azureClient{}, err } spt, err := azure.NewServicePrincipalToken(*oauthConfig, cfg.ClientID, cfg.ClientSecret, azure.PublicCloud.ResourceManagerEndpoint) if err != nil { return azureClient{}, err } c.vm = compute.NewVirtualMachinesClient(cfg.SubscriptionID) c.vm.Authorizer = spt c.nic = network.NewInterfacesClient(cfg.SubscriptionID) c.nic.Authorizer = spt return c, nil }
func (a *acrProvider) Enabled() bool { if a.file == nil || len(*a.file) == 0 { glog.V(5).Infof("Azure config unspecified, disabling") return false } contents, err := ioutil.ReadFile(*a.file) if err != nil { glog.Errorf("Failed to load azure credential file: %v", err) return false } if err := a.loadConfig(contents); err != nil { glog.Errorf("Failed to parse azure credential file: %v", err) return false } oauthConfig, err := a.environment.OAuthConfigForTenant(a.config.TenantID) if err != nil { glog.Errorf("Failed to get oauth config: %v", err) return false } servicePrincipalToken, err := azureapi.NewServicePrincipalToken( *oauthConfig, a.config.AADClientID, a.config.AADClientSecret, a.environment.ServiceManagementEndpoint) if err != nil { glog.Errorf("Failed to create service principal token: %v", err) return false } registryClient := containerregistry.NewRegistriesClient(a.config.SubscriptionID) registryClient.BaseURI = a.environment.ResourceManagerEndpoint registryClient.Authorizer = servicePrincipalToken a.registryClient = registryClient return true }
// NewServicePrincipalTokenFromCredentials creates a new ServicePrincipalToken using values of the // passed credentials map. func NewServicePrincipalTokenFromCredentials(c map[string]string, scope string) (*azure.ServicePrincipalToken, error) { return azure.NewServicePrincipalToken(c["clientID"], c["clientSecret"], c["tenantID"], scope) }
// NewCloud returns a Cloud with initialized clients func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) { var az Cloud configContents, err := ioutil.ReadAll(configReader) if err != nil { return nil, err } err = yaml.Unmarshal(configContents, &az) if err != nil { return nil, err } if az.Cloud == "" { az.Environment = azure.PublicCloud } else { az.Environment, err = azure.EnvironmentFromName(az.Cloud) if err != nil { return nil, err } } oauthConfig, err := az.Environment.OAuthConfigForTenant(az.TenantID) if err != nil { return nil, err } servicePrincipalToken, err := azure.NewServicePrincipalToken( *oauthConfig, az.AADClientID, az.AADClientSecret, az.Environment.ServiceManagementEndpoint) if err != nil { return nil, err } az.SubnetsClient = network.NewSubnetsClient(az.SubscriptionID) az.SubnetsClient.BaseURI = az.Environment.ResourceManagerEndpoint az.SubnetsClient.Authorizer = servicePrincipalToken az.RouteTablesClient = network.NewRouteTablesClient(az.SubscriptionID) az.RouteTablesClient.BaseURI = az.Environment.ResourceManagerEndpoint az.RouteTablesClient.Authorizer = servicePrincipalToken az.RoutesClient = network.NewRoutesClient(az.SubscriptionID) az.RoutesClient.BaseURI = az.Environment.ResourceManagerEndpoint az.RoutesClient.Authorizer = servicePrincipalToken az.InterfacesClient = network.NewInterfacesClient(az.SubscriptionID) az.InterfacesClient.BaseURI = az.Environment.ResourceManagerEndpoint az.InterfacesClient.Authorizer = servicePrincipalToken az.LoadBalancerClient = network.NewLoadBalancersClient(az.SubscriptionID) az.LoadBalancerClient.BaseURI = az.Environment.ResourceManagerEndpoint az.LoadBalancerClient.Authorizer = servicePrincipalToken az.VirtualMachinesClient = compute.NewVirtualMachinesClient(az.SubscriptionID) az.VirtualMachinesClient.BaseURI = az.Environment.ResourceManagerEndpoint az.VirtualMachinesClient.Authorizer = servicePrincipalToken az.PublicIPAddressesClient = network.NewPublicIPAddressesClient(az.SubscriptionID) az.PublicIPAddressesClient.BaseURI = az.Environment.ResourceManagerEndpoint az.PublicIPAddressesClient.Authorizer = servicePrincipalToken az.SecurityGroupsClient = network.NewSecurityGroupsClient(az.SubscriptionID) az.SecurityGroupsClient.BaseURI = az.Environment.ResourceManagerEndpoint az.SecurityGroupsClient.Authorizer = servicePrincipalToken az.StorageAccountClient = storage.NewAccountsClientWithBaseURI(az.Environment.ResourceManagerEndpoint, az.SubscriptionID) az.StorageAccountClient.Authorizer = servicePrincipalToken return &az, nil }
// getArmClient is a helper method which returns a fully instantiated // *ArmClient based on the Config's current settings. func (c *Config) getArmClient() (*ArmClient, error) { // client declarations: client := ArmClient{} rivieraClient, err := riviera.NewClient(&riviera.AzureResourceManagerCredentials{ ClientID: c.ClientID, ClientSecret: c.ClientSecret, TenantID: c.TenantID, SubscriptionID: c.SubscriptionID, }) if err != nil { return nil, fmt.Errorf("Error creating Riviera client: %s", err) } // validate that the credentials are correct using Riviera. Note that this must be // done _before_ using the Microsoft SDK, because Riviera handles errors. Using a // namespace registration instead of a simple OAuth token refresh guarantees that // service delegation is correct. This has the effect of registering Microsoft.Compute // which is neccessary anyway. if err := registerProviderWithSubscription("Microsoft.Compute", rivieraClient); err != nil { return nil, err } client.rivieraClient = rivieraClient oauthConfig, err := azure.PublicCloud.OAuthConfigForTenant(c.TenantID) if err != nil { return nil, err } // This is necessary because no-one thought about API usability. OAuthConfigForTenant // returns a pointer, which can be nil. NewServicePrincipalToken does not take a pointer. // Consequently we have to nil check this and do _something_ if it is nil, which should // be either an invariant of OAuthConfigForTenant (guarantee the token is not nil if // there is no error), or NewServicePrincipalToken should error out if the configuration // is required and is nil. This is the worst of all worlds, however. if oauthConfig == nil { return nil, fmt.Errorf("Unable to configure OAuthConfig for tenant %s", c.TenantID) } spt, err := azure.NewServicePrincipalToken(*oauthConfig, c.ClientID, c.ClientSecret, azure.PublicCloud.ResourceManagerEndpoint) if err != nil { return nil, err } // NOTE: these declarations should be left separate for clarity should the // clients be wished to be configured with custom Responders/PollingModess etc... asc := compute.NewAvailabilitySetsClient(c.SubscriptionID) setUserAgent(&asc.Client) asc.Authorizer = spt asc.Sender = autorest.CreateSender(withRequestLogging()) client.availSetClient = asc uoc := compute.NewUsageOperationsClient(c.SubscriptionID) setUserAgent(&uoc.Client) uoc.Authorizer = spt uoc.Sender = autorest.CreateSender(withRequestLogging()) client.usageOpsClient = uoc vmeic := compute.NewVirtualMachineExtensionImagesClient(c.SubscriptionID) setUserAgent(&vmeic.Client) vmeic.Authorizer = spt vmeic.Sender = autorest.CreateSender(withRequestLogging()) client.vmExtensionImageClient = vmeic vmec := compute.NewVirtualMachineExtensionsClient(c.SubscriptionID) setUserAgent(&vmec.Client) vmec.Authorizer = spt vmec.Sender = autorest.CreateSender(withRequestLogging()) client.vmExtensionClient = vmec vmic := compute.NewVirtualMachineImagesClient(c.SubscriptionID) setUserAgent(&vmic.Client) vmic.Authorizer = spt vmic.Sender = autorest.CreateSender(withRequestLogging()) client.vmImageClient = vmic vmssc := compute.NewVirtualMachineScaleSetsClient(c.SubscriptionID) setUserAgent(&vmssc.Client) vmssc.Authorizer = spt vmssc.Sender = autorest.CreateSender(withRequestLogging()) client.vmScaleSetClient = vmssc vmc := compute.NewVirtualMachinesClient(c.SubscriptionID) setUserAgent(&vmc.Client) vmc.Authorizer = spt vmc.Sender = autorest.CreateSender(withRequestLogging()) client.vmClient = vmc agc := network.NewApplicationGatewaysClient(c.SubscriptionID) setUserAgent(&agc.Client) agc.Authorizer = spt agc.Sender = autorest.CreateSender(withRequestLogging()) client.appGatewayClient = agc ifc := network.NewInterfacesClient(c.SubscriptionID) setUserAgent(&ifc.Client) ifc.Authorizer = spt ifc.Sender = autorest.CreateSender(withRequestLogging()) client.ifaceClient = ifc lbc := network.NewLoadBalancersClient(c.SubscriptionID) setUserAgent(&lbc.Client) lbc.Authorizer = spt lbc.Sender = autorest.CreateSender(withRequestLogging()) client.loadBalancerClient = lbc lgc := network.NewLocalNetworkGatewaysClient(c.SubscriptionID) setUserAgent(&lgc.Client) lgc.Authorizer = spt lgc.Sender = autorest.CreateSender(withRequestLogging()) client.localNetConnClient = lgc pipc := network.NewPublicIPAddressesClient(c.SubscriptionID) setUserAgent(&pipc.Client) pipc.Authorizer = spt pipc.Sender = autorest.CreateSender(withRequestLogging()) client.publicIPClient = pipc sgc := network.NewSecurityGroupsClient(c.SubscriptionID) setUserAgent(&sgc.Client) sgc.Authorizer = spt sgc.Sender = autorest.CreateSender(withRequestLogging()) client.secGroupClient = sgc src := network.NewSecurityRulesClient(c.SubscriptionID) setUserAgent(&src.Client) src.Authorizer = spt src.Sender = autorest.CreateSender(withRequestLogging()) client.secRuleClient = src snc := network.NewSubnetsClient(c.SubscriptionID) setUserAgent(&snc.Client) snc.Authorizer = spt snc.Sender = autorest.CreateSender(withRequestLogging()) client.subnetClient = snc vgcc := network.NewVirtualNetworkGatewayConnectionsClient(c.SubscriptionID) setUserAgent(&vgcc.Client) vgcc.Authorizer = spt vgcc.Sender = autorest.CreateSender(withRequestLogging()) client.vnetGatewayConnectionsClient = vgcc vgc := network.NewVirtualNetworkGatewaysClient(c.SubscriptionID) setUserAgent(&vgc.Client) vgc.Authorizer = spt vgc.Sender = autorest.CreateSender(withRequestLogging()) client.vnetGatewayClient = vgc vnc := network.NewVirtualNetworksClient(c.SubscriptionID) setUserAgent(&vnc.Client) vnc.Authorizer = spt vnc.Sender = autorest.CreateSender(withRequestLogging()) client.vnetClient = vnc rtc := network.NewRouteTablesClient(c.SubscriptionID) setUserAgent(&rtc.Client) rtc.Authorizer = spt rtc.Sender = autorest.CreateSender(withRequestLogging()) client.routeTablesClient = rtc rc := network.NewRoutesClient(c.SubscriptionID) setUserAgent(&rc.Client) rc.Authorizer = spt rc.Sender = autorest.CreateSender(withRequestLogging()) client.routesClient = rc rgc := resources.NewGroupsClient(c.SubscriptionID) setUserAgent(&rgc.Client) rgc.Authorizer = spt rgc.Sender = autorest.CreateSender(withRequestLogging()) client.resourceGroupClient = rgc pc := resources.NewProvidersClient(c.SubscriptionID) setUserAgent(&pc.Client) pc.Authorizer = spt pc.Sender = autorest.CreateSender(withRequestLogging()) client.providers = pc tc := resources.NewTagsClient(c.SubscriptionID) setUserAgent(&tc.Client) tc.Authorizer = spt tc.Sender = autorest.CreateSender(withRequestLogging()) client.tagsClient = tc jc := scheduler.NewJobsClient(c.SubscriptionID) setUserAgent(&jc.Client) jc.Authorizer = spt jc.Sender = autorest.CreateSender(withRequestLogging()) client.jobsClient = jc jcc := scheduler.NewJobCollectionsClient(c.SubscriptionID) setUserAgent(&jcc.Client) jcc.Authorizer = spt jcc.Sender = autorest.CreateSender(withRequestLogging()) client.jobsCollectionsClient = jcc ssc := storage.NewAccountsClient(c.SubscriptionID) setUserAgent(&ssc.Client) ssc.Authorizer = spt ssc.Sender = autorest.CreateSender(withRequestLogging()) client.storageServiceClient = ssc suc := storage.NewUsageOperationsClient(c.SubscriptionID) setUserAgent(&suc.Client) suc.Authorizer = spt suc.Sender = autorest.CreateSender(withRequestLogging()) client.storageUsageClient = suc cpc := cdn.NewProfilesClient(c.SubscriptionID) setUserAgent(&cpc.Client) cpc.Authorizer = spt cpc.Sender = autorest.CreateSender(withRequestLogging()) client.cdnProfilesClient = cpc cec := cdn.NewEndpointsClient(c.SubscriptionID) setUserAgent(&cec.Client) cec.Authorizer = spt cec.Sender = autorest.CreateSender(withRequestLogging()) client.cdnEndpointsClient = cec dc := resources.NewDeploymentsClient(c.SubscriptionID) setUserAgent(&dc.Client) dc.Authorizer = spt dc.Sender = autorest.CreateSender(withRequestLogging()) client.deploymentsClient = dc return &client, nil }
// getArmClient is a helper method which returns a fully instantiated // *ArmClient based on the Config's current settings. func (c *Config) getArmClient() (*ArmClient, error) { // client declarations: client := ArmClient{ clientId: c.ClientID, tenantId: c.TenantID, subscriptionId: c.SubscriptionID, } rivieraClient, err := riviera.NewClient(&riviera.AzureResourceManagerCredentials{ ClientID: c.ClientID, ClientSecret: c.ClientSecret, TenantID: c.TenantID, SubscriptionID: c.SubscriptionID, }) if err != nil { return nil, fmt.Errorf("Error creating Riviera client: %s", err) } // validate that the credentials are correct using Riviera. Note that this must be // done _before_ using the Microsoft SDK, because Riviera handles errors. Using a // namespace registration instead of a simple OAuth token refresh guarantees that // service delegation is correct. This has the effect of registering Microsoft.Compute // which is neccessary anyway. if err := registerProviderWithSubscription("Microsoft.Compute", rivieraClient); err != nil { return nil, err } client.rivieraClient = rivieraClient oauthConfig, err := azure.PublicCloud.OAuthConfigForTenant(c.TenantID) if err != nil { return nil, err } // OAuthConfigForTenant returns a pointer, which can be nil. if oauthConfig == nil { return nil, fmt.Errorf("Unable to configure OAuthConfig for tenant %s", c.TenantID) } spt, err := azure.NewServicePrincipalToken(*oauthConfig, c.ClientID, c.ClientSecret, azure.PublicCloud.ResourceManagerEndpoint) if err != nil { return nil, err } // NOTE: these declarations should be left separate for clarity should the // clients be wished to be configured with custom Responders/PollingModess etc... asc := compute.NewAvailabilitySetsClient(c.SubscriptionID) setUserAgent(&asc.Client) asc.Authorizer = spt asc.Sender = autorest.CreateSender(withRequestLogging()) client.availSetClient = asc uoc := compute.NewUsageOperationsClient(c.SubscriptionID) setUserAgent(&uoc.Client) uoc.Authorizer = spt uoc.Sender = autorest.CreateSender(withRequestLogging()) client.usageOpsClient = uoc vmeic := compute.NewVirtualMachineExtensionImagesClient(c.SubscriptionID) setUserAgent(&vmeic.Client) vmeic.Authorizer = spt vmeic.Sender = autorest.CreateSender(withRequestLogging()) client.vmExtensionImageClient = vmeic vmec := compute.NewVirtualMachineExtensionsClient(c.SubscriptionID) setUserAgent(&vmec.Client) vmec.Authorizer = spt vmec.Sender = autorest.CreateSender(withRequestLogging()) client.vmExtensionClient = vmec vmic := compute.NewVirtualMachineImagesClient(c.SubscriptionID) setUserAgent(&vmic.Client) vmic.Authorizer = spt vmic.Sender = autorest.CreateSender(withRequestLogging()) client.vmImageClient = vmic vmssc := compute.NewVirtualMachineScaleSetsClient(c.SubscriptionID) setUserAgent(&vmssc.Client) vmssc.Authorizer = spt vmssc.Sender = autorest.CreateSender(withRequestLogging()) client.vmScaleSetClient = vmssc vmc := compute.NewVirtualMachinesClient(c.SubscriptionID) setUserAgent(&vmc.Client) vmc.Authorizer = spt vmc.Sender = autorest.CreateSender(withRequestLogging()) client.vmClient = vmc agc := network.NewApplicationGatewaysClient(c.SubscriptionID) setUserAgent(&agc.Client) agc.Authorizer = spt agc.Sender = autorest.CreateSender(withRequestLogging()) client.appGatewayClient = agc ehnc := eventhub.NewNamespacesClient(c.SubscriptionID) setUserAgent(&ehnc.Client) ehnc.Authorizer = spt ehnc.Sender = autorest.CreateSender(withRequestLogging()) client.eventHubNamespacesClient = ehnc ifc := network.NewInterfacesClient(c.SubscriptionID) setUserAgent(&ifc.Client) ifc.Authorizer = spt ifc.Sender = autorest.CreateSender(withRequestLogging()) client.ifaceClient = ifc lbc := network.NewLoadBalancersClient(c.SubscriptionID) setUserAgent(&lbc.Client) lbc.Authorizer = spt lbc.Sender = autorest.CreateSender(withRequestLogging()) client.loadBalancerClient = lbc lgc := network.NewLocalNetworkGatewaysClient(c.SubscriptionID) setUserAgent(&lgc.Client) lgc.Authorizer = spt lgc.Sender = autorest.CreateSender(withRequestLogging()) client.localNetConnClient = lgc pipc := network.NewPublicIPAddressesClient(c.SubscriptionID) setUserAgent(&pipc.Client) pipc.Authorizer = spt pipc.Sender = autorest.CreateSender(withRequestLogging()) client.publicIPClient = pipc sgc := network.NewSecurityGroupsClient(c.SubscriptionID) setUserAgent(&sgc.Client) sgc.Authorizer = spt sgc.Sender = autorest.CreateSender(withRequestLogging()) client.secGroupClient = sgc src := network.NewSecurityRulesClient(c.SubscriptionID) setUserAgent(&src.Client) src.Authorizer = spt src.Sender = autorest.CreateSender(withRequestLogging()) client.secRuleClient = src snc := network.NewSubnetsClient(c.SubscriptionID) setUserAgent(&snc.Client) snc.Authorizer = spt snc.Sender = autorest.CreateSender(withRequestLogging()) client.subnetClient = snc vgcc := network.NewVirtualNetworkGatewayConnectionsClient(c.SubscriptionID) setUserAgent(&vgcc.Client) vgcc.Authorizer = spt vgcc.Sender = autorest.CreateSender(withRequestLogging()) client.vnetGatewayConnectionsClient = vgcc vgc := network.NewVirtualNetworkGatewaysClient(c.SubscriptionID) setUserAgent(&vgc.Client) vgc.Authorizer = spt vgc.Sender = autorest.CreateSender(withRequestLogging()) client.vnetGatewayClient = vgc vnc := network.NewVirtualNetworksClient(c.SubscriptionID) setUserAgent(&vnc.Client) vnc.Authorizer = spt vnc.Sender = autorest.CreateSender(withRequestLogging()) client.vnetClient = vnc vnpc := network.NewVirtualNetworkPeeringsClient(c.SubscriptionID) setUserAgent(&vnpc.Client) vnpc.Authorizer = spt vnpc.Sender = autorest.CreateSender(withRequestLogging()) client.vnetPeeringsClient = vnpc rtc := network.NewRouteTablesClient(c.SubscriptionID) setUserAgent(&rtc.Client) rtc.Authorizer = spt rtc.Sender = autorest.CreateSender(withRequestLogging()) client.routeTablesClient = rtc rc := network.NewRoutesClient(c.SubscriptionID) setUserAgent(&rc.Client) rc.Authorizer = spt rc.Sender = autorest.CreateSender(withRequestLogging()) client.routesClient = rc rgc := resources.NewGroupsClient(c.SubscriptionID) setUserAgent(&rgc.Client) rgc.Authorizer = spt rgc.Sender = autorest.CreateSender(withRequestLogging()) client.resourceGroupClient = rgc pc := resources.NewProvidersClient(c.SubscriptionID) setUserAgent(&pc.Client) pc.Authorizer = spt pc.Sender = autorest.CreateSender(withRequestLogging()) client.providers = pc tc := resources.NewTagsClient(c.SubscriptionID) setUserAgent(&tc.Client) tc.Authorizer = spt tc.Sender = autorest.CreateSender(withRequestLogging()) client.tagsClient = tc rf := resources.NewClient(c.SubscriptionID) setUserAgent(&rf.Client) rf.Authorizer = spt rf.Sender = autorest.CreateSender(withRequestLogging()) client.resourceFindClient = rf jc := scheduler.NewJobsClient(c.SubscriptionID) setUserAgent(&jc.Client) jc.Authorizer = spt jc.Sender = autorest.CreateSender(withRequestLogging()) client.jobsClient = jc jcc := scheduler.NewJobCollectionsClient(c.SubscriptionID) setUserAgent(&jcc.Client) jcc.Authorizer = spt jcc.Sender = autorest.CreateSender(withRequestLogging()) client.jobsCollectionsClient = jcc ssc := storage.NewAccountsClient(c.SubscriptionID) setUserAgent(&ssc.Client) ssc.Authorizer = spt ssc.Sender = autorest.CreateSender(withRequestLogging()) client.storageServiceClient = ssc suc := storage.NewUsageOperationsClient(c.SubscriptionID) setUserAgent(&suc.Client) suc.Authorizer = spt suc.Sender = autorest.CreateSender(withRequestLogging()) client.storageUsageClient = suc cpc := cdn.NewProfilesClient(c.SubscriptionID) setUserAgent(&cpc.Client) cpc.Authorizer = spt cpc.Sender = autorest.CreateSender(withRequestLogging()) client.cdnProfilesClient = cpc cec := cdn.NewEndpointsClient(c.SubscriptionID) setUserAgent(&cec.Client) cec.Authorizer = spt cec.Sender = autorest.CreateSender(withRequestLogging()) client.cdnEndpointsClient = cec dc := resources.NewDeploymentsClient(c.SubscriptionID) setUserAgent(&dc.Client) dc.Authorizer = spt dc.Sender = autorest.CreateSender(withRequestLogging()) client.deploymentsClient = dc tmpc := trafficmanager.NewProfilesClient(c.SubscriptionID) setUserAgent(&tmpc.Client) tmpc.Authorizer = spt tmpc.Sender = autorest.CreateSender(withRequestLogging()) client.trafficManagerProfilesClient = tmpc tmec := trafficmanager.NewEndpointsClient(c.SubscriptionID) setUserAgent(&tmec.Client) tmec.Authorizer = spt tmec.Sender = autorest.CreateSender(withRequestLogging()) client.trafficManagerEndpointsClient = tmec sbnc := servicebus.NewNamespacesClient(c.SubscriptionID) setUserAgent(&sbnc.Client) sbnc.Authorizer = spt sbnc.Sender = autorest.CreateSender(withRequestLogging()) client.serviceBusNamespacesClient = sbnc sbtc := servicebus.NewTopicsClient(c.SubscriptionID) setUserAgent(&sbtc.Client) sbtc.Authorizer = spt sbtc.Sender = autorest.CreateSender(withRequestLogging()) client.serviceBusTopicsClient = sbtc sbsc := servicebus.NewSubscriptionsClient(c.SubscriptionID) setUserAgent(&sbsc.Client) sbsc.Authorizer = spt sbsc.Sender = autorest.CreateSender(withRequestLogging()) client.serviceBusSubscriptionsClient = sbsc kvc := keyvault.NewVaultsClient(c.SubscriptionID) setUserAgent(&kvc.Client) kvc.Authorizer = spt kvc.Sender = autorest.CreateSender(withRequestLogging()) client.keyVaultClient = kvc return &client, nil }
func main() { cred := credentials{} if err := loadCredentials(&cred); err != nil { log.Fatalf("Error: %v", err) } oauthConfig, err := azure.PublicCloud.OAuthConfigForTenant(cred.TenantID) if err != nil { log.Fatalf("Error: %v", err) } spt, err := azure.NewServicePrincipalToken(*oauthConfig, cred.ClientID, cred.ClientSecret, azure.PublicCloud.ResourceManagerEndpoint) if err != nil { log.Fatalf("Error: %v", err) } rateCardClient := ratecard.NewClient(cred.SubscriptionID) rateCardClient.Authorizer = spt vmSizeClient := compute.NewVirtualMachineSizesClient(cred.SubscriptionID) vmSizeClient.Authorizer = spt // Uncomment to inspect http request and responses // rateCardClient.RequestInspector = withInspection() // rateCardClient.ResponseInspector = byInspecting() // vmSizeClient.RequestInspector = withInspection() // vmSizeClient.ResponseInspector = byInspecting() // List all Linux only Pay-as-you-go VM Pricing in USD for all US VMs. // Frontend to backend linux VM sizes mapping. linuxVms := map[string]string{ "BASIC.A0": "Basic_A0", "BASIC.A1": "Basic_A1", "BASIC.A2": "Basic_A2", "BASIC.A3": "Basic_A3", "BASIC.A4": "Basic_A4", "A0": "Standard_A0", "A1": "Standard_A1", "A2": "Standard_A2", "A3": "Standard_A3", "A4": "Standard_A4", "A5": "Standard_A5", "A6": "Standard_A6", "A7": "Standard_A7", "A8": "Standard_A8", "A9": "Standard_A9", "Standard_D1": "Standard_D1", "Standard_D2": "Standard_D2", "Standard_D3": "Standard_D3", "Standard_D4": "Standard_D4", "Standard_D11": "Standard_D11", "Standard_D12": "Standard_D12", "Standard_D13": "Standard_D13", "Standard_D14": "Standard_D14", "Standard_D1_v2": "Standard_D1_v2", "Standard_D2_v2": "Standard_D2_v2", "Standard_D3_v2": "Standard_D3_v2", "Standard_D4_v2": "Standard_D4_v2", "Standard_D5_v2": "Standard_D5_v2", "Standard_D11_v2": "Standard_D11_v2", "Standard_D12_v2": "Standard_D12_v2", "Standard_D13_v2": "Standard_D13_v2", "Standard_D14_v2": "Standard_D14_v2", "Standard_D15_v2": "Standard_D15_v2", "Standard_DS1": "Standard_DS1", "Standard_DS2": "Standard_DS2", "Standard_DS3": "Standard_DS3", "Standard_DS4": "Standard_DS4", "Standard_DS11": "Standard_DS11", "Standard_DS12": "Standard_DS12", "Standard_DS13": "Standard_DS13", "Standard_DS14": "Standard_DS14", "Standard_G1": "Standard_G1", "Standard_G2": "Standard_G2", "Standard_G3": "Standard_G3", "Standard_G4": "Standard_G4", "Standard_G5": "Standard_G5", "Standard_GS1": "Standard_GS1", "Standard_GS2": "Standard_GS2", "Standard_GS3": "Standard_GS3", "Standard_GS4": "Standard_GS4", "Standard_GS5": "Standard_GS5", "Standard_F1": "Standard_F1", "Standard_F2": "Standard_F2", "Standard_F4": "Standard_F4", "Standard_F8": "Standard_F8", "Standard_F16": "Standard_F16", } // Frontend to backend US locations mapping. usLocations := map[string]string{ "US East": "eastus", "US East 2": "eastus2", "US West": "westus", "US Central": "centralus", "US North Central": "northcentralus", "US South Central": "southcentralus", "US West 2": "westus2", "US West Central": "westcentralus", } // The current RateCard API returns weird response. To filter out only Linux VMs, We // create a map that maps the API formatted size tyoes to the actual ones. filterSet := make(map[string]string) for frontSize, backSize := range linuxVms { meterSize := fmt.Sprintf("%s VM", frontSize) filterSet[meterSize] = backSize } param := ratecard.RateCardGetParameters{ OfferDurableId: stringPtr("MS-AZR-0003p"), Currency: stringPtr("USD"), Locale: stringPtr("en-US"), RegionInfo: stringPtr("US"), } rateCard, err := rateCardClient.Get(param, make(chan struct{})) if err != nil { log.Fatalf("Error: %v", err) } result := make(map[id]rate) for _, meter := range *rateCard.Meters { if *meter.MeterCategory != ratecard.VirtualMachines { continue } meterSize := *meter.MeterSubCategory price := *(*meter.MeterRates)["0"] region := *meter.MeterRegion // Filter out Linux VMs. backSize, ok := filterSet[meterSize] if !ok { continue } // Filter out US regions. backRegion, ok := usLocations[region] if !ok { continue } result[id{region: backRegion, size: backSize}] = rate{ size: backSize, price: price, region: backRegion, } } for _, backRegion := range usLocations { vmSizes, err := vmSizeClient.List(backRegion) if err != nil { log.Fatalf("Error: %v", err) } for _, vmSize := range *vmSizes.Value { backSize := *vmSize.Name key := id{region: backRegion, size: backSize} rate, ok := result[key] if !ok { // log.Printf("%s:%s Found in vm info but not in ratecard", backRegion, backSize) continue } rate.cpu = *vmSize.NumberOfCores rate.disk = *vmSize.ResourceDiskSizeInMB / 1024 rate.ram = (float32)(*vmSize.MemoryInMB) / 1024 result[key] = rate } } for _, rate := range result { log.Printf("%v.\n", rate) } }
// getArmClient is a helper method which returns a fully instantiated // *ArmClient based on the Config's current settings. func (c *Config) getArmClient() (*ArmClient, error) { // detect cloud from environment env, envErr := azure.EnvironmentFromName(c.Environment) if envErr != nil { // try again with wrapped value to support readable values like german instead of AZUREGERMANCLOUD wrapped := fmt.Sprintf("AZURE%sCLOUD", c.Environment) var innerErr error if env, innerErr = azure.EnvironmentFromName(wrapped); innerErr != nil { return nil, envErr } } // client declarations: client := ArmClient{ clientId: c.ClientID, tenantId: c.TenantID, subscriptionId: c.SubscriptionID, environment: env, } rivieraClient, err := riviera.NewClient(&riviera.AzureResourceManagerCredentials{ ClientID: c.ClientID, ClientSecret: c.ClientSecret, TenantID: c.TenantID, SubscriptionID: c.SubscriptionID, ResourceManagerEndpoint: env.ResourceManagerEndpoint, ActiveDirectoryEndpoint: env.ActiveDirectoryEndpoint, }) if err != nil { return nil, fmt.Errorf("Error creating Riviera client: %s", err) } client.rivieraClient = rivieraClient oauthConfig, err := env.OAuthConfigForTenant(c.TenantID) if err != nil { return nil, err } // OAuthConfigForTenant returns a pointer, which can be nil. if oauthConfig == nil { return nil, fmt.Errorf("Unable to configure OAuthConfig for tenant %s", c.TenantID) } spt, err := azure.NewServicePrincipalToken(*oauthConfig, c.ClientID, c.ClientSecret, env.ResourceManagerEndpoint) if err != nil { return nil, err } endpoint := env.ResourceManagerEndpoint // NOTE: these declarations should be left separate for clarity should the // clients be wished to be configured with custom Responders/PollingModess etc... asc := compute.NewAvailabilitySetsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&asc.Client) asc.Authorizer = spt asc.Sender = autorest.CreateSender(withRequestLogging()) client.availSetClient = asc uoc := compute.NewUsageOperationsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&uoc.Client) uoc.Authorizer = spt uoc.Sender = autorest.CreateSender(withRequestLogging()) client.usageOpsClient = uoc vmeic := compute.NewVirtualMachineExtensionImagesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&vmeic.Client) vmeic.Authorizer = spt vmeic.Sender = autorest.CreateSender(withRequestLogging()) client.vmExtensionImageClient = vmeic vmec := compute.NewVirtualMachineExtensionsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&vmec.Client) vmec.Authorizer = spt vmec.Sender = autorest.CreateSender(withRequestLogging()) client.vmExtensionClient = vmec vmic := compute.NewVirtualMachineImagesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&vmic.Client) vmic.Authorizer = spt vmic.Sender = autorest.CreateSender(withRequestLogging()) client.vmImageClient = vmic vmssc := compute.NewVirtualMachineScaleSetsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&vmssc.Client) vmssc.Authorizer = spt vmssc.Sender = autorest.CreateSender(withRequestLogging()) client.vmScaleSetClient = vmssc vmc := compute.NewVirtualMachinesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&vmc.Client) vmc.Authorizer = spt vmc.Sender = autorest.CreateSender(withRequestLogging()) client.vmClient = vmc agc := network.NewApplicationGatewaysClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&agc.Client) agc.Authorizer = spt agc.Sender = autorest.CreateSender(withRequestLogging()) client.appGatewayClient = agc crc := containerregistry.NewRegistriesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&crc.Client) crc.Authorizer = spt crc.Sender = autorest.CreateSender(withRequestLogging()) client.containerRegistryClient = crc ehc := eventhub.NewEventHubsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&ehc.Client) ehc.Authorizer = spt ehc.Sender = autorest.CreateSender(withRequestLogging()) client.eventHubClient = ehc chcgc := eventhub.NewConsumerGroupsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&chcgc.Client) chcgc.Authorizer = spt chcgc.Sender = autorest.CreateSender(withRequestLogging()) client.eventHubConsumerGroupClient = chcgc ehnc := eventhub.NewNamespacesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&ehnc.Client) ehnc.Authorizer = spt ehnc.Sender = autorest.CreateSender(withRequestLogging()) client.eventHubNamespacesClient = ehnc ifc := network.NewInterfacesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&ifc.Client) ifc.Authorizer = spt ifc.Sender = autorest.CreateSender(withRequestLogging()) client.ifaceClient = ifc lbc := network.NewLoadBalancersClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&lbc.Client) lbc.Authorizer = spt lbc.Sender = autorest.CreateSender(withRequestLogging()) client.loadBalancerClient = lbc lgc := network.NewLocalNetworkGatewaysClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&lgc.Client) lgc.Authorizer = spt lgc.Sender = autorest.CreateSender(withRequestLogging()) client.localNetConnClient = lgc pipc := network.NewPublicIPAddressesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&pipc.Client) pipc.Authorizer = spt pipc.Sender = autorest.CreateSender(withRequestLogging()) client.publicIPClient = pipc sgc := network.NewSecurityGroupsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&sgc.Client) sgc.Authorizer = spt sgc.Sender = autorest.CreateSender(withRequestLogging()) client.secGroupClient = sgc src := network.NewSecurityRulesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&src.Client) src.Authorizer = spt src.Sender = autorest.CreateSender(withRequestLogging()) client.secRuleClient = src snc := network.NewSubnetsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&snc.Client) snc.Authorizer = spt snc.Sender = autorest.CreateSender(withRequestLogging()) client.subnetClient = snc vgcc := network.NewVirtualNetworkGatewayConnectionsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&vgcc.Client) vgcc.Authorizer = spt vgcc.Sender = autorest.CreateSender(withRequestLogging()) client.vnetGatewayConnectionsClient = vgcc vgc := network.NewVirtualNetworkGatewaysClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&vgc.Client) vgc.Authorizer = spt vgc.Sender = autorest.CreateSender(withRequestLogging()) client.vnetGatewayClient = vgc vnc := network.NewVirtualNetworksClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&vnc.Client) vnc.Authorizer = spt vnc.Sender = autorest.CreateSender(withRequestLogging()) client.vnetClient = vnc vnpc := network.NewVirtualNetworkPeeringsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&vnpc.Client) vnpc.Authorizer = spt vnpc.Sender = autorest.CreateSender(withRequestLogging()) client.vnetPeeringsClient = vnpc rtc := network.NewRouteTablesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&rtc.Client) rtc.Authorizer = spt rtc.Sender = autorest.CreateSender(withRequestLogging()) client.routeTablesClient = rtc rc := network.NewRoutesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&rc.Client) rc.Authorizer = spt rc.Sender = autorest.CreateSender(withRequestLogging()) client.routesClient = rc rgc := resources.NewGroupsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&rgc.Client) rgc.Authorizer = spt rgc.Sender = autorest.CreateSender(withRequestLogging()) client.resourceGroupClient = rgc pc := resources.NewProvidersClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&pc.Client) pc.Authorizer = spt pc.Sender = autorest.CreateSender(withRequestLogging()) client.providers = pc tc := resources.NewTagsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&tc.Client) tc.Authorizer = spt tc.Sender = autorest.CreateSender(withRequestLogging()) client.tagsClient = tc rf := resources.NewClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&rf.Client) rf.Authorizer = spt rf.Sender = autorest.CreateSender(withRequestLogging()) client.resourceFindClient = rf jc := scheduler.NewJobsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&jc.Client) jc.Authorizer = spt jc.Sender = autorest.CreateSender(withRequestLogging()) client.jobsClient = jc jcc := scheduler.NewJobCollectionsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&jcc.Client) jcc.Authorizer = spt jcc.Sender = autorest.CreateSender(withRequestLogging()) client.jobsCollectionsClient = jcc ssc := storage.NewAccountsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&ssc.Client) ssc.Authorizer = spt ssc.Sender = autorest.CreateSender(withRequestLogging()) client.storageServiceClient = ssc suc := storage.NewUsageOperationsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&suc.Client) suc.Authorizer = spt suc.Sender = autorest.CreateSender(withRequestLogging()) client.storageUsageClient = suc cpc := cdn.NewProfilesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&cpc.Client) cpc.Authorizer = spt cpc.Sender = autorest.CreateSender(withRequestLogging()) client.cdnProfilesClient = cpc cec := cdn.NewEndpointsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&cec.Client) cec.Authorizer = spt cec.Sender = autorest.CreateSender(withRequestLogging()) client.cdnEndpointsClient = cec dc := resources.NewDeploymentsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&dc.Client) dc.Authorizer = spt dc.Sender = autorest.CreateSender(withRequestLogging()) client.deploymentsClient = dc tmpc := trafficmanager.NewProfilesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&tmpc.Client) tmpc.Authorizer = spt tmpc.Sender = autorest.CreateSender(withRequestLogging()) client.trafficManagerProfilesClient = tmpc tmec := trafficmanager.NewEndpointsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&tmec.Client) tmec.Authorizer = spt tmec.Sender = autorest.CreateSender(withRequestLogging()) client.trafficManagerEndpointsClient = tmec rdc := redis.NewClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&rdc.Client) rdc.Authorizer = spt rdc.Sender = autorest.CreateSender(withRequestLogging()) client.redisClient = rdc sbnc := servicebus.NewNamespacesClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&sbnc.Client) sbnc.Authorizer = spt sbnc.Sender = autorest.CreateSender(withRequestLogging()) client.serviceBusNamespacesClient = sbnc sbtc := servicebus.NewTopicsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&sbtc.Client) sbtc.Authorizer = spt sbtc.Sender = autorest.CreateSender(withRequestLogging()) client.serviceBusTopicsClient = sbtc sbsc := servicebus.NewSubscriptionsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&sbsc.Client) sbsc.Authorizer = spt sbsc.Sender = autorest.CreateSender(withRequestLogging()) client.serviceBusSubscriptionsClient = sbsc kvc := keyvault.NewVaultsClientWithBaseURI(endpoint, c.SubscriptionID) setUserAgent(&kvc.Client) kvc.Authorizer = spt kvc.Sender = autorest.CreateSender(withRequestLogging()) client.keyVaultClient = kvc return &client, nil }