From a66fb4844980b1d8b7995cea9a690a07d84cf3c5 Mon Sep 17 00:00:00 2001 From: Ikramullah Date: Wed, 21 Aug 2024 11:31:51 +0700 Subject: [PATCH 1/3] feat(client): add feature to delete authentication --- cmd/mdrop-client/auth.go | 33 +++++++++++++++++++++++++++++++++ internal/rw_config_file.go | 15 +++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/cmd/mdrop-client/auth.go b/cmd/mdrop-client/auth.go index a08d67d..d6041da 100644 --- a/cmd/mdrop-client/auth.go +++ b/cmd/mdrop-client/auth.go @@ -23,6 +23,7 @@ func AuthCommand(args []string) { defaultInstance = flag.String("set-default", "", "Set default tunnel instance.") list = flag.Bool("list", false, "Get list of tunnel instance") help = flag.Bool("help", false, "Print this message") + deleteInstance = flag.String("delete", "", "Delete tunnel instance") ) flag.Parse(args) @@ -42,6 +43,11 @@ func AuthCommand(args []string) { os.Exit(0) } + if *deleteInstance != "" { + deleteTunnelInstance(*deleteInstance) + os.Exit(0) + } + // Set prompt config, err := authPrompt() if err != nil { @@ -105,6 +111,33 @@ func getTunnelInstance() { } } +func deleteTunnelInstance(instanceName string) { + var authConfig internal.ConfigSourceAuth + err := authConfig.ParseConfig(&authConfig) + if err != nil { + internal.PrintErrorWithExit("authParseConfig", err, 1) + } + + instanceIndex := -1 + for i, instance := range authConfig.ListConfiguration { + if instance.Name == instanceName { + instanceIndex = i + break + } + } + if instanceIndex < 0 { + internal.PrintErrorWithExit("authInstanceNotFound", errors.New("Instance not found"), 1) + } + authConfig.ListConfiguration = append( + authConfig.ListConfiguration[:instanceIndex], + authConfig.ListConfiguration[instanceIndex+1:]..., + ) + err = authConfig.WriteConfig() + if err != nil { + internal.PrintErrorWithExit("authParseConfig", err, 1) + } +} + func authPrompt() (config internal.ConfigFile, err error) { reader := bufio.NewReader(os.Stdin) stdin := int(syscall.Stdin) diff --git a/internal/rw_config_file.go b/internal/rw_config_file.go index 7d8cea5..b56e6d6 100644 --- a/internal/rw_config_file.go +++ b/internal/rw_config_file.go @@ -72,6 +72,21 @@ func (c ConfigFile) WriteConfig() (err error) { return nil } +func (c ConfigSourceAuth) WriteConfig() (err error) { + strJsonByte, err := json.Marshal(c) + if err != nil { + return err + } + strConfig := base64.StdEncoding.EncodeToString(strJsonByte) + err = os.WriteFile(ConfigFileLocation, []byte(strConfig), 0644) + if err != nil { + return err + } + + fmt.Println("Config file is saved on", ConfigFileLocation) + return nil +} + func (c ConfigSourceAuth) ParseConfig(conf *ConfigSourceAuth) error { if !CheckConfigFileExist() { return errors.New("No config file on local. Please log in first.") From 9b46b2fe8eb2e7fe9b7ef47a44647509d5fadb73 Mon Sep 17 00:00:00 2001 From: Ikramullah Date: Wed, 28 Aug 2024 10:53:23 +0700 Subject: [PATCH 2/3] refactor(shell): change channel output location --- cmd/mdrop-client/shell.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/mdrop-client/shell.go b/cmd/mdrop-client/shell.go index 83683a3..0c347c9 100644 --- a/cmd/mdrop-client/shell.go +++ b/cmd/mdrop-client/shell.go @@ -106,9 +106,9 @@ func StartShellTunnel(s internal.SSHParameter, isTunnel bool) (output string, er } }() + cmd.Wait() output = <-outputChan err = <-errChan - cmd.Wait() return output, err } From 70993113439be954e6487886376622cc40a4524b Mon Sep 17 00:00:00 2001 From: Ikramullah Date: Wed, 28 Aug 2024 10:54:36 +0700 Subject: [PATCH 3/3] Release: v0.3.2-alya --- cmd/mdrop-client/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/mdrop-client/main.go b/cmd/mdrop-client/main.go index cc3011c..b3cd2eb 100644 --- a/cmd/mdrop-client/main.go +++ b/cmd/mdrop-client/main.go @@ -6,7 +6,7 @@ import ( "os" ) -const version string = "v0.3.1-alya" +const version string = "v0.3.2-alya" const subCmdHelpMeesage string = ` Subcommand: