Ejemplo n.º 1
0
func NewClient() *AzureClient {
	c, err := LoadAzureCredentials()
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return nil
	}

	spt, err := NewServicePrincipalTokenFromCredentials(c, azure.AzureResourceManagerScope)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return nil
	}

	rmc := resources.NewResourceGroupsClient(c["subscriptionID"])
	rmc.Authorizer = spt
	rmc.PollingMode = autorest.DoNotPoll

	sac := storage.NewStorageAccountsClient(c["subscriptionID"])
	sac.Authorizer = spt
	sac.PollingMode = autorest.DoNotPoll

	return &AzureClient{
		ResourceManagementClient: &rmc,
		StorageAccountsClient:    &sac,
	}
}
Ejemplo n.º 2
0
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
	}
}