@@ -4,8 +4,10 @@ import (
4
4
"context"
5
5
"fmt"
6
6
"log"
7
+ "os"
7
8
"strings"
8
9
10
+ "github.com/hashicorp/terraform-plugin-sdk/httpclient"
9
11
"github.com/microsoft/azure-devops-go-api/azuredevops"
10
12
"github.com/microsoft/azure-devops-go-api/azuredevops/build"
11
13
"github.com/microsoft/azure-devops-go-api/azuredevops/core"
@@ -15,6 +17,7 @@ import (
15
17
"github.com/microsoft/azure-devops-go-api/azuredevops/operations"
16
18
"github.com/microsoft/azure-devops-go-api/azuredevops/serviceendpoint"
17
19
"github.com/microsoft/azure-devops-go-api/azuredevops/taskagent"
20
+ "github.com/microsoft/terraform-provider-azuredevops/version"
18
21
)
19
22
20
23
// AggregatedClient aggregates all of the underlying clients into a single data
@@ -37,7 +40,7 @@ type AggregatedClient struct {
37
40
}
38
41
39
42
// GetAzdoClient builds and provides a connection to the Azure DevOps API
40
- func GetAzdoClient (azdoPAT string , organizationURL string ) (* AggregatedClient , error ) {
43
+ func GetAzdoClient (azdoPAT string , organizationURL string , tfVersion string ) (* AggregatedClient , error ) {
41
44
ctx := context .Background ()
42
45
43
46
if strings .EqualFold (azdoPAT , "" ) {
@@ -49,6 +52,7 @@ func GetAzdoClient(azdoPAT string, organizationURL string) (*AggregatedClient, e
49
52
}
50
53
51
54
connection := azuredevops .NewPatConnection (organizationURL , azdoPAT )
55
+ setUserAgent (connection , tfVersion )
52
56
53
57
// client for these APIs (includes CRUD for AzDO projects...):
54
58
// https://docs.microsoft.com/en-us/rest/api/azure/devops/core/?view=azure-devops-rest-5.1
@@ -121,3 +125,17 @@ func GetAzdoClient(azdoPAT string, organizationURL string) (*AggregatedClient, e
121
125
log .Printf ("getAzdoClient(): Created core, build, operations, and serviceendpoint clients successfully!" )
122
126
return aggregatedClient , nil
123
127
}
128
+
129
+ // setUserAgent set UserAgent for http headers
130
+ func setUserAgent (connection * azuredevops.Connection , tfVersion string ) {
131
+ tfUserAgent := httpclient .TerraformUserAgent (tfVersion )
132
+ providerUserAgent := fmt .Sprintf ("%s terraform-provider-azuredevops/%s" , tfUserAgent , version .ProviderVersion )
133
+ connection .UserAgent = strings .TrimSpace (fmt .Sprintf ("%s %s" , connection .UserAgent , providerUserAgent ))
134
+
135
+ // append the CloudShell version to the user agent if it exists
136
+ if azureAgent := os .Getenv ("AZURE_HTTP_USER_AGENT" ); azureAgent != "" {
137
+ connection .UserAgent = fmt .Sprintf ("%s %s" , connection .UserAgent , azureAgent )
138
+ }
139
+
140
+ log .Printf ("[DEBUG] AzureRM Client User Agent: %s\n " , connection .UserAgent )
141
+ }
0 commit comments