-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
client_options.go
75 lines (61 loc) · 2.37 KB
/
client_options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package common
import (
"fmt"
"log"
"os"
"strings"
"time"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/hashicorp/go-azure-helpers/sender"
"github.com/hashicorp/terraform-plugin-sdk/httpclient"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/version"
)
type ClientOptions struct {
SubscriptionId string
TenantID string
PartnerId string
TerraformVersion string
GraphAuthorizer autorest.Authorizer
GraphEndpoint string
KeyVaultAuthorizer autorest.Authorizer
ResourceManagerAuthorizer autorest.Authorizer
ResourceManagerEndpoint string
StorageAuthorizer autorest.Authorizer
SkipProviderReg bool
DisableCorrelationRequestID bool
Environment azure.Environment
// TODO: remove me in 2.0
PollingDuration time.Duration
}
func (o ClientOptions) ConfigureClient(c *autorest.Client, authorizer autorest.Authorizer) {
setUserAgent(c, o.TerraformVersion, o.PartnerId)
c.Authorizer = authorizer
c.Sender = sender.BuildSender("AzureRM")
c.SkipResourceProviderRegistration = o.SkipProviderReg
if !o.DisableCorrelationRequestID {
c.RequestInspector = WithCorrelationRequestID(CorrelationRequestID())
}
// TODO: remove in 2.0
if !features.SupportsCustomTimeouts() {
c.PollingDuration = o.PollingDuration
}
}
func setUserAgent(client *autorest.Client, tfVersion, partnerID string) {
tfUserAgent := httpclient.TerraformUserAgent(tfVersion)
providerUserAgent := fmt.Sprintf("%s terraform-provider-azurerm/%s", tfUserAgent, version.ProviderVersion)
client.UserAgent = strings.TrimSpace(fmt.Sprintf("%s %s", client.UserAgent, providerUserAgent))
// append the CloudShell version to the user agent if it exists
if azureAgent := os.Getenv("AZURE_HTTP_USER_AGENT"); azureAgent != "" {
client.UserAgent = fmt.Sprintf("%s %s", client.UserAgent, azureAgent)
}
// only one pid can be interpreted currently
// hence, send partner ID if present, otherrwise send Terraform GUID
if partnerID == "" {
// Microsoft’s Terraform Partner ID is this specific GUID
partnerID = "222c6c49-1b0a-5959-a213-6608f9eb8820"
}
client.UserAgent = fmt.Sprintf("%s pid-%s", client.UserAgent, partnerID)
log.Printf("[DEBUG] AzureRM Client User Agent: %s\n", client.UserAgent)
}