Skip to content

Commit

Permalink
version client (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Aug 23, 2024
1 parent 3c310c2 commit 896125d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
5 changes: 3 additions & 2 deletions agent/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package agent
import (
"context"
"github.com/openziti/zrok/agent/grpc"
"github.com/prometheus/common/version"
"github.com/openziti/zrok/build"
_ "google.golang.org/grpc"
)

Expand All @@ -12,5 +12,6 @@ type agentGrpcImpl struct {
}

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
}
2 changes: 1 addition & 1 deletion cmd/zrok/agent.go → cmd/zrok/agentStart.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type agentStartCommand struct {
func newAgentStartCommand() *agentStartCommand {
cmd := &cobra.Command{
Use: "start",
Short: "Launch a zrok agent",
Short: "Start a zrok agent",
Args: cobra.NoArgs,
}
command := &agentStartCommand{cmd: cmd}
Expand Down
56 changes: 56 additions & 0 deletions cmd/zrok/agentVersion.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 896125d

Please sign in to comment.