Skip to content
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

Assigns Viridian as the default coordinator for cloud invocations [API-1556] #145

Merged
merged 4 commits into from
Sep 28, 2022
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
2 changes: 1 addition & 1 deletion rootcmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func assignPersistentFlags(cmd *cobra.Command, flags *config.GlobalFlagValues) {
cmd.PersistentFlags().StringVarP(&flags.CfgFile, "config", "c", config.DefaultConfigPath(), fmt.Sprintf("config file, only supports yaml for now"))
cmd.PersistentFlags().StringVarP(&flags.Address, "address", "a", "", fmt.Sprintf("addresses of the instances in the cluster (default is %s)", config.DefaultClusterAddress))
cmd.PersistentFlags().StringVar(&flags.Cluster, "cluster-name", "", fmt.Sprintf("name of the cluster that contains the instances (default is %s)", config.DefaultClusterName))
cmd.PersistentFlags().StringVar(&flags.Token, "cloud-token", "", "your Hazelcast Cloud token")
cmd.PersistentFlags().StringVar(&flags.Token, "cloud-token", "", "your Hazelcast Viridian token")
cmd.PersistentFlags().BoolVar(&flags.Verbose, "verbose", false, "verbose output")
cmd.PersistentFlags().BoolVar(&flags.NoColor, "no-color", false, "disable colors")
cmd.PersistentFlags().BoolVar(&flags.NoAutocompletion, "no-completion", false, "disable completion [interactive mode]")
Expand Down
25 changes: 23 additions & 2 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ import (
"github.com/hazelcast/hazelcast-commandline-client/types/mapcmd"
)

const (
ViridianCoordinatorURL = "https://api.viridian.hazelcast.com"
EnvHzCloudCoordinatorBaseURL = "HZ_CLOUD_COORDINATOR_BASE_URL"
)

func IsInteractiveCall(rootCmd *cobra.Command, args []string) bool {
cmd, flags, err := rootCmd.Find(args)
if err != nil {
Expand Down Expand Up @@ -120,8 +125,24 @@ func updateConfigWithFlags(rootCmd *cobra.Command, cnfg *config.Config, programA
// fall back to cmd.Help, even if there is error
_ = subCmd.ParseFlags(flags)
// initialize config from file
err := config.ReadAndMergeWithFlags(globalFlagValues, cnfg)
return err
if err := config.ReadAndMergeWithFlags(globalFlagValues, cnfg); err != nil {
return err
}
if cnfg.Hazelcast.Cluster.Cloud.Enabled {
return setDefaultCoordinator()
}
return nil
}

func setDefaultCoordinator() error {
if os.Getenv(EnvHzCloudCoordinatorBaseURL) != "" {
return nil
}
// if not set assign Viridian
if err := os.Setenv(EnvHzCloudCoordinatorBaseURL, ViridianCoordinatorURL); err != nil {
return hzcerrors.NewLoggableError(err, "Can not assign Viridian as the default coordinator")
}
return nil
}

func HandleError(err error) string {
Expand Down