github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/builder/azure/arm/azure_client.go (about) 1 // Copyright (c) Microsoft Corporation. All rights reserved. 2 // Licensed under the MIT License. See the LICENSE file in builder/azure for license information. 3 4 package arm 5 6 import ( 7 "github.com/Azure/azure-sdk-for-go/arm/compute" 8 "github.com/Azure/azure-sdk-for-go/arm/network" 9 "github.com/Azure/azure-sdk-for-go/arm/resources/resources" 10 armStorage "github.com/Azure/azure-sdk-for-go/arm/storage" 11 "github.com/Azure/azure-sdk-for-go/storage" 12 13 "github.com/Azure/go-autorest/autorest/azure" 14 ) 15 16 type AzureClient struct { 17 compute.VirtualMachinesClient 18 network.PublicIPAddressesClient 19 resources.GroupsClient 20 resources.DeploymentsClient 21 storage.BlobStorageClient 22 } 23 24 func NewAzureClient(subscriptionID string, resourceGroupName string, storageAccountName string, servicePrincipalToken *azure.ServicePrincipalToken) (*AzureClient, error) { 25 var azureClient = &AzureClient{} 26 27 azureClient.DeploymentsClient = resources.NewDeploymentsClient(subscriptionID) 28 azureClient.DeploymentsClient.Authorizer = servicePrincipalToken 29 30 azureClient.GroupsClient = resources.NewGroupsClient(subscriptionID) 31 azureClient.GroupsClient.Authorizer = servicePrincipalToken 32 33 azureClient.PublicIPAddressesClient = network.NewPublicIPAddressesClient(subscriptionID) 34 azureClient.PublicIPAddressesClient.Authorizer = servicePrincipalToken 35 36 azureClient.VirtualMachinesClient = compute.NewVirtualMachinesClient(subscriptionID) 37 azureClient.VirtualMachinesClient.Authorizer = servicePrincipalToken 38 39 storageAccountsClient := armStorage.NewAccountsClient(subscriptionID) 40 storageAccountsClient.Authorizer = servicePrincipalToken 41 42 accountKeys, err := storageAccountsClient.ListKeys(resourceGroupName, storageAccountName) 43 if err != nil { 44 return nil, err 45 } 46 47 storageClient, err := storage.NewBasicClient(storageAccountName, *accountKeys.Key1) 48 if err != nil { 49 return nil, err 50 } 51 52 azureClient.BlobStorageClient = storageClient.GetBlobService() 53 return azureClient, nil 54 }