From a426a1a0b68644d05a6f4735209a7dd0f9aeadf5 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 14 Jul 2021 20:33:35 +0200 Subject: [PATCH] outposts: cleanup UserAgent config for API Client Signed-off-by: Jens Langhammer --- outpost/pkg/ak/api.go | 3 ++- outpost/pkg/ak/api_uag.go | 20 -------------------- outpost/pkg/ldap/instance_bind.go | 3 ++- 3 files changed, 4 insertions(+), 22 deletions(-) delete mode 100644 outpost/pkg/ak/api_uag.go diff --git a/outpost/pkg/ak/api.go b/outpost/pkg/ak/api.go index f39d880f0..46941010b 100644 --- a/outpost/pkg/ak/api.go +++ b/outpost/pkg/ak/api.go @@ -41,10 +41,11 @@ type APIController struct { // NewAPIController initialise new API Controller instance from URL and API token func NewAPIController(akURL url.URL, token string) *APIController { config := api.NewConfiguration() + config.UserAgent = pkg.UserAgent() config.Host = akURL.Host config.Scheme = akURL.Scheme config.HTTPClient = &http.Client{ - Transport: SetUserAgent(GetTLSTransport(), pkg.UserAgent()), + Transport: GetTLSTransport(), } config.AddDefaultHeader("Authorization", fmt.Sprintf("Bearer %s", token)) diff --git a/outpost/pkg/ak/api_uag.go b/outpost/pkg/ak/api_uag.go deleted file mode 100644 index d600abc0f..000000000 --- a/outpost/pkg/ak/api_uag.go +++ /dev/null @@ -1,20 +0,0 @@ -package ak - -import "net/http" - -func SetUserAgent(inner http.RoundTripper, userAgent string) http.RoundTripper { - return &addUGA{ - inner: inner, - Agent: userAgent, - } -} - -type addUGA struct { - inner http.RoundTripper - Agent string -} - -func (ug *addUGA) RoundTrip(r *http.Request) (*http.Response, error) { - r.Header.Set("User-Agent", ug.Agent) - return ug.inner.RoundTrip(r) -} diff --git a/outpost/pkg/ldap/instance_bind.go b/outpost/pkg/ldap/instance_bind.go index 1df592ac5..b145d0958 100644 --- a/outpost/pkg/ldap/instance_bind.go +++ b/outpost/pkg/ldap/instance_bind.go @@ -54,9 +54,10 @@ func (pi *ProviderInstance) Bind(username string, bindDN, bindPW string, conn ne config := api.NewConfiguration() config.Host = pi.s.ac.Client.GetConfig().Host config.Scheme = pi.s.ac.Client.GetConfig().Scheme + config.UserAgent = pkg.UserAgent() config.HTTPClient = &http.Client{ Jar: jar, - Transport: newTransport(ak.SetUserAgent(ak.GetTLSTransport(), pkg.UserAgent()), map[string]string{ + Transport: newTransport(ak.GetTLSTransport(), map[string]string{ "X-authentik-remote-ip": host, }), }