Add the file command with read subcommand
This commit is contained in:
92
cmd/speedrun/cli/file.go
Normal file
92
cmd/speedrun/cli/file.go
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/alitto/pond"
|
||||||
|
"github.com/apex/log"
|
||||||
|
"github.com/dpogorzelski/speedrun/pkg/speedrun/cloud"
|
||||||
|
portalpb "github.com/dpogorzelski/speedrun/proto/portal"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
"storj.io/drpc/drpcconn"
|
||||||
|
)
|
||||||
|
|
||||||
|
var fileCmd = &cobra.Command{
|
||||||
|
Use: "file",
|
||||||
|
Short: "Manage files",
|
||||||
|
TraverseChildren: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
var readCmd = &cobra.Command{
|
||||||
|
Use: "read <path>",
|
||||||
|
Short: "Read a file",
|
||||||
|
Example: " speedrun file read /etc/resolv.conf",
|
||||||
|
Args: cobra.MinimumNArgs(1),
|
||||||
|
RunE: read,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
fileCmd.SetUsageTemplate(usage)
|
||||||
|
fileCmd.AddCommand(readCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func read(cmd *cobra.Command, args []string) error {
|
||||||
|
usePrivateIP := viper.GetBool("portal.use-private-ip")
|
||||||
|
|
||||||
|
tlsConfig, err := cloud.SetupTLS()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
target, err := cmd.Flags().GetString("target")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
portals, err := cloud.GetInstances(target)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pool := pond.New(1000, 10000)
|
||||||
|
for _, p := range portals {
|
||||||
|
portal := p
|
||||||
|
pool.Submit(func() {
|
||||||
|
fields := log.Fields{
|
||||||
|
"host": portal.Name,
|
||||||
|
"address": portal.GetAddress(usePrivateIP),
|
||||||
|
}
|
||||||
|
log := log.WithFields(fields)
|
||||||
|
|
||||||
|
addr := fmt.Sprintf("%s:%d", portal.GetAddress(usePrivateIP), 1337)
|
||||||
|
rawconn, err := tls.Dial("tcp", addr, tlsConfig)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := drpcconn.New(rawconn)
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
c := portalpb.NewDRPCPortalClient(conn)
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
path := strings.Join(args, " ")
|
||||||
|
r, err := c.FileRead(ctx, &portalpb.FileReadRequest{Path: path})
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.WithField("state", r.GetState()).Infof("Contents of %s:\n%s", path, r.GetContent())
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pool.StopAndWait()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -36,7 +36,7 @@ func Execute() {
|
|||||||
|
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
rootCmd.SetUsageTemplate(rootUsage)
|
rootCmd.SetUsageTemplate(rootUsage)
|
||||||
rootCmd.AddCommand(runCmd, serviceCmd)
|
rootCmd.AddCommand(runCmd, serviceCmd, fileCmd)
|
||||||
|
|
||||||
home, err := homedir.Dir()
|
home, err := homedir.Dir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Usage:{{if .Runnable}}
|
|||||||
Core Commands:{{range .Commands}}{{if (or (eq .Name "help") (eq .Name "completion"))}}
|
Core Commands:{{range .Commands}}{{if (or (eq .Name "help") (eq .Name "completion"))}}
|
||||||
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
||||||
|
|
||||||
Action Commands:{{range .Commands}}{{if (or (eq .Name "run") (eq .Name "exec") (eq .Name "service"))}}
|
Action Commands:{{range .Commands}}{{if (or (eq .Name "run") (eq .Name "exec") (eq .Name "service") (eq .Name "file"))}}
|
||||||
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
||||||
{{if .HasAvailableLocalFlags}}
|
{{if .HasAvailableLocalFlags}}
|
||||||
Flags:
|
Flags:
|
||||||
|
|||||||
27
pkg/portal/file.go
Normal file
27
pkg/portal/file.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package portal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/apex/log"
|
||||||
|
"github.com/dpogorzelski/speedrun/proto/portal"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) FileRead(ctx context.Context, file *portal.FileReadRequest) (*portal.FileReadResponse, error) {
|
||||||
|
fields := log.Fields{
|
||||||
|
"context": "file",
|
||||||
|
"command": "read",
|
||||||
|
"name": file.GetPath(),
|
||||||
|
}
|
||||||
|
log := log.WithFields(fields)
|
||||||
|
log.Debug("Received file read request")
|
||||||
|
|
||||||
|
content, err := os.ReadFile(file.GetPath())
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err.Error())
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &portal.FileReadResponse{State: portal.State_UNKNOWN, Content: string(content)}, nil
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
// versions:
|
// versions:
|
||||||
// protoc-gen-go v1.27.1
|
// protoc-gen-go v1.28.0
|
||||||
// protoc v3.17.3
|
// protoc v3.19.4
|
||||||
// source: portal/portal.proto
|
// source: portal/portal.proto
|
||||||
|
|
||||||
package portal
|
package portal
|
||||||
@@ -453,6 +453,108 @@ func (x *CPUusageResponse) GetLoadavg15() int32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FileReadRequest struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FileReadRequest) Reset() {
|
||||||
|
*x = FileReadRequest{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_portal_portal_proto_msgTypes[7]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FileReadRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*FileReadRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *FileReadRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_portal_portal_proto_msgTypes[7]
|
||||||
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use FileReadRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*FileReadRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_portal_portal_proto_rawDescGZIP(), []int{7}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FileReadRequest) GetPath() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Path
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileReadResponse struct {
|
||||||
|
state protoimpl.MessageState
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
State State `protobuf:"varint,1,opt,name=state,proto3,enum=portal.State" json:"state,omitempty"`
|
||||||
|
Content string `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FileReadResponse) Reset() {
|
||||||
|
*x = FileReadResponse{}
|
||||||
|
if protoimpl.UnsafeEnabled {
|
||||||
|
mi := &file_portal_portal_proto_msgTypes[8]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FileReadResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*FileReadResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *FileReadResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_portal_portal_proto_msgTypes[8]
|
||||||
|
if protoimpl.UnsafeEnabled && x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use FileReadResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*FileReadResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_portal_portal_proto_rawDescGZIP(), []int{8}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FileReadResponse) GetState() State {
|
||||||
|
if x != nil {
|
||||||
|
return x.State
|
||||||
|
}
|
||||||
|
return State_UNKNOWN
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *FileReadResponse) GetContent() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Content
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
var File_portal_portal_proto protoreflect.FileDescriptor
|
var File_portal_portal_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_portal_portal_proto_rawDesc = []byte{
|
var file_portal_portal_proto_rawDesc = []byte{
|
||||||
@@ -491,40 +593,51 @@ var file_portal_portal_proto_rawDesc = []byte{
|
|||||||
0x1a, 0x0a, 0x08, 0x6c, 0x6f, 0x61, 0x64, 0x61, 0x76, 0x67, 0x35, 0x18, 0x02, 0x20, 0x01, 0x28,
|
0x1a, 0x0a, 0x08, 0x6c, 0x6f, 0x61, 0x64, 0x61, 0x76, 0x67, 0x35, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||||
0x05, 0x52, 0x08, 0x6c, 0x6f, 0x61, 0x64, 0x61, 0x76, 0x67, 0x35, 0x12, 0x1c, 0x0a, 0x09, 0x6c,
|
0x05, 0x52, 0x08, 0x6c, 0x6f, 0x61, 0x64, 0x61, 0x76, 0x67, 0x35, 0x12, 0x1c, 0x0a, 0x09, 0x6c,
|
||||||
0x6f, 0x61, 0x64, 0x61, 0x76, 0x67, 0x31, 0x35, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09,
|
0x6f, 0x61, 0x64, 0x61, 0x76, 0x67, 0x31, 0x35, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09,
|
||||||
0x6c, 0x6f, 0x61, 0x64, 0x61, 0x76, 0x67, 0x31, 0x35, 0x2a, 0x30, 0x0a, 0x05, 0x53, 0x74, 0x61,
|
0x6c, 0x6f, 0x61, 0x64, 0x61, 0x76, 0x67, 0x31, 0x35, 0x22, 0x25, 0x0a, 0x0f, 0x46, 0x69, 0x6c,
|
||||||
0x74, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12,
|
0x65, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04,
|
||||||
0x0b, 0x0a, 0x07, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x44, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09,
|
0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68,
|
||||||
0x55, 0x4e, 0x43, 0x48, 0x41, 0x4e, 0x47, 0x45, 0x44, 0x10, 0x02, 0x32, 0x9e, 0x03, 0x0a, 0x06,
|
0x22, 0x51, 0x0a, 0x10, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70,
|
||||||
0x50, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x12, 0x43, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
|
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x23, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20,
|
||||||
0x65, 0x52, 0x65, 0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61,
|
0x01, 0x28, 0x0e, 0x32, 0x0d, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x74, 0x61,
|
||||||
0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e,
|
||||||
0x1a, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
|
0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74,
|
||||||
0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x41, 0x0a, 0x0c, 0x53,
|
0x65, 0x6e, 0x74, 0x2a, 0x30, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0b, 0x0a, 0x07,
|
||||||
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x53, 0x74, 0x61, 0x72, 0x74, 0x12, 0x16, 0x2e, 0x70, 0x6f,
|
0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x48, 0x41,
|
||||||
0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75,
|
0x4e, 0x47, 0x45, 0x44, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x43, 0x48, 0x41, 0x4e,
|
||||||
0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72,
|
0x47, 0x45, 0x44, 0x10, 0x02, 0x32, 0xdf, 0x03, 0x0a, 0x06, 0x50, 0x6f, 0x72, 0x74, 0x61, 0x6c,
|
||||||
0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40,
|
0x12, 0x43, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x74, 0x61,
|
||||||
0x0a, 0x0b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x16, 0x2e,
|
0x72, 0x74, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76,
|
||||||
|
0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x6f, 0x72,
|
||||||
|
0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||||
|
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x41, 0x0a, 0x0c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||||
|
0x53, 0x74, 0x61, 0x72, 0x74, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53,
|
||||||
|
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e,
|
||||||
0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65,
|
0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65,
|
||||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53,
|
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x0b, 0x53, 0x65, 0x72, 0x76,
|
||||||
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00,
|
0x69, 0x63, 0x65, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c,
|
||||||
0x12, 0x48, 0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75,
|
0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
|
||||||
0x73, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69,
|
0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
|
||||||
0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x70, 0x6f, 0x72, 0x74,
|
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x48, 0x0a, 0x0d, 0x53, 0x65,
|
||||||
0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73,
|
0x72, 0x76, 0x69, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x2e, 0x70, 0x6f,
|
||||||
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x0a, 0x52, 0x75,
|
0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75,
|
||||||
0x6e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61,
|
0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x53, 0x65, 0x72,
|
||||||
0x6c, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
0x76, 0x69, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
|
||||||
0x1a, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e,
|
0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x43, 0x6f, 0x6d, 0x6d, 0x61,
|
||||||
0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x08, 0x43,
|
0x6e, 0x64, 0x12, 0x16, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x43, 0x6f, 0x6d, 0x6d,
|
||||||
0x50, 0x55, 0x75, 0x73, 0x61, 0x67, 0x65, 0x12, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c,
|
0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x70, 0x6f, 0x72,
|
||||||
0x2e, 0x43, 0x50, 0x55, 0x75, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
0x74, 0x61, 0x6c, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||||
0x1a, 0x18, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x43, 0x50, 0x55, 0x75, 0x73, 0x61,
|
0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x08, 0x43, 0x50, 0x55, 0x75, 0x73, 0x61, 0x67,
|
||||||
0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2d, 0x5a, 0x2b,
|
0x65, 0x12, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x43, 0x50, 0x55, 0x75, 0x73,
|
||||||
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x70, 0x65, 0x65, 0x64,
|
0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x6f, 0x72,
|
||||||
0x72, 0x75, 0x6e, 0x73, 0x68, 0x2f, 0x73, 0x70, 0x65, 0x65, 0x64, 0x72, 0x75, 0x6e, 0x2f, 0x70,
|
0x74, 0x61, 0x6c, 0x2e, 0x43, 0x50, 0x55, 0x75, 0x73, 0x61, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70,
|
||||||
0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f,
|
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3f, 0x0a, 0x08, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65,
|
||||||
0x74, 0x6f, 0x33,
|
0x61, 0x64, 0x12, 0x17, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x2e, 0x46, 0x69, 0x6c, 0x65,
|
||||||
|
0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x6f,
|
||||||
|
0x72, 0x74, 0x61, 0x6c, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x65, 0x61, 0x64, 0x52, 0x65, 0x73,
|
||||||
|
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75,
|
||||||
|
0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x70, 0x6f, 0x67, 0x6f, 0x72, 0x7a, 0x65, 0x6c, 0x73,
|
||||||
|
0x6b, 0x69, 0x2f, 0x73, 0x70, 0x65, 0x65, 0x64, 0x72, 0x75, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74,
|
||||||
|
0x6f, 0x2f, 0x70, 0x6f, 0x72, 0x74, 0x61, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -540,7 +653,7 @@ func file_portal_portal_proto_rawDescGZIP() []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var file_portal_portal_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
var file_portal_portal_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||||
var file_portal_portal_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
|
var file_portal_portal_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
|
||||||
var file_portal_portal_proto_goTypes = []interface{}{
|
var file_portal_portal_proto_goTypes = []interface{}{
|
||||||
(State)(0), // 0: portal.State
|
(State)(0), // 0: portal.State
|
||||||
(*CommandRequest)(nil), // 1: portal.CommandRequest
|
(*CommandRequest)(nil), // 1: portal.CommandRequest
|
||||||
@@ -550,28 +663,33 @@ var file_portal_portal_proto_goTypes = []interface{}{
|
|||||||
(*ServiceStatusResponse)(nil), // 5: portal.ServiceStatusResponse
|
(*ServiceStatusResponse)(nil), // 5: portal.ServiceStatusResponse
|
||||||
(*CPUusageRequest)(nil), // 6: portal.CPUusageRequest
|
(*CPUusageRequest)(nil), // 6: portal.CPUusageRequest
|
||||||
(*CPUusageResponse)(nil), // 7: portal.CPUusageResponse
|
(*CPUusageResponse)(nil), // 7: portal.CPUusageResponse
|
||||||
|
(*FileReadRequest)(nil), // 8: portal.FileReadRequest
|
||||||
|
(*FileReadResponse)(nil), // 9: portal.FileReadResponse
|
||||||
}
|
}
|
||||||
var file_portal_portal_proto_depIdxs = []int32{
|
var file_portal_portal_proto_depIdxs = []int32{
|
||||||
0, // 0: portal.CommandResponse.state:type_name -> portal.State
|
0, // 0: portal.CommandResponse.state:type_name -> portal.State
|
||||||
0, // 1: portal.ServiceResponse.state:type_name -> portal.State
|
0, // 1: portal.ServiceResponse.state:type_name -> portal.State
|
||||||
0, // 2: portal.ServiceStatusResponse.state:type_name -> portal.State
|
0, // 2: portal.ServiceStatusResponse.state:type_name -> portal.State
|
||||||
3, // 3: portal.Portal.ServiceRestart:input_type -> portal.ServiceRequest
|
0, // 3: portal.FileReadResponse.state:type_name -> portal.State
|
||||||
3, // 4: portal.Portal.ServiceStart:input_type -> portal.ServiceRequest
|
3, // 4: portal.Portal.ServiceRestart:input_type -> portal.ServiceRequest
|
||||||
3, // 5: portal.Portal.ServiceStop:input_type -> portal.ServiceRequest
|
3, // 5: portal.Portal.ServiceStart:input_type -> portal.ServiceRequest
|
||||||
3, // 6: portal.Portal.ServiceStatus:input_type -> portal.ServiceRequest
|
3, // 6: portal.Portal.ServiceStop:input_type -> portal.ServiceRequest
|
||||||
1, // 7: portal.Portal.RunCommand:input_type -> portal.CommandRequest
|
3, // 7: portal.Portal.ServiceStatus:input_type -> portal.ServiceRequest
|
||||||
6, // 8: portal.Portal.CPUusage:input_type -> portal.CPUusageRequest
|
1, // 8: portal.Portal.RunCommand:input_type -> portal.CommandRequest
|
||||||
4, // 9: portal.Portal.ServiceRestart:output_type -> portal.ServiceResponse
|
6, // 9: portal.Portal.CPUusage:input_type -> portal.CPUusageRequest
|
||||||
4, // 10: portal.Portal.ServiceStart:output_type -> portal.ServiceResponse
|
8, // 10: portal.Portal.FileRead:input_type -> portal.FileReadRequest
|
||||||
4, // 11: portal.Portal.ServiceStop:output_type -> portal.ServiceResponse
|
4, // 11: portal.Portal.ServiceRestart:output_type -> portal.ServiceResponse
|
||||||
5, // 12: portal.Portal.ServiceStatus:output_type -> portal.ServiceStatusResponse
|
4, // 12: portal.Portal.ServiceStart:output_type -> portal.ServiceResponse
|
||||||
2, // 13: portal.Portal.RunCommand:output_type -> portal.CommandResponse
|
4, // 13: portal.Portal.ServiceStop:output_type -> portal.ServiceResponse
|
||||||
7, // 14: portal.Portal.CPUusage:output_type -> portal.CPUusageResponse
|
5, // 14: portal.Portal.ServiceStatus:output_type -> portal.ServiceStatusResponse
|
||||||
9, // [9:15] is the sub-list for method output_type
|
2, // 15: portal.Portal.RunCommand:output_type -> portal.CommandResponse
|
||||||
3, // [3:9] is the sub-list for method input_type
|
7, // 16: portal.Portal.CPUusage:output_type -> portal.CPUusageResponse
|
||||||
3, // [3:3] is the sub-list for extension type_name
|
9, // 17: portal.Portal.FileRead:output_type -> portal.FileReadResponse
|
||||||
3, // [3:3] is the sub-list for extension extendee
|
11, // [11:18] is the sub-list for method output_type
|
||||||
0, // [0:3] is the sub-list for field type_name
|
4, // [4:11] is the sub-list for method input_type
|
||||||
|
4, // [4:4] is the sub-list for extension type_name
|
||||||
|
4, // [4:4] is the sub-list for extension extendee
|
||||||
|
0, // [0:4] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_portal_portal_proto_init() }
|
func init() { file_portal_portal_proto_init() }
|
||||||
@@ -664,6 +782,30 @@ func file_portal_portal_proto_init() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
file_portal_portal_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*FileReadRequest); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file_portal_portal_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
|
||||||
|
switch v := v.(*FileReadResponse); i {
|
||||||
|
case 0:
|
||||||
|
return &v.state
|
||||||
|
case 1:
|
||||||
|
return &v.sizeCache
|
||||||
|
case 2:
|
||||||
|
return &v.unknownFields
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
type x struct{}
|
type x struct{}
|
||||||
out := protoimpl.TypeBuilder{
|
out := protoimpl.TypeBuilder{
|
||||||
@@ -671,7 +813,7 @@ func file_portal_portal_proto_init() {
|
|||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: file_portal_portal_proto_rawDesc,
|
RawDescriptor: file_portal_portal_proto_rawDesc,
|
||||||
NumEnums: 1,
|
NumEnums: 1,
|
||||||
NumMessages: 7,
|
NumMessages: 9,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 1,
|
NumServices: 1,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -42,14 +42,24 @@ message CPUusageResponse {
|
|||||||
int32 loadavg15 = 3;
|
int32 loadavg15 = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message FileReadRequest {
|
||||||
|
string path = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message FileReadResponse {
|
||||||
|
State state = 1;
|
||||||
|
string content = 2;
|
||||||
|
}
|
||||||
|
|
||||||
service Portal {
|
service Portal {
|
||||||
rpc ServiceRestart(ServiceRequest) returns (ServiceResponse) {}
|
rpc ServiceRestart(ServiceRequest) returns (ServiceResponse) {}
|
||||||
rpc ServiceStart(ServiceRequest) returns (ServiceResponse) {}
|
rpc ServiceStart(ServiceRequest) returns (ServiceResponse) {}
|
||||||
rpc ServiceStop(ServiceRequest) returns (ServiceResponse) {}
|
rpc ServiceStop(ServiceRequest) returns (ServiceResponse) {}
|
||||||
rpc ServiceStatus(ServiceRequest) returns (ServiceStatusResponse) {}
|
rpc ServiceStatus(ServiceRequest) returns (ServiceStatusResponse) {}
|
||||||
rpc RunCommand(CommandRequest) returns (CommandResponse) {}
|
rpc RunCommand(CommandRequest) returns (CommandResponse) {}
|
||||||
rpc CPUusage(CPUusageRequest) returns (CPUusageResponse) {
|
rpc CPUusage(CPUusageRequest) returns (CPUusageResponse) {}
|
||||||
} // --target group1 --target group2
|
rpc FileRead(FileReadRequest) returns (FileReadResponse) {}
|
||||||
|
// --target group1 --target group2
|
||||||
// rpc CPUProfile(CPUProfileRequest) returns (CPUProfileResponse) {}
|
// rpc CPUProfile(CPUProfileRequest) returns (CPUProfileResponse) {}
|
||||||
// rpc MemProfile(MemProfileRequest) returns (MemProfileResponse) {}
|
// rpc MemProfile(MemProfileRequest) returns (MemProfileResponse) {}
|
||||||
// rpc EnsureMountedDisk()
|
// rpc EnsureMountedDisk()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
// Code generated by protoc-gen-go-drpc. DO NOT EDIT.
|
||||||
// protoc-gen-go-drpc version: v0.0.26
|
// protoc-gen-go-drpc version: v0.0.30
|
||||||
// source: portal/portal.proto
|
// source: portal/portal.proto
|
||||||
|
|
||||||
package portal
|
package portal
|
||||||
@@ -44,6 +44,7 @@ type DRPCPortalClient interface {
|
|||||||
ServiceStatus(ctx context.Context, in *ServiceRequest) (*ServiceStatusResponse, error)
|
ServiceStatus(ctx context.Context, in *ServiceRequest) (*ServiceStatusResponse, error)
|
||||||
RunCommand(ctx context.Context, in *CommandRequest) (*CommandResponse, error)
|
RunCommand(ctx context.Context, in *CommandRequest) (*CommandResponse, error)
|
||||||
CPUusage(ctx context.Context, in *CPUusageRequest) (*CPUusageResponse, error)
|
CPUusage(ctx context.Context, in *CPUusageRequest) (*CPUusageResponse, error)
|
||||||
|
FileRead(ctx context.Context, in *FileReadRequest) (*FileReadResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type drpcPortalClient struct {
|
type drpcPortalClient struct {
|
||||||
@@ -110,6 +111,15 @@ func (c *drpcPortalClient) CPUusage(ctx context.Context, in *CPUusageRequest) (*
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *drpcPortalClient) FileRead(ctx context.Context, in *FileReadRequest) (*FileReadResponse, error) {
|
||||||
|
out := new(FileReadResponse)
|
||||||
|
err := c.cc.Invoke(ctx, "/portal.Portal/FileRead", drpcEncoding_File_portal_portal_proto{}, in, out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
type DRPCPortalServer interface {
|
type DRPCPortalServer interface {
|
||||||
ServiceRestart(context.Context, *ServiceRequest) (*ServiceResponse, error)
|
ServiceRestart(context.Context, *ServiceRequest) (*ServiceResponse, error)
|
||||||
ServiceStart(context.Context, *ServiceRequest) (*ServiceResponse, error)
|
ServiceStart(context.Context, *ServiceRequest) (*ServiceResponse, error)
|
||||||
@@ -117,6 +127,7 @@ type DRPCPortalServer interface {
|
|||||||
ServiceStatus(context.Context, *ServiceRequest) (*ServiceStatusResponse, error)
|
ServiceStatus(context.Context, *ServiceRequest) (*ServiceStatusResponse, error)
|
||||||
RunCommand(context.Context, *CommandRequest) (*CommandResponse, error)
|
RunCommand(context.Context, *CommandRequest) (*CommandResponse, error)
|
||||||
CPUusage(context.Context, *CPUusageRequest) (*CPUusageResponse, error)
|
CPUusage(context.Context, *CPUusageRequest) (*CPUusageResponse, error)
|
||||||
|
FileRead(context.Context, *FileReadRequest) (*FileReadResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DRPCPortalUnimplementedServer struct{}
|
type DRPCPortalUnimplementedServer struct{}
|
||||||
@@ -145,9 +156,13 @@ func (s *DRPCPortalUnimplementedServer) CPUusage(context.Context, *CPUusageReque
|
|||||||
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DRPCPortalUnimplementedServer) FileRead(context.Context, *FileReadRequest) (*FileReadResponse, error) {
|
||||||
|
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||||
|
}
|
||||||
|
|
||||||
type DRPCPortalDescription struct{}
|
type DRPCPortalDescription struct{}
|
||||||
|
|
||||||
func (DRPCPortalDescription) NumMethods() int { return 6 }
|
func (DRPCPortalDescription) NumMethods() int { return 7 }
|
||||||
|
|
||||||
func (DRPCPortalDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
|
func (DRPCPortalDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
|
||||||
switch n {
|
switch n {
|
||||||
@@ -205,6 +220,15 @@ func (DRPCPortalDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver
|
|||||||
in1.(*CPUusageRequest),
|
in1.(*CPUusageRequest),
|
||||||
)
|
)
|
||||||
}, DRPCPortalServer.CPUusage, true
|
}, DRPCPortalServer.CPUusage, true
|
||||||
|
case 6:
|
||||||
|
return "/portal.Portal/FileRead", drpcEncoding_File_portal_portal_proto{},
|
||||||
|
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||||
|
return srv.(DRPCPortalServer).
|
||||||
|
FileRead(
|
||||||
|
ctx,
|
||||||
|
in1.(*FileReadRequest),
|
||||||
|
)
|
||||||
|
}, DRPCPortalServer.FileRead, true
|
||||||
default:
|
default:
|
||||||
return "", nil, nil, nil, false
|
return "", nil, nil, nil, false
|
||||||
}
|
}
|
||||||
@@ -309,3 +333,19 @@ func (x *drpcPortal_CPUusageStream) SendAndClose(m *CPUusageResponse) error {
|
|||||||
}
|
}
|
||||||
return x.CloseSend()
|
return x.CloseSend()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DRPCPortal_FileReadStream interface {
|
||||||
|
drpc.Stream
|
||||||
|
SendAndClose(*FileReadResponse) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type drpcPortal_FileReadStream struct {
|
||||||
|
drpc.Stream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *drpcPortal_FileReadStream) SendAndClose(m *FileReadResponse) error {
|
||||||
|
if err := x.MsgSend(m, drpcEncoding_File_portal_portal_proto{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return x.CloseSend()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user