From b26846fb5fa52e20bccfb55f13c6e3107515d043 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Mon, 31 Oct 2016 12:19:20 +0000 Subject: [PATCH] Revert "provider/azurerm: Bump SDK version of jen20/riviera" (#9742) --- .../github.com/jen20/riviera/azure/client.go | 7 +-- .../jen20/riviera/azure/endpoints.go | 27 ---------- .../jen20/riviera/azure/locations.go | 51 ++++++++----------- .../github.com/jen20/riviera/azure/request.go | 10 ++-- .../github.com/jen20/riviera/azure/token.go | 15 +++--- .../jen20/riviera/sql/get_database.go | 42 +++++++-------- vendor/vendor.json | 24 ++++----- 7 files changed, 70 insertions(+), 106 deletions(-) delete mode 100644 vendor/github.com/jen20/riviera/azure/endpoints.go diff --git a/vendor/github.com/jen20/riviera/azure/client.go b/vendor/github.com/jen20/riviera/azure/client.go index f7d2c885a3..937760dc2d 100644 --- a/vendor/github.com/jen20/riviera/azure/client.go +++ b/vendor/github.com/jen20/riviera/azure/client.go @@ -4,14 +4,14 @@ import ( "io/ioutil" "log" - "net/http" - "github.com/hashicorp/go-retryablehttp" + "net/http" ) type Client struct { logger *log.Logger + BaseURL string subscriptionID string tokenRequester *tokenRequester @@ -27,6 +27,7 @@ func NewClient(creds *AzureResourceManagerCredentials) (*Client, error) { tr := newTokenRequester(httpClient, creds.ClientID, creds.ClientSecret, creds.TenantID) return &Client{ + BaseURL: "https://management.azure.com", subscriptionID: creds.SubscriptionID, httpClient: httpClient, tokenRequester: tr, @@ -34,7 +35,7 @@ func NewClient(creds *AzureResourceManagerCredentials) (*Client, error) { }, nil } -func (c *Client) SetRequestLoggingHook(hook func(*log.Logger, *http.Request, int)) { +func (c *Client) SetRequestLoggingHook(hook func (*log.Logger, *http.Request, int)) { c.httpClient.RequestLogHook = hook } diff --git a/vendor/github.com/jen20/riviera/azure/endpoints.go b/vendor/github.com/jen20/riviera/azure/endpoints.go deleted file mode 100644 index 72ac6c9c0c..0000000000 --- a/vendor/github.com/jen20/riviera/azure/endpoints.go +++ /dev/null @@ -1,27 +0,0 @@ -package azure - -import "strings" - -type Endpoints struct { - resourceManagerEndpointUrl string - activeDirectoryEndpointUrl string -} - -func GetEndpoints(location string) Endpoints { - var e Endpoints - - location = strings.Replace(strings.ToLower(location), " ", "", -1) - - switch location { - case GermanyCentral, GermanyEast: - e = Endpoints{"https://management.microsoftazure.de", "https://login.microsoftonline.de"} - case ChinaEast, ChinaNorth: - e = Endpoints{"https://management.chinacloudapi.cn", "https://login.chinacloudapi.cn"} - case USGovIowa, USGovVirginia: - e = Endpoints{"https://management.usgovcloudapi.net", "https://login.microsoftonline.com"} - default: - e = Endpoints{"https://management.azure.com", "https://login.microsoftonline.com"} - } - - return e -} diff --git a/vendor/github.com/jen20/riviera/azure/locations.go b/vendor/github.com/jen20/riviera/azure/locations.go index c52c7c1bdc..fb72bb3571 100644 --- a/vendor/github.com/jen20/riviera/azure/locations.go +++ b/vendor/github.com/jen20/riviera/azure/locations.go @@ -1,33 +1,26 @@ package azure const ( - Global = "global" - CentralUS = "centralus" - EastUS = "eastus" - EastUS2 = "eastus2" - USGovIowa = "usgoviowa" - USGovVirginia = "usgovvirginia" - NorthCentralUS = "northcentralus" - SouthCentralUS = "southcentralus" - WestUS = "westus" - NorthEurope = "northeurope" - WestEurope = "westeurope" - EastAsia = "eastasia" - SoutheastAsia = "southeastasia" - JapanEast = "japaneast" - JapanWest = "japanwest" - BrazilSouth = "brazilsouth" - AustraliaEast = "australiaeast" - AustraliaSouthEast = "australiasoutheast" - CentralIndia = "centralindia" - SouthIndia = "southindia" - WestIndia = "westindia" - ChinaEast = "chinaeast" - ChinaNorth = "chinanorth" - UKSouth = "uksouth" - UKWest = "ukwest" - CanadaCentral = "canadacentral" - CanadaEast = "canadaeast" - GermanyCentral = "germanycentral" - GermanyEast = "germanyeast" + Global = "global" + CentralUS = "centralus" + EastUS = "eastus" + EastUS2 = "eastus2" + USGovIowa = "usgoviowa" + USGovVirginia = "usgovvirginia" + NorthCentralUS = "northcentralus" + SouthCentralUS = "southcentralus" + WestUS = "westus" + NorthEurope = "northeurope" + WestEurope = "westeurope" + EastAsia = "eastasia" + SoutheastAsia = "southeastasia" + JapanEast = "japaneast" + JapanWest = "japanwest" + BrazilSouth = "brazilsouth" + AustraliaEast = "australiaeast" + Australia = "australia" + CentralIndia = "centralindia" + SouthIndia = "southindia" + WestIndia = "westindia" + ChinaEast = "chinaeast" ) diff --git a/vendor/github.com/jen20/riviera/azure/request.go b/vendor/github.com/jen20/riviera/azure/request.go index 68c61d1a68..a7546a751c 100644 --- a/vendor/github.com/jen20/riviera/azure/request.go +++ b/vendor/github.com/jen20/riviera/azure/request.go @@ -75,8 +75,7 @@ func (request *Request) pollForAsynchronousResponse(acceptedResponse *http.Respo return nil, err } - location := reflect.Indirect(reflect.ValueOf(request.Command)).FieldByName("Location").Interface().(string) - err = request.client.tokenRequester.addAuthorizationToRequest(req, location) + err = request.client.tokenRequester.addAuthorizationToRequest(req) if err != nil { return nil, err } @@ -116,11 +115,10 @@ func defaultARMRequestSerialize(body interface{}) (io.ReadSeeker, error) { func (request *Request) Execute() (*Response, error) { apiInfo := request.Command.APIInfo() - location := reflect.Indirect(reflect.ValueOf(request.Command)).FieldByName("Location").Interface().(string) - var urlString string - urlObj, _ := url.Parse(GetEndpoints(location).resourceManagerEndpointUrl) + // Base URL should already be validated by now so Parse is safe without error handling + urlObj, _ := url.Parse(request.client.BaseURL) // Determine whether to use the URLPathFunc or the URI explicitly set in the request if request.URI == nil { @@ -166,7 +164,7 @@ func (request *Request) Execute() (*Response, error) { req.Header.Add("Content-Type", "application/json") } - err = request.client.tokenRequester.addAuthorizationToRequest(req, location) + err = request.client.tokenRequester.addAuthorizationToRequest(req) if err != nil { return nil, err } diff --git a/vendor/github.com/jen20/riviera/azure/token.go b/vendor/github.com/jen20/riviera/azure/token.go index 2c6f38abf5..cf99c17abe 100644 --- a/vendor/github.com/jen20/riviera/azure/token.go +++ b/vendor/github.com/jen20/riviera/azure/token.go @@ -43,8 +43,8 @@ func newTokenRequester(client *retryablehttp.Client, clientID, clientSecret, ten // addAuthorizationToRequest adds an Authorization header to an http.Request, having ensured // that the token is sufficiently fresh. This may invoke network calls, so should not be // relied on to return quickly. -func (tr *tokenRequester) addAuthorizationToRequest(request *retryablehttp.Request, location string) error { - token, err := tr.getUsableToken(location) +func (tr *tokenRequester) addAuthorizationToRequest(request *retryablehttp.Request) error { + token, err := tr.getUsableToken() if err != nil { return fmt.Errorf("Error obtaining authorization token: %s", err) } @@ -53,7 +53,7 @@ func (tr *tokenRequester) addAuthorizationToRequest(request *retryablehttp.Reque return nil } -func (tr *tokenRequester) getUsableToken(location string) (*token, error) { +func (tr *tokenRequester) getUsableToken() (*token, error) { tr.l.Lock() defer tr.l.Unlock() @@ -61,7 +61,7 @@ func (tr *tokenRequester) getUsableToken(location string) (*token, error) { return tr.currentToken, nil } - newToken, err := tr.refreshToken(location) + newToken, err := tr.refreshToken() if err != nil { return nil, fmt.Errorf("Error refreshing token: %s", err) } @@ -70,15 +70,14 @@ func (tr *tokenRequester) getUsableToken(location string) (*token, error) { return newToken, nil } -func (tr *tokenRequester) refreshToken(location string) (*token, error) { - endpoints := GetEndpoints(location) - oauthURL := fmt.Sprintf("%s/%s/oauth2/%s?api-version=1.0", endpoints.activeDirectoryEndpointUrl, tr.tenantID, "token") +func (tr *tokenRequester) refreshToken() (*token, error) { + oauthURL := fmt.Sprintf("https://login.microsoftonline.com/%s/oauth2/%s?api-version=1.0", tr.tenantID, "token") v := url.Values{} v.Set("client_id", tr.clientID) v.Set("client_secret", tr.clientSecret) v.Set("grant_type", "client_credentials") - v.Set("resource", endpoints.resourceManagerEndpointUrl) + v.Set("resource", "https://management.azure.com/") var newToken token response, err := tr.httpClient.PostForm(oauthURL, v) diff --git a/vendor/github.com/jen20/riviera/sql/get_database.go b/vendor/github.com/jen20/riviera/sql/get_database.go index d8bbdd42e0..ed6a72aea7 100644 --- a/vendor/github.com/jen20/riviera/sql/get_database.go +++ b/vendor/github.com/jen20/riviera/sql/get_database.go @@ -3,27 +3,27 @@ package sql import "github.com/jen20/riviera/azure" type GetDatabaseResponse struct { - ID *string `mapstructure:"id"` - Name *string `mapstructure:"name"` - Location *string `mapstructure:"location"` - Tags *map[string]*string `mapstructure:"tags"` - Kind *string `mapstructure:"kind"` - DatabaseID *string `mapstructure:"databaseId"` - DatabaseName *string `mapstructure:"databaseName"` - Status *string `mapstructure:"status"` - Collation *string `mapstructure:"collation"` - Edition *string `mapstructure:"edition"` - ServiceLevelObjective *string `mapstructure:"serviceLevelObjective"` - MaxSizeInBytes *string `mapstructure:"maxSizeInBytes"` - CreationDate *string `mapstructure:"creationDate"` - CurrentServiceLevelObjectiveID *string `mapstructure:"currentServiceLevelObjectiveId"` - RequestedServiceObjectiveID *string `mapstructure:"requestedServiceObjectiveId"` - RequestedServiceObjectiveName *string `mapstructure:"requestedServiceObjectiveName"` - DefaultSecondaryLocation *string `mapstructure:"defaultSecondaryLocation"` - Encryption *string `mapstructure:"encryption"` - EarliestRestoreDate *string `mapstructure:"earliestRestoreDate"` - ElasticPoolName *string `mapstructure:"elasticPoolName"` - ContainmentState *string `mapstructure:"containmentState"` + ID *string `mapstructure:"id"` + Name *string `mapstructure:"name"` + Location *string `mapstructure:"location"` + Tags *map[string]string `mapstructure:"tags"` + Kind *string `mapstructure:"kind"` + DatabaseID *string `mapstructure:"databaseId"` + DatabaseName *string `mapstructure:"databaseName"` + Status *string `mapstructure:"status"` + Collation *string `mapstructure:"collation"` + Edition *string `mapstructure:"edition"` + ServiceLevelObjective *string `mapstructure:"serviceLevelObjective"` + MaxSizeInBytes *string `mapstructure:"maxSizeInBytes"` + CreationDate *string `mapstructure:"creationDate"` + CurrentServiceLevelObjectiveID *string `mapstructure:"currentServiceLevelObjectiveId"` + RequestedServiceObjectiveID *string `mapstructure:"requestedServiceObjectiveId"` + RequestedServiceObjectiveName *string `mapstructure:"requestedServiceObjectiveName"` + DefaultSecondaryLocation *string `mapstructure:"defaultSecondaryLocation"` + Encryption *string `mapstructure:"encryption"` + EarliestRestoreDate *string `mapstructure:"earliestRestoreDate"` + ElasticPoolName *string `mapstructure:"elasticPoolName"` + ContainmentState *string `mapstructure:"containmentState"` } type GetDatabase struct { diff --git a/vendor/vendor.json b/vendor/vendor.json index 3486698933..cd6674c059 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1451,34 +1451,34 @@ "revisionTime": "2016-09-29T21:48:42Z" }, { - "checksumSHA1": "dQ9OpoeiMUPiSgRPCC5Ekj3uNu8=", + "checksumSHA1": "oPpOfZn11Ef6DWOoETxSW9Venzs=", "path": "github.com/jen20/riviera/azure", - "revision": "f6cb638392f1df73c2385b8c5c4f6dcba421eeaf", - "revisionTime": "2016-10-31T11:27:19Z" + "revision": "1159d86fc8144abafeb29ee7c5a3e2e85af336ba", + "revisionTime": "2016-06-30T14:11:29Z" }, { "checksumSHA1": "ncdT+1PFEF5ly0niXuQc9/pKzT0=", "path": "github.com/jen20/riviera/dns", - "revision": "f6cb638392f1df73c2385b8c5c4f6dcba421eeaf", - "revisionTime": "2016-10-31T11:27:19Z" + "revision": "1159d86fc8144abafeb29ee7c5a3e2e85af336ba", + "revisionTime": "2016-06-30T14:11:29Z" }, { "checksumSHA1": "zVXx6ha3bt0N4ukRbRHXjSl91S4=", "path": "github.com/jen20/riviera/search", - "revision": "f6cb638392f1df73c2385b8c5c4f6dcba421eeaf", - "revisionTime": "2016-10-31T11:27:19Z" + "revision": "1159d86fc8144abafeb29ee7c5a3e2e85af336ba", + "revisionTime": "2016-06-30T14:11:29Z" }, { - "checksumSHA1": "mD+brnqSfkLheYdGzTUqUi6VWgw=", + "checksumSHA1": "KfquDaeBPGchw92QnojlJFsJKgk=", "path": "github.com/jen20/riviera/sql", - "revision": "f6cb638392f1df73c2385b8c5c4f6dcba421eeaf", - "revisionTime": "2016-10-31T11:27:19Z" + "revision": "1159d86fc8144abafeb29ee7c5a3e2e85af336ba", + "revisionTime": "2016-06-30T14:11:29Z" }, { "checksumSHA1": "nKUCquNpJ9ifHgkXoT4K3Xar6R8=", "path": "github.com/jen20/riviera/storage", - "revision": "f6cb638392f1df73c2385b8c5c4f6dcba421eeaf", - "revisionTime": "2016-10-31T11:27:19Z" + "revision": "1159d86fc8144abafeb29ee7c5a3e2e85af336ba", + "revisionTime": "2016-06-30T14:11:29Z" }, { "comment": "0.2.2-2-gc01cf91",