Skip to content

Commit 62b3017

Browse files
authored
Merge pull request #122 from yjinjo/master
Add internal grpc connection
2 parents cb44600 + 298076a commit 62b3017

File tree

2 files changed

+70
-23
lines changed

2 files changed

+70
-23
lines changed

cmd/other/setting.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,27 @@ var settingInitProxyCmd = &cobra.Command{
167167
endpointStr := args[0]
168168
appFlag, _ := cmd.Flags().GetBool("app")
169169
userFlag, _ := cmd.Flags().GetBool("user")
170+
internalFlag, _ := cmd.Flags().GetBool("internal")
170171

171172
if !appFlag && !userFlag {
172173
pterm.Error.Println("You must specify either --app or --user flag.")
173174
cmd.Help()
174175
return
175176
}
176177

178+
// Internal flag can only be used with --app flag
179+
if internalFlag && userFlag {
180+
pterm.DefaultBox.WithTitle("Internal Flag Not Allowed").
181+
WithTitleTopCenter().
182+
WithRightPadding(4).
183+
WithLeftPadding(4).
184+
WithBoxStyle(pterm.NewStyle(pterm.FgRed)).
185+
Println("The --internal flag can only be used with the --app flag.\n" +
186+
"Example usage:\n" +
187+
" $ cfctl setting init proxy <URL> --app --internal")
188+
return
189+
}
190+
177191
// Get environment name from user input
178192
result, err := pterm.DefaultInteractiveTextInput.
179193
WithDefaultText("default").
@@ -254,8 +268,6 @@ var settingInitProxyCmd = &cobra.Command{
254268
}
255269
}
256270

257-
internalFlag, _ := cmd.Flags().GetBool("internal")
258-
259271
// Update configuration
260272
updateSetting(envName, endpointStr, envSuffix, internalFlag)
261273
},

pkg/transport/service.go

+56-21
Original file line numberDiff line numberDiff line change
@@ -674,33 +674,68 @@ func fetchJSONResponse(config *Config, serviceName string, verb string, resource
674674
if err != nil {
675675
if strings.Contains(err.Error(), "ERROR_AUTHENTICATE_FAILURE") ||
676676
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))
683677

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))
686685

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."
689690

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()
695693

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+
}
700701

701-
instructionBox.Println(strings.Join(steps, "\n\n"))
702+
instructionBox := pterm.DefaultBox.WithTitle("Required Steps").
703+
WithTitleTopCenter().
704+
WithRightPadding(4).
705+
WithLeftPadding(4)
702706

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+
}
704739
}
705740
return nil, fmt.Errorf("failed to invoke method %s: %v", fullMethod, err)
706741
}

0 commit comments

Comments
 (0)