Skip to content

Commit

Permalink
Merge branch 'master' into task#800RMloggerVnet
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamMortlMicrosoft authored Mar 31, 2020
2 parents 089cf96 + 3e1953f commit c835c82
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
34 changes: 21 additions & 13 deletions pkg/resourcemanager/appinsights/appinsights.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package appinsights
import (
"context"
"fmt"
"log"
"net/http"

"github.com/Azure/azure-service-operator/pkg/secrets"

Expand Down Expand Up @@ -81,9 +81,12 @@ func (m *Manager) CreateAppInsights(
kind string,
applicationType string,
location string,
resourceName string) (insights.ApplicationInsightsComponent, error) {
resourceName string) (*insights.ApplicationInsightsComponent, error) {

componentsClient := getComponentsClient()
componentsClient, err := getComponentsClient()
if err != nil {
return nil, err
}

// submit the ARM request
result, err := componentsClient.CreateOrUpdate(
Expand All @@ -100,7 +103,7 @@ func (m *Manager) CreateAppInsights(
},
},
)
return result, err
return &result, err
}

// Ensure checks the desired state of the operator
Expand Down Expand Up @@ -212,7 +215,10 @@ func (m *Manager) DeleteAppInsights(
resourceGroupName string,
resourceName string) (autorest.Response, error) {

componentsClient := getComponentsClient()
componentsClient, err := getComponentsClient()
if err != nil {
return autorest.Response{Response: &http.Response{StatusCode: 500}}, err
}

result, err := componentsClient.Get(ctx, resourceGroupName, resourceName)
if err == nil {
Expand All @@ -227,19 +233,21 @@ func (m *Manager) GetAppInsights(
resourceGroupName string,
resourceName string) (insights.ApplicationInsightsComponent, error) {

componentsClient := getComponentsClient()
componentsClient, err := getComponentsClient()
if err != nil {
return insights.ApplicationInsightsComponent{}, err
}
return componentsClient.Get(ctx, resourceGroupName, resourceName)
}

func getComponentsClient() insights.ComponentsClient {
func getComponentsClient() (insights.ComponentsClient, error) {
insightsClient := insights.NewComponentsClientWithBaseURI(config.BaseURI(), config.SubscriptionID())

a, err := iam.GetResourceManagementAuthorizer()
if err != nil {
log.Fatalf("failed to initialize authorizer %v\n", err)
insightsClient = insights.ComponentsClient{}
} else {
insightsClient.Authorizer = a
insightsClient.AddToUserAgent(config.UserAgent())
}
insightsClient.Authorizer = a
insightsClient.AddToUserAgent(config.UserAgent())

return insightsClient
return insightsClient, err
}
2 changes: 1 addition & 1 deletion pkg/resourcemanager/appinsights/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ApplicationInsightsManager interface {
kind string,
applicationType string,
location string,
resourceName string) (insights.ApplicationInsightsComponent, error)
resourceName string) (*insights.ApplicationInsightsComponent, error)
DeleteAppInsights(ctx context.Context, resourceGroupName string, resourceName string) (autorest.Response, error)
GetAppInsights(ctx context.Context, resourceGroupName string, resourceName string) (insights.ApplicationInsightsComponent, error)

Expand Down
4 changes: 3 additions & 1 deletion pkg/resourcemanager/appinsights/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package appinsights

import (
"fmt"
"github.com/Azure/azure-service-operator/pkg/errhelp"
"log"
"testing"
"time"

"github.com/Azure/azure-service-operator/pkg/errhelp"

"context"

resourcemanagerconfig "github.com/Azure/azure-service-operator/pkg/resourcemanager/config"
resourcegroupsresourcemanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/resourcegroups"
. "github.com/onsi/ginkgo"
Expand Down
31 changes: 21 additions & 10 deletions pkg/resourcemanager/cosmosdbs/cosmosdbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cosmosdbs
import (
"context"
"fmt"
"log"

"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb"
azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1"
Expand All @@ -15,15 +14,17 @@ import (
"github.com/Azure/go-autorest/autorest/to"
)

func getCosmosDBClient() documentdb.DatabaseAccountsClient {
func getCosmosDBClient() (documentdb.DatabaseAccountsClient, error) {
cosmosDBClient := documentdb.NewDatabaseAccountsClientWithBaseURI(config.BaseURI(), config.SubscriptionID())
a, err := iam.GetResourceManagementAuthorizer()
if err != nil {
log.Fatalf("failed to initialize authorizer: %v\n", err)
cosmosDBClient = documentdb.DatabaseAccountsClient{}
} else {
cosmosDBClient.Authorizer = a
cosmosDBClient.AddToUserAgent(config.UserAgent())
}
cosmosDBClient.Authorizer = a
cosmosDBClient.AddToUserAgent(config.UserAgent())
return cosmosDBClient

return cosmosDBClient, err
}

// CreateCosmosDB creates a new CosmosDB
Expand All @@ -33,7 +34,10 @@ func CreateCosmosDB(ctx context.Context, groupName string,
kind azurev1alpha1.CosmosDBKind,
dbType azurev1alpha1.CosmosDBDatabaseAccountOfferType,
tags map[string]*string) (*documentdb.DatabaseAccount, error) {
cosmosDBClient := getCosmosDBClient()
cosmosDBClient, err := getCosmosDBClient()
if err != nil {
return nil, err
}

dbKind := documentdb.DatabaseAccountKind(kind)
sDBType := string(dbType)
Expand Down Expand Up @@ -91,7 +95,14 @@ func CreateCosmosDB(ctx context.Context, groupName string,
}

// DeleteCosmosDB removes the resource group named by env var
func DeleteCosmosDB(ctx context.Context, groupName string, cosmosDBName string) (result documentdb.DatabaseAccountsDeleteFuture, err error) {
cosmosDBClient := getCosmosDBClient()
return cosmosDBClient.Delete(ctx, groupName, cosmosDBName)
func DeleteCosmosDB(ctx context.Context, groupName string, cosmosDBName string) (result *documentdb.DatabaseAccountsDeleteFuture, err error) {
cosmosDBClient, err := getCosmosDBClient()
if err != nil {
return nil, err
}
future, err := cosmosDBClient.Delete(ctx, groupName, cosmosDBName)
if err != nil {
return nil, err
}
return &future, nil
}

0 comments on commit c835c82

Please sign in to comment.