TUN-6459: Add cloudflared user-agent to access calls

This commit is contained in:
Devin Carr
2022-06-24 11:51:53 -07:00
parent b849def673
commit 2e2718b7e3
4 changed files with 23 additions and 4 deletions

View File

@@ -29,6 +29,10 @@ const (
AccessLoginWorkerPath = "/cdn-cgi/access/login"
)
var (
userAgent = "DEV"
)
type AppInfo struct {
AuthDomain string
AppAUD string
@@ -144,6 +148,10 @@ func isTokenLocked(lockFilePath string) bool {
return exists && err == nil
}
func Init(version string) {
userAgent = fmt.Sprintf("cloudflared/%s", version)
}
// FetchTokenWithRedirect will either load a stored token or generate a new one
// it appends the full url as the redirect URL to the access cli request if opening the browser
func FetchTokenWithRedirect(appURL *url.URL, appInfo *AppInfo, log *zerolog.Logger) (string, error) {
@@ -261,6 +269,7 @@ func GetAppInfo(reqURL *url.URL) (*AppInfo, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to create app info request")
}
appInfoReq.Header.Add("User-Agent", userAgent)
resp, err := client.Do(appInfoReq)
if err != nil {
return nil, errors.Wrap(err, "failed to get app info")
@@ -311,6 +320,7 @@ func exchangeOrgToken(appURL *url.URL, orgToken string) (string, error) {
if err != nil {
return "", errors.Wrap(err, "failed to create app token request")
}
appTokenRequest.Header.Add("User-Agent", userAgent)
resp, err := client.Do(appTokenRequest)
if err != nil {
return "", errors.Wrap(err, "failed to get app token")