Skip to content

Add internal grpc connection #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions cmd/other/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,27 @@ var settingInitProxyCmd = &cobra.Command{
endpointStr := args[0]
appFlag, _ := cmd.Flags().GetBool("app")
userFlag, _ := cmd.Flags().GetBool("user")
internalFlag, _ := cmd.Flags().GetBool("internal")

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

// Internal flag can only be used with --app flag
if internalFlag && userFlag {
pterm.DefaultBox.WithTitle("Internal Flag Not Allowed").
WithTitleTopCenter().
WithRightPadding(4).
WithLeftPadding(4).
WithBoxStyle(pterm.NewStyle(pterm.FgRed)).
Println("The --internal flag can only be used with the --app flag.\n" +
"Example usage:\n" +
" $ cfctl setting init proxy <URL> --app --internal")
return
}

// Get environment name from user input
result, err := pterm.DefaultInteractiveTextInput.
WithDefaultText("default").
Expand Down Expand Up @@ -254,8 +268,6 @@ var settingInitProxyCmd = &cobra.Command{
}
}

internalFlag, _ := cmd.Flags().GetBool("internal")

// Update configuration
updateSetting(envName, endpointStr, envSuffix, internalFlag)
},
Expand Down
77 changes: 56 additions & 21 deletions pkg/transport/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,33 +674,68 @@ func fetchJSONResponse(config *Config, serviceName string, verb string, resource
if err != nil {
if strings.Contains(err.Error(), "ERROR_AUTHENTICATE_FAILURE") ||
strings.Contains(err.Error(), "Token is invalid or expired") {
// Create a styled error message box
headerBox := pterm.DefaultBox.WithTitle("Authentication Error").
WithTitleTopCenter().
WithRightPadding(4).
WithLeftPadding(4).
WithBoxStyle(pterm.NewStyle(pterm.FgLightRed))

errorExplain := "Your authentication token has expired or is invalid.\n" +
"Please login again to refresh your credentials."
// Check if current environment is app type
if strings.HasSuffix(config.Environment, "-app") {
headerBox := pterm.DefaultBox.WithTitle("App Token Required").
WithTitleTopCenter().
WithRightPadding(4).
WithLeftPadding(4).
WithBoxStyle(pterm.NewStyle(pterm.FgLightRed))

headerBox.Println(errorExplain)
fmt.Println()
appTokenExplain := "Please create a Domain Admin App in SpaceONE Console.\n" +
"This requires Domain Admin privilege.\n\n" +
"Or Please create a Workspace App in SpaceONE Console.\n" +
"This requires Workspace Owner privilege."

steps := []string{
"1. Run 'cfctl login'",
"2. Enter your credentials when prompted",
"3. Try your command again",
}
headerBox.Println(appTokenExplain)
fmt.Println()

instructionBox := pterm.DefaultBox.WithTitle("Required Steps").
WithTitleTopCenter().
WithRightPadding(4).
WithLeftPadding(4)
steps := []string{
"1. Go to SpaceONE Console",
"2. Navigate to either 'Admin > App Page' or specific 'Workspace > App page'",
"3. Click 'Create' to create your App",
"4. Copy the generated App Token",
fmt.Sprintf("5. Update token in your config file:\n Path: ~/.cfctl/setting.yaml\n Environment: %s", config.Environment),
}

instructionBox.Println(strings.Join(steps, "\n\n"))
instructionBox := pterm.DefaultBox.WithTitle("Required Steps").
WithTitleTopCenter().
WithRightPadding(4).
WithLeftPadding(4)

return nil, fmt.Errorf("authentication required")
instructionBox.Println(strings.Join(steps, "\n\n"))

return nil, fmt.Errorf("app token required")
} else {
// Original user authentication error message
headerBox := pterm.DefaultBox.WithTitle("Authentication Error").
WithTitleTopCenter().
WithRightPadding(4).
WithLeftPadding(4).
WithBoxStyle(pterm.NewStyle(pterm.FgLightRed))

errorExplain := "Your authentication token has expired or is invalid.\n" +
"Please login again to refresh your credentials."

headerBox.Println(errorExplain)
fmt.Println()

steps := []string{
"1. Run 'cfctl login'",
"2. Enter your credentials when prompted",
"3. Try your command again",
}

instructionBox := pterm.DefaultBox.WithTitle("Required Steps").
WithTitleTopCenter().
WithRightPadding(4).
WithLeftPadding(4)

instructionBox.Println(strings.Join(steps, "\n\n"))

return nil, fmt.Errorf("authentication required")
}
}
return nil, fmt.Errorf("failed to invoke method %s: %v", fullMethod, err)
}
Expand Down
Loading