Skip to content

Commit

Permalink
move pollclient up a level and make it more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
frodopwns committed Apr 3, 2020
1 parent 5e219fa commit 1793522
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/Azure/azure-service-operator/pkg/helpers"
"github.com/Azure/azure-service-operator/pkg/resourcemanager"
azuresqlshared "github.com/Azure/azure-service-operator/pkg/resourcemanager/azuresql/azuresqlshared"
"github.com/Azure/azure-service-operator/pkg/resourcemanager/pollclient"
"github.com/Azure/azure-service-operator/pkg/secrets"
"github.com/Azure/go-autorest/autorest/to"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -106,12 +107,11 @@ func (s *AzureSqlServerManager) Ensure(ctx context.Context, obj runtime.Object,

serv, err := s.GetServer(ctx, instance.Spec.ResourceGroup, instance.Name)
if err != nil {

azerr := errhelp.NewAzureErrorAzureError(err)

// handle failures in the async operation
if instance.Status.PollingURL != "" {
pClient := NewPollClient()
pClient := pollclient.NewPollClient()
res, err := pClient.Get(ctx, instance.Status.PollingURL)
if err != nil {
return false, err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,56 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package azuresqlserver
package pollclient

import (
"context"
"net/http"

"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2015-05-01-preview/sql"
"github.com/Azure/azure-service-operator/pkg/resourcemanager/config"
"github.com/Azure/azure-service-operator/pkg/resourcemanager/iam"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/tracing"
)

const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2015-05-01-preview/sql"
const fqdn = "github.com/Azure/azure-service-operator/pollingclient"

// PollClient inherits from the sql sdk baseclient and has the methods needed to handle the polling url
// BaseClient was modeled off some of the other Baseclients in the go sdk and contains an autorest client
type BaseClient struct {
autorest.Client
BaseURI string
SubscriptionID string
}

// PollClient inherits from the autorest client and has the methods needed to handle GETs to the polling url
type PollClient struct {
sql.BaseClient
BaseClient
}

// NewPollClient returns a client using hte env values
// NewPollClient returns a client using hte env values from config
func NewPollClient() PollClient {
return NewPollClientWithBaseURI(config.BaseURI(), config.SubscriptionID())
}

// NewPollClientWithBaseURI returns a paramterized client
func NewPollClientWithBaseURI(baseURI string, subscriptionID string) PollClient {
c := PollClient{sql.NewWithBaseURI(baseURI, subscriptionID)}
c := PollClient{NewWithBaseURI(baseURI, subscriptionID)}
a, _ := iam.GetResourceManagementAuthorizer()
c.Authorizer = a
c.AddToUserAgent(config.UserAgent())
return c
}

// NewWithBaseURI creates an instance of the BaseClient client.
func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient {
return BaseClient{
Client: autorest.NewClientWithUserAgent(config.UserAgent()),
BaseURI: baseURI,
SubscriptionID: subscriptionID,
}
}

// PollRespons models the expected response from the poll url
type PollRespons struct {
autorest.Response `json:"-"`
Expand Down

0 comments on commit 1793522

Please sign in to comment.