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

aeon: added the ability to connect from the config #1094

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
52 changes: 49 additions & 3 deletions cli/cmd/aeon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package cmd
import (
"errors"
"fmt"
"os"
"path/filepath"
"regexp"

"github.com/spf13/cobra"
aeon "github.com/tarantool/tt/cli/aeon"
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,13 +27,17 @@ var connectCtx = aeoncmd.ConnectCtx{
Transport: aeoncmd.TransportPlain,
}

var configPath string
var instance string

func newAeonConnectCmd() *cobra.Command {
var aeonCmd = &cobra.Command{
Use: "connect URI",
Short: "Connect to the aeon instance",
Long: `Connect to the aeon instance.
tt aeon connect localhost:50051
tt aeon connect unix://<socket-path>`,
tt aeon connect unix://<socket-path>
tt aeon connect -c path instanceName>`,
Copy link
Contributor

@patapenka-alexey patapenka-alexey Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tt aeon connect -c path instanceName>`,
tt aeon connect -c /path/to/config -i INSTANCE_NAME`,

To correlate with tt connect/play help style.

PreRunE: func(cmd *cobra.Command, args []string) error {
err := aeonConnectValidateArgs(cmd, args)
util.HandleCmdErr(cmd, err)
Expand All @@ -42,14 +49,16 @@ tt aeon connect unix://<socket-path>`,
internalAeonConnect, args)
util.HandleCmdErr(cmd, err)
},
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 +89,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("it is impossible to result in a string")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("it is impossible to result in a string")
return errors.New("it is impossible to cast result in a 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
5 changes: 0 additions & 5 deletions test/integration/aeon/test_aeon.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ def test_cli_ssl_arguments_success(tt_cmd, aeon_ssl, certificates):
@pytest.mark.parametrize(
"args, error",
[
((), "Error: accepts 1 arg(s), received 0"),
(
("localhost:50051", "@aeon_unix_socket"),
"Error: accepts 1 arg(s), received 2",
),
(
(
"--transport",
Expand Down