From abdc119bbd5963d7ed2a2acbfb3ffb187e6f57ca Mon Sep 17 00:00:00 2001 From: rlegan Date: Wed, 12 Apr 2023 11:30:22 +0200 Subject: [PATCH] internal: Update CLI not to set the `Circle-Token` header when there is no token present --- api/api.go | 4 +++- api/context_rest.go | 4 +++- api/info/info.go | 4 +++- api/policy/policy.go | 4 +++- api/rest/client.go | 4 +++- api/schedule_rest.go | 4 +++- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/api/api.go b/api/api.go index 3ea130e0d..ac29d7c1f 100644 --- a/api/api.go +++ b/api/api.go @@ -1834,7 +1834,9 @@ func FollowProject(config settings.Config, vcs string, owner string, projectName } r.Header.Set("Content-Type", "application/json; charset=utf-8") r.Header.Set("Accept", "application/json; charset=utf-8") - r.Header.Set("Circle-Token", config.Token) + if config.Token != "" { + r.Header.Set("Circle-Token", config.Token) + } response, err := config.HTTPClient.Do(r) if err != nil { diff --git a/api/context_rest.go b/api/context_rest.go index ce484ea7c..17b2ff21d 100644 --- a/api/context_rest.go +++ b/api/context_rest.go @@ -544,7 +544,9 @@ func (c *ContextRestClient) newHTTPRequest(method, url string, body io.Reader) ( if err != nil { return nil, err } - req.Header.Add("circle-token", c.token) + if c.token != "" { + req.Header.Add("circle-token", c.token) + } req.Header.Add("Accept", "application/json") req.Header.Add("Content-Type", "application/json") req.Header.Add("User-Agent", version.UserAgent()) diff --git a/api/info/info.go b/api/info/info.go index df1c79455..d8feb74e4 100644 --- a/api/info/info.go +++ b/api/info/info.go @@ -86,7 +86,9 @@ func (c *InfoRESTClient) newHTTPRequest(method, url string, body io.Reader) (*ht if err != nil { return nil, err } - req.Header.Add("circle-token", c.token) + if c.token != "" { + req.Header.Add("circle-token", c.token) + } req.Header.Add("Accept", "application/json") req.Header.Add("Content-Type", "application/json") req.Header.Add("User-Agent", version.UserAgent()) diff --git a/api/policy/policy.go b/api/policy/policy.go index 605d31558..19babab9a 100644 --- a/api/policy/policy.go +++ b/api/policy/policy.go @@ -341,7 +341,9 @@ func NewClient(baseURL string, config *settings.Config) *Client { // releasing the semaphore after a second ensuring client doesn't make more than cap(sem)/second time.AfterFunc(time.Second, func() { <-sem }) - r.Header.Add("circle-token", config.Token) + if config.Token != "" { + r.Header.Add("circle-token", config.Token) + } r.Header.Add("Accept", "application/json") r.Header.Add("Content-Type", "application/json") r.Header.Add("User-Agent", version.UserAgent()) diff --git a/api/rest/client.go b/api/rest/client.go index 219363301..93a89ac9b 100644 --- a/api/rest/client.go +++ b/api/rest/client.go @@ -70,7 +70,9 @@ func (c *Client) NewRequest(method string, u *url.URL, payload interface{}) (req } func (c *Client) enrichRequestHeaders(req *http.Request, payload interface{}) { - req.Header.Set("Circle-Token", c.circleToken) + if c.circleToken != "" { + req.Header.Set("Circle-Token", c.circleToken) + } req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", version.UserAgent()) commandStr := header.GetCommandStr() diff --git a/api/schedule_rest.go b/api/schedule_rest.go index c422b66a0..efa8fac5c 100644 --- a/api/schedule_rest.go +++ b/api/schedule_rest.go @@ -402,7 +402,9 @@ func (c *ScheduleRestClient) newHTTPRequest(method, url string, body io.Reader) if err != nil { return nil, err } - req.Header.Add("circle-token", c.token) + if c.token != "" { + req.Header.Add("circle-token", c.token) + } req.Header.Add("Accept", "application/json") req.Header.Add("Content-Type", "application/json") req.Header.Add("User-Agent", version.UserAgent())