From d3568c061da0b4cf28b524ea9df2dfd17e1951da Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 4 Oct 2024 16:06:30 -0400 Subject: [PATCH] wired in console endpoint into agent, wired into 'zrok agent console' (#221) --- agent/agent.go | 14 ++- agent/agentGrpc/agent.pb.go | 89 +++++++++++-------- agent/agentGrpc/agent.proto | 1 + agent/agentGrpc/agent.swagger.json | 3 + .../agentUi/src/api/.openapi-generator/FILES | 12 --- agent/agentUi/src/api/docs/VersionResponse.md | 1 + .../src/api/src/model/VersionResponse.js | 12 +++ agent/config.go | 11 +++ agent/version.go | 5 +- cmd/zrok/agentConsole.go | 25 +++++- cmd/zrok/agentStart.go | 8 +- cmd/zrok/agentVersion.go | 5 +- 12 files changed, 124 insertions(+), 62 deletions(-) create mode 100644 agent/config.go diff --git a/agent/agent.go b/agent/agent.go index 10b111b1..e50c4211 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -18,6 +18,7 @@ import ( ) type Agent struct { + cfg *AgentConfig root env_core.Root agentSocket string shares map[string]*share @@ -28,11 +29,12 @@ type Agent struct { rmAccess chan *access } -func NewAgent(root env_core.Root) (*Agent, error) { +func NewAgent(cfg *AgentConfig, root env_core.Root) (*Agent, error) { if !root.IsEnabled() { return nil, errors.Errorf("unable to load environment; did you 'zrok enable'?") } return &Agent{ + cfg: cfg, root: root, shares: make(map[string]*share), addShare: make(chan *share), @@ -61,7 +63,7 @@ func (a *Agent) Run() error { a.agentSocket = agentSocket go a.manager() - go a.gateway() + go a.gateway(a.cfg) srv := grpc.NewServer() agentGrpc.RegisterAgentServer(srv, &agentGrpcImpl{agent: a}) @@ -88,7 +90,11 @@ func (a *Agent) Shutdown() { } } -func (a *Agent) gateway() { +func (a *Agent) Config() *AgentConfig { + return a.cfg +} + +func (a *Agent) gateway(cfg *AgentConfig) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -100,7 +106,7 @@ func (a *Agent) gateway() { logrus.Fatalf("unable to register gateway: %v", err) } - if err := http.ListenAndServe(":8888", agentUi.Middleware(mux)); err != nil { + if err := http.ListenAndServe(cfg.ConsoleEndpoint, agentUi.Middleware(mux)); err != nil { logrus.Error(err) } } diff --git a/agent/agentGrpc/agent.pb.go b/agent/agentGrpc/agent.pb.go index 83285f1e..bb50482e 100644 --- a/agent/agentGrpc/agent.pb.go +++ b/agent/agentGrpc/agent.pb.go @@ -1053,7 +1053,8 @@ type VersionResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - V string `protobuf:"bytes,1,opt,name=v,proto3" json:"v,omitempty"` + V string `protobuf:"bytes,1,opt,name=v,proto3" json:"v,omitempty"` + ConsoleEndpoint string `protobuf:"bytes,2,opt,name=consoleEndpoint,proto3" json:"consoleEndpoint,omitempty"` } func (x *VersionResponse) Reset() { @@ -1095,6 +1096,13 @@ func (x *VersionResponse) GetV() string { return "" } +func (x *VersionResponse) GetConsoleEndpoint() string { + if x != nil { + return x.ConsoleEndpoint + } + return "" +} + var File_agent_agentGrpc_agent_proto protoreflect.FileDescriptor var file_agent_agentGrpc_agent_proto_rawDesc = []byte{ @@ -1220,45 +1228,48 @@ var file_agent_agentGrpc_agent_proto_rawDesc = []byte{ 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x52, 0x06, 0x73, 0x68, 0x61, 0x72, 0x65, 0x73, 0x22, 0x10, 0x0a, 0x0e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, - 0x1f, 0x0a, 0x0f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x49, 0x0a, 0x0f, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0c, 0x0a, 0x01, 0x76, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x01, 0x76, - 0x32, 0x95, 0x04, 0x0a, 0x05, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x12, 0x40, 0x0a, 0x0d, 0x41, 0x63, - 0x63, 0x65, 0x73, 0x73, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x12, 0x15, 0x2e, 0x41, 0x63, - 0x63, 0x65, 0x73, 0x73, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x72, 0x69, 0x76, 0x61, - 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x0d, - 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x12, 0x15, 0x2e, - 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x41, 0x63, - 0x63, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, - 0x0a, 0x0c, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x12, 0x14, - 0x2e, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x53, 0x68, - 0x61, 0x72, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, - 0x0d, 0x53, 0x68, 0x61, 0x72, 0x65, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x12, 0x15, - 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x52, 0x65, 0x73, - 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, - 0x3d, 0x0a, 0x0c, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x12, - 0x14, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x69, - 0x76, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3a, - 0x0a, 0x0b, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x12, 0x13, 0x2e, - 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x43, 0x0a, 0x06, 0x53, 0x74, - 0x61, 0x74, 0x75, 0x73, 0x12, 0x0e, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0f, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, - 0x76, 0x31, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, - 0x47, 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x0f, 0x2e, 0x56, 0x65, 0x72, - 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x56, 0x65, - 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, 0x82, - 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, 0x11, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, - 0x2f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x7a, 0x69, 0x74, 0x69, 0x2f, - 0x7a, 0x72, 0x6f, 0x6b, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, - 0x47, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x28, 0x0a, 0x0f, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x45, 0x6e, 0x64, 0x70, 0x6f, + 0x69, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x63, 0x6f, 0x6e, 0x73, 0x6f, + 0x6c, 0x65, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x32, 0x95, 0x04, 0x0a, 0x05, 0x41, + 0x67, 0x65, 0x6e, 0x74, 0x12, 0x40, 0x0a, 0x0d, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x72, + 0x69, 0x76, 0x61, 0x74, 0x65, 0x12, 0x15, 0x2e, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x72, + 0x69, 0x76, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x41, + 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x0d, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, + 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x12, 0x15, 0x2e, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, + 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, + 0x2e, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x0c, 0x52, 0x65, 0x6c, 0x65, + 0x61, 0x73, 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x12, 0x14, 0x2e, 0x52, 0x65, 0x6c, 0x65, 0x61, + 0x73, 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, + 0x2e, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x0d, 0x53, 0x68, 0x61, 0x72, 0x65, + 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x12, 0x15, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, + 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x16, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x52, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x0c, 0x53, 0x68, 0x61, + 0x72, 0x65, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x53, 0x68, 0x61, 0x72, + 0x65, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x15, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3a, 0x0a, 0x0b, 0x53, 0x68, 0x61, 0x72, + 0x65, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x12, 0x13, 0x2e, 0x53, 0x68, 0x61, 0x72, 0x65, 0x50, + 0x75, 0x62, 0x6c, 0x69, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x53, + 0x68, 0x61, 0x72, 0x65, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x12, 0x43, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0e, + 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0f, + 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x12, 0x10, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x67, 0x65, + 0x6e, 0x74, 0x2f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x47, 0x0a, 0x07, 0x56, 0x65, 0x72, + 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x0f, 0x2e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x19, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x13, 0x12, + 0x11, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x76, 0x65, 0x72, 0x73, 0x69, + 0x6f, 0x6e, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x6f, 0x70, 0x65, 0x6e, 0x7a, 0x69, 0x74, 0x69, 0x2f, 0x7a, 0x72, 0x6f, 0x6b, 0x2f, 0x61, + 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x47, 0x72, 0x70, 0x63, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/agent/agentGrpc/agent.proto b/agent/agentGrpc/agent.proto index 071ff0de..bb77b47e 100644 --- a/agent/agentGrpc/agent.proto +++ b/agent/agentGrpc/agent.proto @@ -122,4 +122,5 @@ message VersionRequest { message VersionResponse { string v = 1; + string consoleEndpoint = 2; } diff --git a/agent/agentGrpc/agent.swagger.json b/agent/agentGrpc/agent.swagger.json index e8393096..d58606c8 100644 --- a/agent/agentGrpc/agent.swagger.json +++ b/agent/agentGrpc/agent.swagger.json @@ -197,6 +197,9 @@ "properties": { "v": { "type": "string" + }, + "consoleEndpoint": { + "type": "string" } } }, diff --git a/agent/agentUi/src/api/.openapi-generator/FILES b/agent/agentUi/src/api/.openapi-generator/FILES index 69c72a77..d9dd0a5c 100644 --- a/agent/agentUi/src/api/.openapi-generator/FILES +++ b/agent/agentUi/src/api/.openapi-generator/FILES @@ -1,6 +1,5 @@ .babelrc .gitignore -.openapi-generator-ignore .travis.yml README.md docs/AccessDetail.md @@ -30,14 +29,3 @@ src/model/SharePublicResponse.js src/model/ShareReservedResponse.js src/model/StatusResponse.js src/model/VersionResponse.js -test/api/AgentApi.spec.js -test/model/AccessDetail.spec.js -test/model/AccessPrivateResponse.spec.js -test/model/ProtobufAny.spec.js -test/model/RpcStatus.spec.js -test/model/ShareDetail.spec.js -test/model/SharePrivateResponse.spec.js -test/model/SharePublicResponse.spec.js -test/model/ShareReservedResponse.spec.js -test/model/StatusResponse.spec.js -test/model/VersionResponse.spec.js diff --git a/agent/agentUi/src/api/docs/VersionResponse.md b/agent/agentUi/src/api/docs/VersionResponse.md index 1ddafb96..f428eb39 100644 --- a/agent/agentUi/src/api/docs/VersionResponse.md +++ b/agent/agentUi/src/api/docs/VersionResponse.md @@ -5,5 +5,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **v** | **String** | | [optional] +**consoleEndpoint** | **String** | | [optional] diff --git a/agent/agentUi/src/api/src/model/VersionResponse.js b/agent/agentUi/src/api/src/model/VersionResponse.js index c717d2c9..68a44729 100644 --- a/agent/agentUi/src/api/src/model/VersionResponse.js +++ b/agent/agentUi/src/api/src/model/VersionResponse.js @@ -50,6 +50,9 @@ class VersionResponse { if (data.hasOwnProperty('v')) { obj['v'] = ApiClient.convertToType(data['v'], 'String'); } + if (data.hasOwnProperty('consoleEndpoint')) { + obj['consoleEndpoint'] = ApiClient.convertToType(data['consoleEndpoint'], 'String'); + } } return obj; } @@ -64,6 +67,10 @@ class VersionResponse { if (data['v'] && !(typeof data['v'] === 'string' || data['v'] instanceof String)) { throw new Error("Expected the field `v` to be a primitive type in the JSON string but got " + data['v']); } + // ensure the json data is a string + if (data['consoleEndpoint'] && !(typeof data['consoleEndpoint'] === 'string' || data['consoleEndpoint'] instanceof String)) { + throw new Error("Expected the field `consoleEndpoint` to be a primitive type in the JSON string but got " + data['consoleEndpoint']); + } return true; } @@ -78,6 +85,11 @@ class VersionResponse { */ VersionResponse.prototype['v'] = undefined; +/** + * @member {String} consoleEndpoint + */ +VersionResponse.prototype['consoleEndpoint'] = undefined; + diff --git a/agent/config.go b/agent/config.go new file mode 100644 index 00000000..317092c3 --- /dev/null +++ b/agent/config.go @@ -0,0 +1,11 @@ +package agent + +type AgentConfig struct { + ConsoleEndpoint string +} + +func DefaultAgentConfig() *AgentConfig { + return &AgentConfig{ + ConsoleEndpoint: "127.0.0.1:8888", + } +} diff --git a/agent/version.go b/agent/version.go index add0841c..8519fe38 100644 --- a/agent/version.go +++ b/agent/version.go @@ -10,5 +10,8 @@ import ( func (i *agentGrpcImpl) Version(_ context.Context, _ *agentGrpc.VersionRequest) (*agentGrpc.VersionResponse, error) { v := build.String() logrus.Debugf("responding to version inquiry with '%v'", v) - return &agentGrpc.VersionResponse{V: v}, nil + return &agentGrpc.VersionResponse{ + V: v, + ConsoleEndpoint: i.agent.Config().ConsoleEndpoint, + }, nil } diff --git a/cmd/zrok/agentConsole.go b/cmd/zrok/agentConsole.go index a73556e4..d60e353b 100644 --- a/cmd/zrok/agentConsole.go +++ b/cmd/zrok/agentConsole.go @@ -1,6 +1,11 @@ package main import ( + "context" + "fmt" + "github.com/openziti/zrok/agent/agentClient" + "github.com/openziti/zrok/agent/agentGrpc" + "github.com/openziti/zrok/environment" "github.com/openziti/zrok/tui" "github.com/spf13/cobra" ) @@ -25,7 +30,23 @@ func newAgentConsoleCommand() *agentConsoleCommand { } func (cmd *agentConsoleCommand) run(_ *cobra.Command, _ []string) { - if err := openBrowser("http://localhost:8888"); err != nil { - tui.Error("unable to open agent console at 'http://localhost:8888'", err) + root, err := environment.LoadRoot() + if err != nil { + tui.Error("error loading zrokdir", err) + } + + client, conn, err := agentClient.NewClient(root) + if err != nil { + tui.Error("error connecting to agent", err) + } + defer func() { _ = conn.Close() }() + + v, err := client.Version(context.Background(), &agentGrpc.VersionRequest{}) + if err != nil { + tui.Error("error getting agent version", err) + } + + if err := openBrowser("http://" + v.ConsoleEndpoint); err != nil { + tui.Error(fmt.Sprintf("unable to open agent console at 'http://%v'", v.ConsoleEndpoint), err) } } diff --git a/cmd/zrok/agentStart.go b/cmd/zrok/agentStart.go index 3c3c651d..797f09c7 100644 --- a/cmd/zrok/agentStart.go +++ b/cmd/zrok/agentStart.go @@ -15,7 +15,8 @@ func init() { } type agentStartCommand struct { - cmd *cobra.Command + cmd *cobra.Command + consoleEndpoint string } func newAgentStartCommand() *agentStartCommand { @@ -26,6 +27,7 @@ func newAgentStartCommand() *agentStartCommand { } command := &agentStartCommand{cmd: cmd} cmd.Run = command.run + cmd.Flags().StringVar(&command.consoleEndpoint, "console-endpoint", "127.0.0.1:8888", "gRPC gateway endpoint") return command } @@ -39,7 +41,9 @@ func (cmd *agentStartCommand) run(_ *cobra.Command, _ []string) { tui.Error("unable to load environment; did you 'zrok enable'?", nil) } - a, err := agent.NewAgent(root) + cfg := agent.DefaultAgentConfig() + cfg.ConsoleEndpoint = cmd.consoleEndpoint + a, err := agent.NewAgent(cfg, root) if err != nil { tui.Error("error creating agent", err) } diff --git a/cmd/zrok/agentVersion.go b/cmd/zrok/agentVersion.go index dc522a63..bb2afd43 100644 --- a/cmd/zrok/agentVersion.go +++ b/cmd/zrok/agentVersion.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "github.com/openziti/zrok/agent/agentClient" "github.com/openziti/zrok/agent/agentGrpc" "github.com/openziti/zrok/environment" @@ -38,12 +39,12 @@ func (cmd *agentVersionCommand) run(_ *cobra.Command, _ []string) { if err != nil { tui.Error("error connecting to agent", err) } - defer conn.Close() + defer func() { _ = conn.Close() }() v, err := client.Version(context.Background(), &agentGrpc.VersionRequest{}) if err != nil { tui.Error("error getting agent version", err) } - println(v.GetV()) + fmt.Printf("%v\n%v\n", v.GetV(), v.GetConsoleEndpoint()) }