From e36fa4661e7452f9e97fad16d4636ba181cda3ba Mon Sep 17 00:00:00 2001 From: Satyam Singh Date: Wed, 18 Oct 2023 13:56:49 +0530 Subject: [PATCH] Fetch grpc url using about api --- cmd/about.go | 1 + cmd/tail.go | 12 ++++++++++-- pkg/config/config.go | 7 +++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/about.go b/cmd/about.go index 60b428b..ff0670d 100644 --- a/cmd/about.go +++ b/cmd/about.go @@ -30,6 +30,7 @@ type About struct { Mode string `json:"mode"` Staging string `json:"staging"` Store string `json:"store"` + GrpcPort uint16 `json:"grpcPort"` UpdateAvailable bool `json:"updateAvailable"` Version string `json:"version"` } diff --git a/cmd/tail.go b/cmd/tail.go index 9da2e67..cc5e387 100644 --- a/cmd/tail.go +++ b/cmd/tail.go @@ -22,7 +22,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "pb/pkg/config" "github.com/apache/arrow/go/v13/arrow/array" @@ -52,7 +51,16 @@ func tail(profile config.Profile, stream string) error { }{ Stream: stream, }) - client, err := flight.NewClientWithMiddleware("localhost:8001", nil, nil, grpc.WithTransportCredentials(insecure.NewCredentials())) + + // get grpc url for this request + httpClient := DefaultClient() + about, err := FetchAbout(&httpClient) + if err != nil { + return err + } + url := profile.GrpcAddr(fmt.Sprint(about.GrpcPort)) + + client, err := flight.NewClientWithMiddleware(url, nil, nil, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return err } diff --git a/pkg/config/config.go b/pkg/config/config.go index b90ec0c..bb49b33 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -18,6 +18,8 @@ package config import ( "fmt" + "net" + "net/url" "os" path "path/filepath" @@ -51,6 +53,11 @@ type Profile struct { Password string } +func (p *Profile) GrpcAddr(port string) string { + urlv, _ := url.Parse(p.URL) + return net.JoinHostPort(urlv.Hostname(), port) +} + // WriteConfigToFile writes the configuration to the config file func WriteConfigToFile(config *Config) error { tomlData, _ := toml.Marshal(config)