@@ -207,6 +207,12 @@ func Exec(data *global.Data) error {
207
207
displayAPIEndpoint (apiEndpoint , endpointSource , data .Output )
208
208
}
209
209
210
+ // User can set env.DebugMode env var or the --debug-mode boolean flag.
211
+ // This will prioritise the flag over the env var.
212
+ if data .Flags .Debug {
213
+ data .Env .DebugMode = "true"
214
+ }
215
+
210
216
// NOTE: Some commands need just the auth server to be running.
211
217
// But not necessarily need to process an existing token.
212
218
// e.g. `profile create example_sso_user --sso`
@@ -334,7 +340,7 @@ func processToken(cmds []argparser.Command, data *global.Data) (token string, to
334
340
// So we have to presume those overrides are using a long-lived token.
335
341
switch tokenSource {
336
342
case lookup .SourceFile :
337
- profileName , profileData , err := getProfile ( data )
343
+ profileName , profileData , err := data . Profile ( )
338
344
if err != nil {
339
345
return "" , tokenSource , err
340
346
}
@@ -344,7 +350,7 @@ func processToken(cmds []argparser.Command, data *global.Data) (token string, to
344
350
}
345
351
// User now either has an existing SSO-based token or they want to migrate.
346
352
// If a long-lived token, then trigger SSO.
347
- if longLivedToken (profileData ) {
353
+ if auth . IsLongLivedToken (profileData ) {
348
354
return ssoAuthentication ("You've not authenticated via OAuth before" , cmds , data )
349
355
}
350
356
// Otherwise, for an existing SSO token, check its freshness.
@@ -373,39 +379,6 @@ func processToken(cmds []argparser.Command, data *global.Data) (token string, to
373
379
return token , tokenSource , nil
374
380
}
375
381
376
- // getProfile identifies the profile we should extract a token from.
377
- func getProfile (data * global.Data ) (string , * config.Profile , error ) {
378
- var (
379
- profileData * config.Profile
380
- found bool
381
- name , profileName string
382
- )
383
- switch {
384
- case data .Flags .Profile != "" : // --profile
385
- profileName = data .Flags .Profile
386
- case data .Manifest .File .Profile != "" : // `profile` field in fastly.toml
387
- profileName = data .Manifest .File .Profile
388
- default :
389
- profileName = "default"
390
- }
391
- for name , profileData = range data .Config .Profiles {
392
- if (profileName == "default" && profileData .Default ) || name == profileName {
393
- // Once we find the default profile we can update the variable to be the
394
- // associated profile name so later on we can use that information to
395
- // update the specific profile.
396
- if profileName == "default" {
397
- profileName = name
398
- }
399
- found = true
400
- break
401
- }
402
- }
403
- if ! found {
404
- return "" , nil , fmt .Errorf ("failed to locate '%s' profile" , profileName )
405
- }
406
- return profileName , profileData , nil
407
- }
408
-
409
382
// checkAndRefreshSSOToken refreshes the access/refresh tokens if expired.
410
383
func checkAndRefreshSSOToken (profileData * config.Profile , profileName string , data * global.Data ) (reauth bool , err error ) {
411
384
// Access Token has expired
@@ -483,7 +456,7 @@ func checkAndRefreshSSOToken(profileData *config.Profile, profileName string, da
483
456
// informs the user how they can use the SSO flow. It checks if the SSO
484
457
// environment variable (or flag) has been set and enables the SSO flow if so.
485
458
func shouldSkipSSO (_ string , profileData * config.Profile , data * global.Data ) bool {
486
- if longLivedToken (profileData ) {
459
+ if auth . IsLongLivedToken (profileData ) {
487
460
// Skip SSO if user hasn't indicated they want to migrate.
488
461
return data .Env .UseSSO != "1" && ! data .Flags .SSO
489
462
// FIXME: Put back messaging once SSO is GA.
@@ -501,11 +474,6 @@ func shouldSkipSSO(_ string, profileData *config.Profile, data *global.Data) boo
501
474
return false // don't skip SSO
502
475
}
503
476
504
- func longLivedToken (pd * config.Profile ) bool {
505
- // If user has followed SSO flow before, then these will not be zero values.
506
- return pd .AccessToken == "" && pd .RefreshToken == "" && pd .AccessTokenCreated == 0 && pd .RefreshTokenCreated == 0
507
- }
508
-
509
477
// ssoAuthentication executes the `sso` command to handle authentication.
510
478
func ssoAuthentication (outputMessage string , cmds []argparser.Command , data * global.Data ) (token string , tokenSource lookup.Source , err error ) {
511
479
for _ , command := range cmds {
@@ -643,7 +611,11 @@ func commandCollectsData(command string) bool {
643
611
// commandRequiresAuthServer determines if the command to be executed is one that
644
612
// requires just the authentication server to be running.
645
613
func commandRequiresAuthServer (command string ) bool {
646
- return command == "profile create"
614
+ switch command {
615
+ case "profile create" , "profile update" :
616
+ return true
617
+ }
618
+ return false
647
619
}
648
620
649
621
// commandRequiresToken determines if the command to be executed is one that
@@ -675,7 +647,7 @@ func configureAuth(apiEndpoint string, args []string, f config.File, c api.HTTPC
675
647
676
648
resp , err := c .Do (req )
677
649
if err != nil {
678
- return nil , fmt .Errorf ("failed to request OpenID Connect .well-known metadata: %w" , err )
650
+ return nil , fmt .Errorf ("failed to request OpenID Connect .well-known metadata (%s) : %w" , metadataEndpoint , err )
679
651
}
680
652
681
653
openIDConfig , err := io .ReadAll (resp .Body )
0 commit comments