mirror of
https://github.com/openziti/zrok.git
synced 2024-11-07 16:54:23 +01:00
version client (#463)
This commit is contained in:
parent
3c310c27db
commit
896125d25d
@ -3,7 +3,7 @@ package agent
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openziti/zrok/agent/grpc"
|
"github.com/openziti/zrok/agent/grpc"
|
||||||
"github.com/prometheus/common/version"
|
"github.com/openziti/zrok/build"
|
||||||
_ "google.golang.org/grpc"
|
_ "google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,5 +12,6 @@ type agentGrpcImpl struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *agentGrpcImpl) Version(ctx context.Context, req *grpc.VersionRequest) (*grpc.VersionReply, error) {
|
func (s *agentGrpcImpl) Version(ctx context.Context, req *grpc.VersionRequest) (*grpc.VersionReply, error) {
|
||||||
return &grpc.VersionReply{V: &version.Version}, nil
|
v := build.String()
|
||||||
|
return &grpc.VersionReply{V: &v}, nil
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ type agentStartCommand struct {
|
|||||||
func newAgentStartCommand() *agentStartCommand {
|
func newAgentStartCommand() *agentStartCommand {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "start",
|
Use: "start",
|
||||||
Short: "Launch a zrok agent",
|
Short: "Start a zrok agent",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
}
|
}
|
||||||
command := &agentStartCommand{cmd: cmd}
|
command := &agentStartCommand{cmd: cmd}
|
56
cmd/zrok/agentVersion.go
Normal file
56
cmd/zrok/agentVersion.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
grpc2 "github.com/openziti/zrok/agent/grpc"
|
||||||
|
"github.com/openziti/zrok/environment"
|
||||||
|
"github.com/openziti/zrok/tui"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
agentCmd.AddCommand(newAgentVersionCommand().cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
type agentVersionCommand struct {
|
||||||
|
cmd *cobra.Command
|
||||||
|
}
|
||||||
|
|
||||||
|
func newAgentVersionCommand() *agentVersionCommand {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "Retrieve the running zrok Agent version",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
}
|
||||||
|
command := &agentVersionCommand{cmd: cmd}
|
||||||
|
cmd.Run = command.run
|
||||||
|
return command
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cmd *agentVersionCommand) run(_ *cobra.Command, _ []string) {
|
||||||
|
root, err := environment.LoadRoot()
|
||||||
|
if err != nil {
|
||||||
|
tui.Error("error loading zrokdir", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
agentSocket, err := root.AgentSocket()
|
||||||
|
if err != nil {
|
||||||
|
tui.Error("error getting agent socket", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := grpc.NewClient("unix://"+agentSocket, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
|
if err != nil {
|
||||||
|
tui.Error("error connecting to agent socket", err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
client := grpc2.NewAgentClient(conn)
|
||||||
|
|
||||||
|
v, err := client.Version(context.Background(), &grpc2.VersionRequest{})
|
||||||
|
if err != nil {
|
||||||
|
tui.Error("error getting agent version", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
println(*v.V)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user