From 38ee95ccf2a155c6afa6c95cbef9db5bb170a191 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 11 Jul 2022 10:21:28 +0200 Subject: [PATCH] [skip-changelog] Try to whitelist CI for Cloudflare spam-check filters (#1796) * Provide a way to define extra UserAgent fields via env vars * Add secret token to User Agent This will allow to possibly bypass spam-checks on the server side reducing the jobs failures due to rate limiting. --- .github/workflows/test-go-integration-task.yml | 3 +++ configuration/network.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-go-integration-task.yml b/.github/workflows/test-go-integration-task.yml index f9de83c5b74..aea78ced81c 100644 --- a/.github/workflows/test-go-integration-task.yml +++ b/.github/workflows/test-go-integration-task.yml @@ -84,6 +84,9 @@ jobs: runs-on: ${{ matrix.operating-system }} + env: + ARDUINO_CLI_USER_AGENT_EXTENSION: ${{ secrets.CLOUDFLARE_SPAMCHECK_BYPASS_TOKEN }} + steps: # By default, actions/checkout converts the repo's LF line endings to CRLF on the Windows runner. - name: Disable EOL conversions diff --git a/configuration/network.go b/configuration/network.go index 04d6bb98985..e2e81d937bb 100644 --- a/configuration/network.go +++ b/configuration/network.go @@ -18,6 +18,7 @@ package configuration import ( "fmt" "net/url" + "os" "runtime" "github.com/arduino/arduino-cli/cli/globals" @@ -34,12 +35,18 @@ func UserAgent(settings *viper.Viper) string { subComponent = " " + subComponent } - return fmt.Sprintf("%s/%s%s (%s; %s; %s) Commit:%s", + extendedUA := os.Getenv("ARDUINO_CLI_USER_AGENT_EXTENSION") + if extendedUA != "" { + extendedUA = " " + extendedUA + } + + return fmt.Sprintf("%s/%s%s (%s; %s; %s) Commit:%s%s", globals.VersionInfo.Application, globals.VersionInfo.VersionString, subComponent, runtime.GOARCH, runtime.GOOS, runtime.Version(), - globals.VersionInfo.Commit) + globals.VersionInfo.Commit, + extendedUA) } // NetworkProxy returns the proxy configuration (mainly used by HTTP clients)