terraform/vendor/github.com/jen20/riviera/azure/client.go

59 lines
1.2 KiB
Go
Raw Normal View History

package azure
import (
"io/ioutil"
"log"
"github.com/hashicorp/go-retryablehttp"
2016-05-07 02:36:25 +02:00
"net/http"
)
type Client struct {
logger *log.Logger
BaseURL string
subscriptionID string
tokenRequester *tokenRequester
httpClient *retryablehttp.Client
}
func NewClient(creds *AzureResourceManagerCredentials) (*Client, error) {
defaultLogger := log.New(ioutil.Discard, "", 0)
httpClient := retryablehttp.NewClient()
httpClient.Logger = defaultLogger
tr := newTokenRequester(httpClient, creds.ClientID, creds.ClientSecret, creds.TenantID)
return &Client{
BaseURL: "https://management.azure.com",
subscriptionID: creds.SubscriptionID,
httpClient: httpClient,
tokenRequester: tr,
logger: defaultLogger,
}, nil
}
2016-05-07 02:36:25 +02:00
func (c *Client) SetRequestLoggingHook(hook func (*log.Logger, *http.Request, int)) {
c.httpClient.RequestLogHook = hook
}
func (c *Client) SetLogger(newLogger *log.Logger) {
c.logger = newLogger
c.httpClient.Logger = newLogger
}
func (c *Client) NewRequest() *Request {
return &Request{
client: c,
}
}
func (c *Client) NewRequestForURI(resourceURI string) *Request {
return &Request{
URI: &resourceURI,
client: c,
}
}