Skip to content

Commit

Permalink
Add CreateVMInsightsClientE, CreateActivityLogAlertsClientE, CreateDi…
Browse files Browse the repository at this point in the history
…agnosticsSettingsClientE
  • Loading branch information
davidkpiano committed Apr 29, 2021
1 parent fd6fc42 commit f03cac5
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 3 deletions.
81 changes: 81 additions & 0 deletions modules/azure/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"reflect"

"github.com/Azure/azure-sdk-for-go/profiles/preview/cosmos-db/mgmt/documentdb"
"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/monitor/mgmt/insights"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
"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"
Expand Down Expand Up @@ -206,6 +207,86 @@ func CreateStorageBlobContainerClientE(subscriptionID string) (*storage.BlobCont
return &blobContainerClient, nil
}

// CreateVMInsightsClientE gets a VM Insights client
func CreateVMInsightsClientE(subscriptionID string) (*insights.VMInsightsClient, 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
}

client := insights.NewVMInsightsClientWithBaseURI(baseURI, subscriptionID)

authorizer, err := NewAuthorizer()
if err != nil {
return nil, err
}

client.Authorizer = *authorizer

return &client, nil
}

// CreateActivityLogAlertsClientE gets an Action Groups client in the specified Azure Subscription
func CreateActivityLogAlertsClientE(subscriptionID string) (*insights.ActivityLogAlertsClient, 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
}

// Get the Action Groups client
client := insights.NewActivityLogAlertsClientWithBaseURI(baseURI, subscriptionID)

// Create an authorizer
authorizer, err := NewAuthorizer()
if err != nil {
return nil, err
}

client.Authorizer = *authorizer

return &client, nil
}

// CreateDiagnosticsSettingsClientE returns a diagnostics settings client
func CreateDiagnosticsSettingsClientE(subscriptionID string) (*insights.DiagnosticSettingsClient, 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
}

client := insights.NewDiagnosticSettingsClientWithBaseURI(baseURI, subscriptionID)

authorizer, err := NewAuthorizer()
if err != nil {
return nil, err
}

client.Authorizer = *authorizer

return &client, 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) {
Expand Down
9 changes: 6 additions & 3 deletions modules/azure/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func GetDiagnosticsSettingsResourceE(name string, resourceURI string, subscripti
return nil, err
}

client, err := GetDiagnosticsSettingsClientE(subscriptionID)
client, err := CreateDiagnosticsSettingsClientE(subscriptionID)
if err != nil {
return nil, err
}
Expand All @@ -60,6 +60,7 @@ func GetDiagnosticsSettingsResourceE(name string, resourceURI string, subscripti
}

// GetDiagnosticsSettingsClientE returns a diagnostics settings client
// TODO: delete in next version
func GetDiagnosticsSettingsClientE(subscriptionID string) (*insights.DiagnosticSettingsClient, error) {
// Validate Azure subscription ID
subscriptionID, err := getTargetAzureSubscription(subscriptionID)
Expand Down Expand Up @@ -89,7 +90,7 @@ func GetVMInsightsOnboardingStatus(t testing.TestingT, resourceURI string, subsc

// GetVMInsightsOnboardingStatusE get diagnostics VM onboarding status
func GetVMInsightsOnboardingStatusE(t testing.TestingT, resourceURI string, subscriptionID string) (*insights.VMInsightsOnboardingStatus, error) {
client, err := GetVMInsightsClientE(t, subscriptionID)
client, err := CreateVMInsightsClientE(subscriptionID)
if err != nil {
return nil, err
}
Expand All @@ -103,6 +104,7 @@ func GetVMInsightsOnboardingStatusE(t testing.TestingT, resourceURI string, subs
}

// GetVMInsightsClientE gets a VM Insights client
// TODO: delete in next version
func GetVMInsightsClientE(t testing.TestingT, subscriptionID string) (*insights.VMInsightsClient, error) {
// Validate Azure subscription ID
subscriptionID, err := getTargetAzureSubscription(subscriptionID)
Expand Down Expand Up @@ -140,7 +142,7 @@ func GetActivityLogAlertResourceE(activityLogAlertName string, resGroupName stri
}

// Get the client reference
client, err := GetActivityLogAlertsClientE(subscriptionID)
client, err := CreateActivityLogAlertsClientE(subscriptionID)
if err != nil {
return nil, err
}
Expand All @@ -155,6 +157,7 @@ func GetActivityLogAlertResourceE(activityLogAlertName string, resGroupName stri
}

// GetActivityLogAlertsClientE gets an Action Groups client in the specified Azure Subscription
// TODO: delete in next version
func GetActivityLogAlertsClientE(subscriptionID string) (*insights.ActivityLogAlertsClient, error) {
// Validate Azure subscription ID
subscriptionID, err := getTargetAzureSubscription(subscriptionID)
Expand Down

0 comments on commit f03cac5

Please sign in to comment.