• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang azure.NewServicePrincipalToken函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/Azure/go-autorest/autorest/azure.NewServicePrincipalToken函数的典型用法代码示例。如果您正苦于以下问题:Golang NewServicePrincipalToken函数的具体用法?Golang NewServicePrincipalToken怎么用?Golang NewServicePrincipalToken使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewServicePrincipalToken函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: NewServicePrincipalTokenFromCredentials

// 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)
}
开发者ID:daemonfire300,项目名称:azure-sdk-for-go,代码行数:9,代码来源:helpers.go


示例2: newServicePrincipalTokenFromCredentials

// 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)
}
开发者ID:Rudloff,项目名称:platform,代码行数:9,代码来源:azure.go


示例3: getStorageAccountAccessKey

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
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:33,代码来源:azure.go


示例4: AuthToken

// 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
}
开发者ID:bac,项目名称:juju,代码行数:36,代码来源:auth.go


示例5: createServicePrincipalToken

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
}
开发者ID:Gamesparks-OSS,项目名称:packer-azure,代码行数:9,代码来源:builder.go


示例6: NewClient

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
	}
}
开发者ID:ve-interactive,项目名称:terraform,代码行数:13,代码来源:config.go


示例7: ServicePrincipalAuth

// 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
	}
}
开发者ID:bgokden,项目名称:machine,代码行数:16,代码来源:auth.go


示例8: Connect

// 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()
}
开发者ID:yuenmeiwan,项目名称:quilt,代码行数:52,代码来源:azure.go


示例9: getServicePrincipalTokenWithResource

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
}
开发者ID:boumenot,项目名称:packer,代码行数:14,代码来源:authenticate.go


示例10: createServicePrincipalToken

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
}
开发者ID:rchalumeau,项目名称:packer-azure,代码行数:14,代码来源:builder.go


示例11: AuthenticateServicePrincipal

// 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
}
开发者ID:flavio,项目名称:machine,代码行数:18,代码来源:auth.go


示例12: createAzureClient

// 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
}
开发者ID:prometheus,项目名称:prometheus,代码行数:20,代码来源:azure.go


示例13: Enabled

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
}
开发者ID:kubernetes,项目名称:kubernetes,代码行数:38,代码来源:azure_credentials.go


示例14: NewServicePrincipalTokenFromCredentials

// 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)
}
开发者ID:containerx,项目名称:machine,代码行数:5,代码来源:helpers.go


示例15: NewCloud

// 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
}
开发者ID:eljefedelrodeodeljefe,项目名称:kubernetes,代码行数:72,代码来源:azure.go


示例16: getArmClient

// 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
//.........这里部分代码省略.........
开发者ID:ewdurbin,项目名称:terraform,代码行数:101,代码来源:config.go


示例17: getArmClient

// 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())
//.........这里部分代码省略.........
开发者ID:spotinst,项目名称:terraform,代码行数:101,代码来源:config.go


示例18: main

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",
//.........这里部分代码省略.........
开发者ID:ZhongtianWang,项目名称:azure,代码行数:101,代码来源:pricing.go


示例19: getArmClient

// 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())
//.........这里部分代码省略.........
开发者ID:hashicorp,项目名称:terraform,代码行数:101,代码来源:config.go



注:本文中的github.com/Azure/go-autorest/autorest/azure.NewServicePrincipalToken函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang azure.WithErrorUnlessStatusCode函数代码示例发布时间:2022-05-24
下一篇:
Golang azure.DoPollForAsynchronous函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap