Skip to content

Commit

Permalink
aeon:added the ability to connect from the config Closes #TNTP-1073
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrLitkevich committed Jan 30, 2025
1 parent f13b13e commit 2a018f4
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions cli/aeon/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ type ConnectCtx struct {
Network string
// Address is a connection URL, unix socket address and etc.
Address string

}
85 changes: 83 additions & 2 deletions cli/cmd/aeon.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cmd

import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
Expand All @@ -12,6 +14,7 @@ import (
"github.com/tarantool/tt/cli/console"
"github.com/tarantool/tt/cli/modules"
"github.com/tarantool/tt/cli/util"
"github.com/tarantool/tt/lib/cluster"
libconnect "github.com/tarantool/tt/lib/connect"
)

Expand All @@ -24,6 +27,10 @@ var connectCtx = aeoncmd.ConnectCtx{
Transport: aeoncmd.TransportPlain,
}

// Определяем переменные для флагов
var configPath string
var instance string

func newAeonConnectCmd() *cobra.Command {
var aeonCmd = &cobra.Command{
Use: "connect URI",
Expand All @@ -42,14 +49,17 @@ tt aeon connect unix://<socket-path>`,
internalAeonConnect, args)
util.HandleCmdErr(cmd, err)
},
Args: cobra.ExactArgs(1),
// Args: cobra.ExactArgs(1),
}

aeonCmd.Flags().StringVar(&connectCtx.Ssl.KeyFile, "sslkeyfile", "",
"path to a private SSL key file")
aeonCmd.Flags().StringVar(&connectCtx.Ssl.CertFile, "sslcertfile", "",
"path to a SSL certificate file")
aeonCmd.Flags().StringVar(&connectCtx.Ssl.CaFile, "sslcafile", "",
"path to a trusted certificate authorities (CA) file")
aeonCmd.Flags().StringVarP(&configPath, "config", "c", "", "path config")
aeonCmd.Flags().StringVarP(&instance, "instanceName", "i", "", "instance name")

aeonCmd.Flags().Var(&connectCtx.Transport, "transport",
fmt.Sprintf("allowed %s", aeoncmd.ListValidTransports()))
Expand Down Expand Up @@ -80,7 +90,78 @@ func NewAeonCmd() *cobra.Command {
}

func aeonConnectValidateArgs(cmd *cobra.Command, args []string) error {
connectCtx.Network, connectCtx.Address = libconnect.ParseBaseURI(args[0])
if len(args) != 0 {
connectCtx.Network, connectCtx.Address = libconnect.ParseBaseURI(args[0])
} else if cmd.Flags().Changed("config") && cmd.Flags().Changed("instanceName") {
f, err := os.ReadFile(configPath)
if err != nil {
return err
}

var data map[string]interface{}
json.Unmarshal([]byte(f), &data)

pb := cluster.NewYamlCollector(f)
config, err := pb.Collect()
if err != nil {
return err
}

clusterConfig, err := cluster.MakeClusterConfig(config)
if err != nil {
return err
}

result := cluster.Instantiate(clusterConfig, instance)

path := []string{"iproto", "listen"}
lconfig, err := result.Get(path)
if err != nil {
return err
}

d, ok := lconfig.([]any)
if !ok {
return fmt.Errorf("fail convert slice uri")
}

fmt.Println("THIS d", d)
fmt.Println("THIS d[0]", d[0])

if len(d) == 0 {
return fmt.Errorf("the connection URI could not be found in the specified configuration file")
}

fmt.Println("d[0]", d[0])

c, ok := d[0].(map[any]any)
if !ok {
return fmt.Errorf("fail convert map")
}

uri, ok := c["uri"]
if !ok {
return fmt.Errorf("fail to get uri ")
}

us, ok := uri.(string)
if !ok {
return fmt.Errorf("fail to conver string")
}

connectCtx.Network, connectCtx.Address = libconnect.ParseBaseURI(us)

fmt.Println("URI", lconfig)

//парсим кофиг
}

path, err := cmd.Flags().GetString("config")
if err != nil {
return err
}
fmt.Println("PATH CONFIG", path)
fmt.Println("VAR configPath", configPath)

if !cmd.Flags().Changed("transport") && (connectCtx.Ssl.KeyFile != "" ||
connectCtx.Ssl.CertFile != "" || connectCtx.Ssl.CaFile != "") {
Expand Down

0 comments on commit 2a018f4

Please sign in to comment.