TUN-3284: Use cloudflared/<version> as user agent of tunnelstore client
This commit is contained in:
parent
00d6ab2eb7
commit
22d771b51d
|
@ -54,7 +54,8 @@ func (sc *subcommandContext) client() (tunnelstore.Client, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
client, err := tunnelstore.NewRESTClient(sc.c.String("api-url"), credential.cert.AccountID, credential.cert.ZoneID, credential.cert.ServiceKey, sc.logger)
|
userAgent := fmt.Sprintf("cloudflared/%s", version)
|
||||||
|
client, err := tunnelstore.NewRESTClient(sc.c.String("api-url"), credential.cert.AccountID, credential.cert.ZoneID, credential.cert.ServiceKey, userAgent, sc.logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,7 @@ type Client interface {
|
||||||
type RESTClient struct {
|
type RESTClient struct {
|
||||||
baseEndpoints *baseEndpoints
|
baseEndpoints *baseEndpoints
|
||||||
authToken string
|
authToken string
|
||||||
|
userAgent string
|
||||||
client http.Client
|
client http.Client
|
||||||
logger logger.Service
|
logger logger.Service
|
||||||
}
|
}
|
||||||
|
@ -136,7 +137,7 @@ type baseEndpoints struct {
|
||||||
|
|
||||||
var _ Client = (*RESTClient)(nil)
|
var _ Client = (*RESTClient)(nil)
|
||||||
|
|
||||||
func NewRESTClient(baseURL string, accountTag, zoneTag string, authToken string, logger logger.Service) (*RESTClient, error) {
|
func NewRESTClient(baseURL, accountTag, zoneTag, authToken, userAgent string, logger logger.Service) (*RESTClient, error) {
|
||||||
if strings.HasSuffix(baseURL, "/") {
|
if strings.HasSuffix(baseURL, "/") {
|
||||||
baseURL = baseURL[:len(baseURL)-1]
|
baseURL = baseURL[:len(baseURL)-1]
|
||||||
}
|
}
|
||||||
|
@ -154,6 +155,7 @@ func NewRESTClient(baseURL string, accountTag, zoneTag string, authToken string,
|
||||||
zoneLevel: *zoneLevelEndpoint,
|
zoneLevel: *zoneLevelEndpoint,
|
||||||
},
|
},
|
||||||
authToken: authToken,
|
authToken: authToken,
|
||||||
|
userAgent: userAgent,
|
||||||
client: http.Client{
|
client: http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
TLSHandshakeTimeout: defaultTimeout,
|
TLSHandshakeTimeout: defaultTimeout,
|
||||||
|
@ -284,6 +286,7 @@ func (r *RESTClient) sendRequest(method string, url url.URL, body interface{}) (
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "can't create %s request", method)
|
return nil, errors.Wrapf(err, "can't create %s request", method)
|
||||||
}
|
}
|
||||||
|
req.Header.Set("User-Agent", r.userAgent)
|
||||||
if bodyReader != nil {
|
if bodyReader != nil {
|
||||||
req.Header.Set("Content-Type", jsonContentType)
|
req.Header.Set("Content-Type", jsonContentType)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue