diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1be3b7c5b..27dc1dbe9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,8 @@ name: ci-workflow # target_pr: pr number on the source repo (e.g. 14, 25, etc.) on: + push: + branches: master workflow_dispatch: inputs: repo: diff --git a/modules/azure/client_factory.go b/modules/azure/client_factory.go index d871de180..906967976 100644 --- a/modules/azure/client_factory.go +++ b/modules/azure/client_factory.go @@ -19,6 +19,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-11-01/containerservice" kvmng "github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-06-01/subscriptions" + "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" autorestAzure "github.com/Azure/go-autorest/autorest/azure" ) @@ -45,7 +46,7 @@ type ClientType int // the Azure environment that is currently setup (or "Public", if none is setup). func CreateSubscriptionsClientE() (subscriptions.Client, error) { // Lookup environment URI - baseURI, err := getEnvironmentEndpointE(ResourceManagerEndpointName) + baseURI, err := getBaseURI() if err != nil { return subscriptions.Client{}, err } @@ -66,7 +67,7 @@ func CreateVirtualMachinesClientE(subscriptionID string) (compute.VirtualMachine } // Lookup environment URI - baseURI, err := getEnvironmentEndpointE(ResourceManagerEndpointName) + baseURI, err := getBaseURI() if err != nil { return compute.VirtualMachinesClient{}, err } @@ -87,7 +88,7 @@ func CreateManagedClustersClientE(subscriptionID string) (containerservice.Manag } // Lookup environment URI - baseURI, err := getEnvironmentEndpointE(ResourceManagerEndpointName) + baseURI, err := getBaseURI() if err != nil { return containerservice.ManagedClustersClient{}, err } @@ -106,7 +107,7 @@ func CreateCosmosDBAccountClientE(subscriptionID string) (*documentdb.DatabaseAc } // Lookup environment URI - baseURI, err := getEnvironmentEndpointE(ResourceManagerEndpointName) + baseURI, err := getBaseURI() if err != nil { return nil, err } @@ -127,7 +128,7 @@ func CreateCosmosDBSQLClientE(subscriptionID string) (*documentdb.SQLResourcesCl } // Lookup environment URI - baseURI, err := getEnvironmentEndpointE(ResourceManagerEndpointName) + baseURI, err := getBaseURI() if err != nil { return nil, err } @@ -148,7 +149,7 @@ func CreateKeyVaultManagementClientE(subscriptionID string) (*kvmng.VaultsClient } // Lookup environment URI - baseURI, err := getEnvironmentEndpointE(ResourceManagerEndpointName) + baseURI, err := getBaseURI() if err != nil { return nil, err } @@ -159,6 +160,52 @@ func CreateKeyVaultManagementClientE(subscriptionID string) (*kvmng.VaultsClient return &vaultClient, nil } +// CreateStorageAccountClientE creates a storage account client. +func CreateStorageAccountClientE(subscriptionID string) (*storage.AccountsClient, error) { + // Validate Azure subscription ID + subscriptionID, err := getTargetAzureSubscription(subscriptionID) + if err != nil { + return nil, err + } + + // Lookup environment URI + baseURI, err := getBaseURI() + if err != nil { + return nil, err + } + + storageAccountClient := storage.NewAccountsClientWithBaseURI(baseURI, subscriptionID) + authorizer, err := NewAuthorizer() + if err != nil { + return nil, err + } + storageAccountClient.Authorizer = *authorizer + return &storageAccountClient, nil +} + +// CreateStorageBlobContainerClientE creates a storage container client. +func CreateStorageBlobContainerClientE(subscriptionID string) (*storage.BlobContainersClient, error) { + subscriptionID, err := getTargetAzureSubscription(subscriptionID) + if err != nil { + return nil, err + } + + // Lookup environment URI + baseURI, err := getBaseURI() + if err != nil { + return nil, err + } + + blobContainerClient := storage.NewBlobContainersClientWithBaseURI(baseURI, subscriptionID) + authorizer, err := NewAuthorizer() + + if err != nil { + return nil, err + } + blobContainerClient.Authorizer = *authorizer + return &blobContainerClient, nil +} + // GetKeyVaultURISuffixE returns the proper KeyVault URI suffix for the configured Azure environment. // This function would fail the test if there is an error. func GetKeyVaultURISuffixE() (string, error) { @@ -197,3 +244,13 @@ func getFieldValue(env *autorestAzure.Environment, field string) string { fieldVal := reflect.Indirect(structValue).FieldByName(field) return fieldVal.String() } + +// getBaseURI gets the base URI endpoint. +func getBaseURI() (string, error) { + // Lookup environment URI + baseURI, err := getEnvironmentEndpointE(ResourceManagerEndpointName) + if err != nil { + return "", err + } + return baseURI, nil +} diff --git a/modules/azure/storage.go b/modules/azure/storage.go index 7db176ee6..59c53f459 100644 --- a/modules/azure/storage.go +++ b/modules/azure/storage.go @@ -141,7 +141,7 @@ func GetStorageBlobContainerE(containerName, storageAccountName, resourceGroupNa if err2 != nil { return nil, err2 } - client, err := GetStorageBlobContainerClientE(subscriptionID) + client, err := CreateStorageBlobContainerClientE(subscriptionID) if err != nil { return nil, err } @@ -162,7 +162,7 @@ func GetStorageAccountPropertyE(storageAccountName, resourceGroupName, subscript if err2 != nil { return nil, err2 } - client, err := GetStorageAccountClientE(subscriptionID) + client, err := CreateStorageAccountClientE(subscriptionID) if err != nil { return nil, err } @@ -174,6 +174,7 @@ func GetStorageAccountPropertyE(storageAccountName, resourceGroupName, subscript } // GetStorageAccountClientE creates a storage account client. +// TODO: remove in next version func GetStorageAccountClientE(subscriptionID string) (*storage.AccountsClient, error) { // Validate Azure subscription ID subscriptionID, err := getTargetAzureSubscription(subscriptionID) @@ -191,6 +192,7 @@ func GetStorageAccountClientE(subscriptionID string) (*storage.AccountsClient, e } // GetStorageBlobContainerClientE creates a storage container client. +// TODO: remove in next version func GetStorageBlobContainerClientE(subscriptionID string) (*storage.BlobContainersClient, error) { subscriptionID, err := getTargetAzureSubscription(subscriptionID) if err != nil {