@@ -674,33 +674,68 @@ func fetchJSONResponse(config *Config, serviceName string, verb string, resource
674
674
if err != nil {
675
675
if strings .Contains (err .Error (), "ERROR_AUTHENTICATE_FAILURE" ) ||
676
676
strings .Contains (err .Error (), "Token is invalid or expired" ) {
677
- // Create a styled error message box
678
- headerBox := pterm .DefaultBox .WithTitle ("Authentication Error" ).
679
- WithTitleTopCenter ().
680
- WithRightPadding (4 ).
681
- WithLeftPadding (4 ).
682
- WithBoxStyle (pterm .NewStyle (pterm .FgLightRed ))
683
677
684
- errorExplain := "Your authentication token has expired or is invalid.\n " +
685
- "Please login again to refresh your credentials."
678
+ // Check if current environment is app type
679
+ if strings .HasSuffix (config .Environment , "-app" ) {
680
+ headerBox := pterm .DefaultBox .WithTitle ("App Token Required" ).
681
+ WithTitleTopCenter ().
682
+ WithRightPadding (4 ).
683
+ WithLeftPadding (4 ).
684
+ WithBoxStyle (pterm .NewStyle (pterm .FgLightRed ))
686
685
687
- headerBox .Println (errorExplain )
688
- fmt .Println ()
686
+ appTokenExplain := "Please create a Domain Admin App in SpaceONE Console.\n " +
687
+ "This requires Domain Admin privilege.\n \n " +
688
+ "Or Please create a Workspace App in SpaceONE Console.\n " +
689
+ "This requires Workspace Owner privilege."
689
690
690
- steps := []string {
691
- "1. Run 'cfctl login'" ,
692
- "2. Enter your credentials when prompted" ,
693
- "3. Try your command again" ,
694
- }
691
+ headerBox .Println (appTokenExplain )
692
+ fmt .Println ()
695
693
696
- instructionBox := pterm .DefaultBox .WithTitle ("Required Steps" ).
697
- WithTitleTopCenter ().
698
- WithRightPadding (4 ).
699
- WithLeftPadding (4 )
694
+ steps := []string {
695
+ "1. Go to SpaceONE Console" ,
696
+ "2. Navigate to either 'Admin > App Page' or specific 'Workspace > App page'" ,
697
+ "3. Click 'Create' to create your App" ,
698
+ "4. Copy the generated App Token" ,
699
+ fmt .Sprintf ("5. Update token in your config file:\n Path: ~/.cfctl/setting.yaml\n Environment: %s" , config .Environment ),
700
+ }
700
701
701
- instructionBox .Println (strings .Join (steps , "\n \n " ))
702
+ instructionBox := pterm .DefaultBox .WithTitle ("Required Steps" ).
703
+ WithTitleTopCenter ().
704
+ WithRightPadding (4 ).
705
+ WithLeftPadding (4 )
702
706
703
- return nil , fmt .Errorf ("authentication required" )
707
+ instructionBox .Println (strings .Join (steps , "\n \n " ))
708
+
709
+ return nil , fmt .Errorf ("app token required" )
710
+ } else {
711
+ // Original user authentication error message
712
+ headerBox := pterm .DefaultBox .WithTitle ("Authentication Error" ).
713
+ WithTitleTopCenter ().
714
+ WithRightPadding (4 ).
715
+ WithLeftPadding (4 ).
716
+ WithBoxStyle (pterm .NewStyle (pterm .FgLightRed ))
717
+
718
+ errorExplain := "Your authentication token has expired or is invalid.\n " +
719
+ "Please login again to refresh your credentials."
720
+
721
+ headerBox .Println (errorExplain )
722
+ fmt .Println ()
723
+
724
+ steps := []string {
725
+ "1. Run 'cfctl login'" ,
726
+ "2. Enter your credentials when prompted" ,
727
+ "3. Try your command again" ,
728
+ }
729
+
730
+ instructionBox := pterm .DefaultBox .WithTitle ("Required Steps" ).
731
+ WithTitleTopCenter ().
732
+ WithRightPadding (4 ).
733
+ WithLeftPadding (4 )
734
+
735
+ instructionBox .Println (strings .Join (steps , "\n \n " ))
736
+
737
+ return nil , fmt .Errorf ("authentication required" )
738
+ }
704
739
}
705
740
return nil , fmt .Errorf ("failed to invoke method %s: %v" , fullMethod , err )
706
741
}
0 commit comments