@@ -71,10 +71,10 @@ type request struct {
7171
7272// ClientOpts encapsulates the options given to NewClient.
7373type ClientOpts struct {
74- EndpointURL * url.URL
75- AccessToken string
76- AdditionalHeaders map [string ]string
77- RequireAccessToken bool
74+ EndpointURL * url.URL
75+ AccessToken string
76+ AdditionalHeaders map [string ]string
77+ RequireAccessTokenInCI bool
7878
7979 // Flags are the standard API client flags provided by NewFlags. If nil,
8080 // default values will be used.
@@ -139,20 +139,20 @@ func NewClient(opts ClientOpts) Client {
139139
140140 return & client {
141141 opts : ClientOpts {
142- EndpointURL : opts .EndpointURL ,
143- AccessToken : opts .AccessToken ,
144- AdditionalHeaders : opts .AdditionalHeaders ,
145- RequireAccessToken : opts .RequireAccessToken ,
146- Flags : flags ,
147- Out : opts .Out ,
142+ EndpointURL : opts .EndpointURL ,
143+ AccessToken : opts .AccessToken ,
144+ AdditionalHeaders : opts .AdditionalHeaders ,
145+ RequireAccessTokenInCI : opts .RequireAccessTokenInCI ,
146+ Flags : flags ,
147+ Out : opts .Out ,
148148 },
149149 httpClient : httpClient ,
150150 }
151151}
152152
153- func (c * client ) requireAccessToken () error {
154- if c .opts .RequireAccessToken && c .opts .AccessToken == "" {
155- return fmt .Errorf ("SRC_ACCESS_TOKEN must be set in CI" )
153+ func (c * client ) checkIfCIAccessTokenRequired () error {
154+ if c .opts .RequireAccessTokenInCI && c .opts .AccessToken == "" {
155+ return fmt .Errorf ("CI is true and no SRC_ACCESS_TOKEN is set. When running in CI OAuth tokens cannot be used, only SRC_ACCESS_TOKEN. Either set CI=false or define a SRC_ACCESS_TOKEN " )
156156 }
157157
158158 return nil
@@ -183,7 +183,7 @@ func (c *client) NewHTTPRequest(ctx context.Context, method, p string, body io.R
183183}
184184
185185func (c * client ) createHTTPRequest (ctx context.Context , method , p string , body io.Reader ) (* http.Request , error ) {
186- if err := c .requireAccessToken (); err != nil {
186+ if err := c .checkIfCIAccessTokenRequired (); err != nil {
187187 return nil , err
188188 }
189189
@@ -216,7 +216,7 @@ func (c *client) createHTTPRequest(ctx context.Context, method, p string, body i
216216}
217217
218218func (r * request ) do (ctx context.Context , result any ) (bool , error ) {
219- if err := r .client .requireAccessToken (); err != nil {
219+ if err := r .client .checkIfCIAccessTokenRequired (); err != nil {
220220 return false , err
221221 }
222222
0 commit comments