Skip to content

Commit

Permalink
aeon: added the ability to connect from the config
Browse files Browse the repository at this point in the history
Closes #TNTP-1073
  • Loading branch information
AlexandrLitkevich committed Jan 31, 2025
1 parent f13b13e commit 5a3a88e
Show file tree
Hide file tree
Showing 2 changed files with 51 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

}
52 changes: 50 additions & 2 deletions cli/cmd/aeon.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package cmd

import (
"encoding/json"

Check failure on line 4 in cli/cmd/aeon.go

View workflow job for this annotation

GitHub Actions / tests-ce (1.10)

"encoding/json" imported and not used

Check failure on line 4 in cli/cmd/aeon.go

View workflow job for this annotation

GitHub Actions / tests-ee (2.11.2-0-r609.linux.x86_64)

"encoding/json" imported and not used

Check failure on line 4 in cli/cmd/aeon.go

View workflow job for this annotation

GitHub Actions / tests-ce (2.10)

"encoding/json" imported and not used

Check failure on line 4 in cli/cmd/aeon.go

View workflow job for this annotation

GitHub Actions / tests-ee (3.2.0-0-r40.linux.x86_64)

"encoding/json" imported and not used

Check failure on line 4 in cli/cmd/aeon.go

View workflow job for this annotation

GitHub Actions / tests-ce (3.0)

"encoding/json" imported and not used
"errors"
"fmt"
"os"
"path/filepath"
"regexp"

"github.com/spf13/cobra"
aeon "github.com/tarantool/tt/cli/aeon"
Expand All @@ -12,6 +15,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 +28,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 +50,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 +91,44 @@ 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
}

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{"roles_cfg", "aeon.grpc", "advertise", "uri"}
uri, err := result.Get(path)
if err != nil {
return err
}

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

re := regexp.MustCompile("^https?://")
cleanedURL := re.ReplaceAllString(us, "")

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

}

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

0 comments on commit 5a3a88e

Please sign in to comment.