Skip to content

Commit

Permalink
internal: Update CLI not to set the Circle-Token header when there …
Browse files Browse the repository at this point in the history
…is no token present
  • Loading branch information
rlegan committed Apr 12, 2023
1 parent 29170d6 commit abdc119
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion api/context_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion api/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion api/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion api/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion api/schedule_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit abdc119

Please sign in to comment.