diff --git a/api/proto.go/myshoes.pb.go b/api/proto.go/myshoes.pb.go index 1636193..57e8fd5 100644 --- a/api/proto.go/myshoes.pb.go +++ b/api/proto.go/myshoes.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.35.1 -// protoc v5.28.2 +// protoc-gen-go v1.36.11 +// protoc v5.29.3 // source: myshoes.proto package proto_go @@ -11,6 +11,7 @@ import ( protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + unsafe "unsafe" ) const ( @@ -91,14 +92,13 @@ func (ResourceType) EnumDescriptor() ([]byte, []int) { } type AddInstanceRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + RunnerName string `protobuf:"bytes,1,opt,name=runner_name,json=runnerName,proto3" json:"runner_name,omitempty"` + SetupScript string `protobuf:"bytes,2,opt,name=setup_script,json=setupScript,proto3" json:"setup_script,omitempty"` + ResourceType ResourceType `protobuf:"varint,3,opt,name=resource_type,json=resourceType,proto3,enum=whywaita.myshoes.ResourceType" json:"resource_type,omitempty"` + Labels []string `protobuf:"bytes,4,rep,name=labels,proto3" json:"labels,omitempty"` unknownFields protoimpl.UnknownFields - - RunnerName string `protobuf:"bytes,1,opt,name=runner_name,json=runnerName,proto3" json:"runner_name,omitempty"` - SetupScript string `protobuf:"bytes,2,opt,name=setup_script,json=setupScript,proto3" json:"setup_script,omitempty"` - ResourceType ResourceType `protobuf:"varint,3,opt,name=resource_type,json=resourceType,proto3,enum=whywaita.myshoes.ResourceType" json:"resource_type,omitempty"` - Labels []string `protobuf:"bytes,4,rep,name=labels,proto3" json:"labels,omitempty"` + sizeCache protoimpl.SizeCache } func (x *AddInstanceRequest) Reset() { @@ -160,14 +160,13 @@ func (x *AddInstanceRequest) GetLabels() []string { } type AddInstanceResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + CloudId string `protobuf:"bytes,1,opt,name=cloud_id,json=cloudId,proto3" json:"cloud_id,omitempty"` + ShoesType string `protobuf:"bytes,2,opt,name=shoes_type,json=shoesType,proto3" json:"shoes_type,omitempty"` + IpAddress string `protobuf:"bytes,3,opt,name=ip_address,json=ipAddress,proto3" json:"ip_address,omitempty"` + ResourceType ResourceType `protobuf:"varint,4,opt,name=resource_type,json=resourceType,proto3,enum=whywaita.myshoes.ResourceType" json:"resource_type,omitempty"` unknownFields protoimpl.UnknownFields - - CloudId string `protobuf:"bytes,1,opt,name=cloud_id,json=cloudId,proto3" json:"cloud_id,omitempty"` - ShoesType string `protobuf:"bytes,2,opt,name=shoes_type,json=shoesType,proto3" json:"shoes_type,omitempty"` - IpAddress string `protobuf:"bytes,3,opt,name=ip_address,json=ipAddress,proto3" json:"ip_address,omitempty"` - ResourceType ResourceType `protobuf:"varint,4,opt,name=resource_type,json=resourceType,proto3,enum=whywaita.myshoes.ResourceType" json:"resource_type,omitempty"` + sizeCache protoimpl.SizeCache } func (x *AddInstanceResponse) Reset() { @@ -229,12 +228,11 @@ func (x *AddInstanceResponse) GetResourceType() ResourceType { } type DeleteInstanceRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + CloudId string `protobuf:"bytes,1,opt,name=cloud_id,json=cloudId,proto3" json:"cloud_id,omitempty"` + Labels []string `protobuf:"bytes,2,rep,name=labels,proto3" json:"labels,omitempty"` unknownFields protoimpl.UnknownFields - - CloudId string `protobuf:"bytes,1,opt,name=cloud_id,json=cloudId,proto3" json:"cloud_id,omitempty"` - Labels []string `protobuf:"bytes,2,rep,name=labels,proto3" json:"labels,omitempty"` + sizeCache protoimpl.SizeCache } func (x *DeleteInstanceRequest) Reset() { @@ -282,9 +280,9 @@ func (x *DeleteInstanceRequest) GetLabels() []string { } type DeleteInstanceResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *DeleteInstanceResponse) Reset() { @@ -319,73 +317,51 @@ func (*DeleteInstanceResponse) Descriptor() ([]byte, []int) { var File_myshoes_proto protoreflect.FileDescriptor -var file_myshoes_proto_rawDesc = []byte{ - 0x0a, 0x0d, 0x6d, 0x79, 0x73, 0x68, 0x6f, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, - 0x10, 0x77, 0x68, 0x79, 0x77, 0x61, 0x69, 0x74, 0x61, 0x2e, 0x6d, 0x79, 0x73, 0x68, 0x6f, 0x65, - 0x73, 0x22, 0xb5, 0x01, 0x0a, 0x12, 0x41, 0x64, 0x64, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x75, 0x6e, 0x6e, - 0x65, 0x72, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x72, - 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x73, 0x65, 0x74, - 0x75, 0x70, 0x5f, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0b, 0x73, 0x65, 0x74, 0x75, 0x70, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x12, 0x43, 0x0a, 0x0d, - 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x0e, 0x32, 0x1e, 0x2e, 0x77, 0x68, 0x79, 0x77, 0x61, 0x69, 0x74, 0x61, 0x2e, 0x6d, - 0x79, 0x73, 0x68, 0x6f, 0x65, 0x73, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x54, - 0x79, 0x70, 0x65, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x54, 0x79, 0x70, - 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x22, 0xb3, 0x01, 0x0a, 0x13, 0x41, 0x64, - 0x64, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, - 0x73, 0x68, 0x6f, 0x65, 0x73, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x09, 0x73, 0x68, 0x6f, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, - 0x70, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x09, 0x69, 0x70, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x43, 0x0a, 0x0d, 0x72, 0x65, - 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x0e, 0x32, 0x1e, 0x2e, 0x77, 0x68, 0x79, 0x77, 0x61, 0x69, 0x74, 0x61, 0x2e, 0x6d, 0x79, 0x73, - 0x68, 0x6f, 0x65, 0x73, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x54, 0x79, 0x70, - 0x65, 0x52, 0x0c, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, - 0x4a, 0x0a, 0x15, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x6c, 0x6f, 0x75, - 0x64, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6c, 0x6f, 0x75, - 0x64, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x02, 0x20, - 0x03, 0x28, 0x09, 0x52, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x22, 0x18, 0x0a, 0x16, 0x44, - 0x65, 0x6c, 0x65, 0x74, 0x65, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2a, 0x85, 0x01, 0x0a, 0x0c, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, - 0x63, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, - 0x6e, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x61, 0x6e, 0x6f, 0x10, 0x01, 0x12, 0x09, 0x0a, - 0x05, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x6d, 0x61, 0x6c, - 0x6c, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, 0x4d, 0x65, 0x64, 0x69, 0x75, 0x6d, 0x10, 0x04, 0x12, - 0x09, 0x0a, 0x05, 0x4c, 0x61, 0x72, 0x67, 0x65, 0x10, 0x05, 0x12, 0x0a, 0x0a, 0x06, 0x58, 0x4c, - 0x61, 0x72, 0x67, 0x65, 0x10, 0x06, 0x12, 0x0b, 0x0a, 0x07, 0x58, 0x4c, 0x61, 0x72, 0x67, 0x65, - 0x32, 0x10, 0x07, 0x12, 0x0b, 0x0a, 0x07, 0x58, 0x4c, 0x61, 0x72, 0x67, 0x65, 0x33, 0x10, 0x08, - 0x12, 0x0b, 0x0a, 0x07, 0x58, 0x4c, 0x61, 0x72, 0x67, 0x65, 0x34, 0x10, 0x09, 0x32, 0xcc, 0x01, - 0x0a, 0x05, 0x53, 0x68, 0x6f, 0x65, 0x73, 0x12, 0x5c, 0x0a, 0x0b, 0x41, 0x64, 0x64, 0x49, 0x6e, - 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x24, 0x2e, 0x77, 0x68, 0x79, 0x77, 0x61, 0x69, 0x74, - 0x61, 0x2e, 0x6d, 0x79, 0x73, 0x68, 0x6f, 0x65, 0x73, 0x2e, 0x41, 0x64, 0x64, 0x49, 0x6e, 0x73, - 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x77, - 0x68, 0x79, 0x77, 0x61, 0x69, 0x74, 0x61, 0x2e, 0x6d, 0x79, 0x73, 0x68, 0x6f, 0x65, 0x73, 0x2e, - 0x41, 0x64, 0x64, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x65, 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x49, - 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x27, 0x2e, 0x77, 0x68, 0x79, 0x77, 0x61, 0x69, - 0x74, 0x61, 0x2e, 0x6d, 0x79, 0x73, 0x68, 0x6f, 0x65, 0x73, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, - 0x65, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x28, 0x2e, 0x77, 0x68, 0x79, 0x77, 0x61, 0x69, 0x74, 0x61, 0x2e, 0x6d, 0x79, 0x73, 0x68, - 0x6f, 0x65, 0x73, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, - 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2a, 0x5a, 0x28, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x68, 0x79, 0x77, 0x61, - 0x69, 0x74, 0x61, 0x2f, 0x6d, 0x79, 0x73, 0x68, 0x6f, 0x65, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x67, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} +const file_myshoes_proto_rawDesc = "" + + "\n" + + "\rmyshoes.proto\x12\x10whywaita.myshoes\"\xb5\x01\n" + + "\x12AddInstanceRequest\x12\x1f\n" + + "\vrunner_name\x18\x01 \x01(\tR\n" + + "runnerName\x12!\n" + + "\fsetup_script\x18\x02 \x01(\tR\vsetupScript\x12C\n" + + "\rresource_type\x18\x03 \x01(\x0e2\x1e.whywaita.myshoes.ResourceTypeR\fresourceType\x12\x16\n" + + "\x06labels\x18\x04 \x03(\tR\x06labels\"\xb3\x01\n" + + "\x13AddInstanceResponse\x12\x19\n" + + "\bcloud_id\x18\x01 \x01(\tR\acloudId\x12\x1d\n" + + "\n" + + "shoes_type\x18\x02 \x01(\tR\tshoesType\x12\x1d\n" + + "\n" + + "ip_address\x18\x03 \x01(\tR\tipAddress\x12C\n" + + "\rresource_type\x18\x04 \x01(\x0e2\x1e.whywaita.myshoes.ResourceTypeR\fresourceType\"J\n" + + "\x15DeleteInstanceRequest\x12\x19\n" + + "\bcloud_id\x18\x01 \x01(\tR\acloudId\x12\x16\n" + + "\x06labels\x18\x02 \x03(\tR\x06labels\"\x18\n" + + "\x16DeleteInstanceResponse*\x85\x01\n" + + "\fResourceType\x12\v\n" + + "\aUnknown\x10\x00\x12\b\n" + + "\x04Nano\x10\x01\x12\t\n" + + "\x05Micro\x10\x02\x12\t\n" + + "\x05Small\x10\x03\x12\n" + + "\n" + + "\x06Medium\x10\x04\x12\t\n" + + "\x05Large\x10\x05\x12\n" + + "\n" + + "\x06XLarge\x10\x06\x12\v\n" + + "\aXLarge2\x10\a\x12\v\n" + + "\aXLarge3\x10\b\x12\v\n" + + "\aXLarge4\x10\t2\xcc\x01\n" + + "\x05Shoes\x12\\\n" + + "\vAddInstance\x12$.whywaita.myshoes.AddInstanceRequest\x1a%.whywaita.myshoes.AddInstanceResponse\"\x00\x12e\n" + + "\x0eDeleteInstance\x12'.whywaita.myshoes.DeleteInstanceRequest\x1a(.whywaita.myshoes.DeleteInstanceResponse\"\x00B*Z(github.com/whywaita/myshoes/api/proto.gob\x06proto3" var ( file_myshoes_proto_rawDescOnce sync.Once - file_myshoes_proto_rawDescData = file_myshoes_proto_rawDesc + file_myshoes_proto_rawDescData []byte ) func file_myshoes_proto_rawDescGZIP() []byte { file_myshoes_proto_rawDescOnce.Do(func() { - file_myshoes_proto_rawDescData = protoimpl.X.CompressGZIP(file_myshoes_proto_rawDescData) + file_myshoes_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_myshoes_proto_rawDesc), len(file_myshoes_proto_rawDesc))) }) return file_myshoes_proto_rawDescData } @@ -422,7 +398,7 @@ func file_myshoes_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_myshoes_proto_rawDesc, + RawDescriptor: unsafe.Slice(unsafe.StringData(file_myshoes_proto_rawDesc), len(file_myshoes_proto_rawDesc)), NumEnums: 1, NumMessages: 4, NumExtensions: 0, @@ -434,7 +410,6 @@ func file_myshoes_proto_init() { MessageInfos: file_myshoes_proto_msgTypes, }.Build() File_myshoes_proto = out.File - file_myshoes_proto_rawDesc = nil file_myshoes_proto_goTypes = nil file_myshoes_proto_depIdxs = nil } diff --git a/api/proto.go/myshoes_grpc.pb.go b/api/proto.go/myshoes_grpc.pb.go index bc5a47c..2fd1042 100644 --- a/api/proto.go/myshoes_grpc.pb.go +++ b/api/proto.go/myshoes_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.3.0 -// - protoc v5.28.2 +// - protoc-gen-go-grpc v1.6.0 +// - protoc v5.29.3 // source: myshoes.proto package proto_go @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( Shoes_AddInstance_FullMethodName = "/whywaita.myshoes.Shoes/AddInstance" @@ -40,8 +40,9 @@ func NewShoesClient(cc grpc.ClientConnInterface) ShoesClient { } func (c *shoesClient) AddInstance(ctx context.Context, in *AddInstanceRequest, opts ...grpc.CallOption) (*AddInstanceResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(AddInstanceResponse) - err := c.cc.Invoke(ctx, Shoes_AddInstance_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, Shoes_AddInstance_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -49,8 +50,9 @@ func (c *shoesClient) AddInstance(ctx context.Context, in *AddInstanceRequest, o } func (c *shoesClient) DeleteInstance(ctx context.Context, in *DeleteInstanceRequest, opts ...grpc.CallOption) (*DeleteInstanceResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(DeleteInstanceResponse) - err := c.cc.Invoke(ctx, Shoes_DeleteInstance_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, Shoes_DeleteInstance_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -59,24 +61,28 @@ func (c *shoesClient) DeleteInstance(ctx context.Context, in *DeleteInstanceRequ // ShoesServer is the server API for Shoes service. // All implementations must embed UnimplementedShoesServer -// for forward compatibility +// for forward compatibility. type ShoesServer interface { AddInstance(context.Context, *AddInstanceRequest) (*AddInstanceResponse, error) DeleteInstance(context.Context, *DeleteInstanceRequest) (*DeleteInstanceResponse, error) mustEmbedUnimplementedShoesServer() } -// UnimplementedShoesServer must be embedded to have forward compatible implementations. -type UnimplementedShoesServer struct { -} +// UnimplementedShoesServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedShoesServer struct{} func (UnimplementedShoesServer) AddInstance(context.Context, *AddInstanceRequest) (*AddInstanceResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method AddInstance not implemented") + return nil, status.Error(codes.Unimplemented, "method AddInstance not implemented") } func (UnimplementedShoesServer) DeleteInstance(context.Context, *DeleteInstanceRequest) (*DeleteInstanceResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method DeleteInstance not implemented") + return nil, status.Error(codes.Unimplemented, "method DeleteInstance not implemented") } func (UnimplementedShoesServer) mustEmbedUnimplementedShoesServer() {} +func (UnimplementedShoesServer) testEmbeddedByValue() {} // UnsafeShoesServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to ShoesServer will @@ -86,6 +92,13 @@ type UnsafeShoesServer interface { } func RegisterShoesServer(s grpc.ServiceRegistrar, srv ShoesServer) { + // If the following call panics, it indicates UnimplementedShoesServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&Shoes_ServiceDesc, srv) } diff --git a/cmd/shoes-tester/main.go b/cmd/shoes-tester/main.go new file mode 100644 index 0000000..515095e --- /dev/null +++ b/cmd/shoes-tester/main.go @@ -0,0 +1,314 @@ +package main + +import ( + "context" + "crypto/x509" + "encoding/json" + "encoding/pem" + "flag" + "fmt" + "os" + "os/exec" + "strconv" + "strings" + + "github.com/hashicorp/go-plugin" + "github.com/whywaita/myshoes/pkg/config" + "github.com/whywaita/myshoes/pkg/datastore" + "github.com/whywaita/myshoes/pkg/gh" + "github.com/whywaita/myshoes/pkg/shoes" + "github.com/whywaita/myshoes/pkg/starter" +) + +func main() { + if len(os.Args) < 2 { + printUsage() + os.Exit(1) + } + + subcommand := os.Args[1] + switch subcommand { + case "add": + if err := runAdd(os.Args[2:]); err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + os.Exit(1) + } + case "delete": + if err := runDelete(os.Args[2:]); err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + os.Exit(1) + } + default: + fmt.Fprintf(os.Stderr, "Unknown subcommand: %s\n", subcommand) + printUsage() + os.Exit(1) + } +} + +func printUsage() { + fmt.Fprintf(os.Stderr, `Usage: shoes-tester [options] + +Commands: + add Add an instance + delete Delete an instance + +Run 'shoes-tester --help' for more information on a command. +`) +} + +type addFlags struct { + pluginPath string + runnerName string + resourceType string + labels string + setupScript string + generateScript bool + scope string + githubAppID string + githubPrivateKeyPath string + runnerVersion string + runnerUser string + runnerBaseDirectory string + githubURL string + jsonOutput bool +} + +type deleteFlags struct { + pluginPath string + cloudID string + labels string + jsonOutput bool +} + +func runAdd(args []string) error { + fs := flag.NewFlagSet("add", flag.ExitOnError) + flags := &addFlags{} + + fs.StringVar(&flags.pluginPath, "plugin", "", "Path to shoes-provider binary (required)") + fs.StringVar(&flags.runnerName, "runner-name", "", "Runner name (required)") + fs.StringVar(&flags.resourceType, "resource-type", "nano", "Resource type (nano|micro|small|medium|large|xlarge|2xlarge|3xlarge|4xlarge)") + fs.StringVar(&flags.labels, "labels", "", "Comma-separated labels") + fs.StringVar(&flags.setupScript, "setup-script", "", "Setup script (simple mode)") + fs.BoolVar(&flags.generateScript, "generate-script", false, "Generate setup script (script generation mode)") + fs.StringVar(&flags.scope, "scope", "", "Repository (owner/repo) or Organization (script generation mode)") + fs.StringVar(&flags.githubAppID, "github-app-id", os.Getenv("GITHUB_APP_ID"), "GitHub App ID (script generation mode)") + fs.StringVar(&flags.githubPrivateKeyPath, "github-private-key-path", os.Getenv("GITHUB_PRIVATE_KEY_PATH"), "GitHub App private key path (script generation mode)") + fs.StringVar(&flags.runnerVersion, "runner-version", "latest", "Runner version (script generation mode)") + fs.StringVar(&flags.runnerUser, "runner-user", "runner", "Runner user (script generation mode)") + fs.StringVar(&flags.runnerBaseDirectory, "runner-base-directory", "/tmp", "Runner base directory (script generation mode)") + fs.StringVar(&flags.githubURL, "github-url", "", "GitHub Enterprise Server URL (script generation mode)") + fs.BoolVar(&flags.jsonOutput, "json", false, "Output in JSON format") + + fs.Parse(args) + + if flags.pluginPath == "" { + return fmt.Errorf("--plugin is required") + } + if flags.runnerName == "" { + return fmt.Errorf("--runner-name is required") + } + + if flags.generateScript { + if flags.scope == "" { + return fmt.Errorf("--scope is required for script generation mode") + } + if flags.githubAppID == "" { + return fmt.Errorf("--github-app-id is required for script generation mode") + } + if flags.githubPrivateKeyPath == "" { + return fmt.Errorf("--github-private-key-path is required for script generation mode") + } + } + + ctx := context.Background() + + var setupScript string + if flags.generateScript { + script, err := generateSetupScript(ctx, flags) + if err != nil { + return fmt.Errorf("failed to generate setup script: %w", err) + } + setupScript = script + } else { + setupScript = flags.setupScript + } + + resourceType := datastore.UnmarshalResourceTypeString(flags.resourceType) + if resourceType == datastore.ResourceTypeUnknown && flags.resourceType != "unknown" { + return fmt.Errorf("invalid resource type: %s", flags.resourceType) + } + + labels := parseLabels(flags.labels) + + client, teardown, err := getClientWithPath(flags.pluginPath) + if err != nil { + return fmt.Errorf("failed to get plugin client: %w", err) + } + defer teardown() + + cloudID, ipAddress, shoesType, actualResourceType, err := client.AddInstance(ctx, flags.runnerName, setupScript, resourceType, labels) + if err != nil { + return fmt.Errorf("failed to add instance: %w", err) + } + + if flags.jsonOutput { + output := map[string]string{ + "cloud_id": cloudID, + "ip_address": ipAddress, + "shoes_type": shoesType, + "resource_type": actualResourceType.String(), + } + data, err := json.Marshal(output) + if err != nil { + return fmt.Errorf("failed to marshal JSON: %w", err) + } + fmt.Println(string(data)) + } else { + fmt.Printf("AddInstance succeeded:\n") + fmt.Printf(" Cloud ID: %s\n", cloudID) + fmt.Printf(" Shoes Type: %s\n", shoesType) + fmt.Printf(" IP Address: %s\n", ipAddress) + fmt.Printf(" Resource Type: %s\n", actualResourceType.String()) + } + + return nil +} + +func runDelete(args []string) error { + fs := flag.NewFlagSet("delete", flag.ExitOnError) + flags := &deleteFlags{} + + fs.StringVar(&flags.pluginPath, "plugin", "", "Path to shoes-provider binary (required)") + fs.StringVar(&flags.cloudID, "cloud-id", "", "Cloud ID (required)") + fs.StringVar(&flags.labels, "labels", "", "Comma-separated labels") + fs.BoolVar(&flags.jsonOutput, "json", false, "Output in JSON format") + + fs.Parse(args) + + if flags.pluginPath == "" { + return fmt.Errorf("--plugin is required") + } + if flags.cloudID == "" { + return fmt.Errorf("--cloud-id is required") + } + + ctx := context.Background() + + labels := parseLabels(flags.labels) + + client, teardown, err := getClientWithPath(flags.pluginPath) + if err != nil { + return fmt.Errorf("failed to get plugin client: %w", err) + } + defer teardown() + + if err := client.DeleteInstance(ctx, flags.cloudID, labels); err != nil { + return fmt.Errorf("failed to delete instance: %w", err) + } + + if flags.jsonOutput { + output := map[string]string{ + "status": "success", + } + data, err := json.Marshal(output) + if err != nil { + return fmt.Errorf("failed to marshal JSON: %w", err) + } + fmt.Println(string(data)) + } else { + fmt.Printf("DeleteInstance succeeded\n") + } + + return nil +} + +func getClientWithPath(pluginPath string) (shoes.Client, func(), error) { + handshake := plugin.HandshakeConfig{ + ProtocolVersion: 1, + MagicCookieKey: "SHOES_PLUGIN_MAGIC_COOKIE", + MagicCookieValue: "are_you_a_shoes?", + } + pluginMap := map[string]plugin.Plugin{ + "shoes_grpc": &shoes.Plugin{}, + } + + client := plugin.NewClient(&plugin.ClientConfig{ + HandshakeConfig: handshake, + Plugins: pluginMap, + Cmd: exec.Command(pluginPath), + Managed: true, + Stderr: os.Stderr, + SyncStdout: os.Stdout, + SyncStderr: os.Stderr, + AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC}, + }) + + rpcClient, err := client.Client() + if err != nil { + return nil, nil, fmt.Errorf("failed to get shoes client: %w", err) + } + + raw, err := rpcClient.Dispense("shoes_grpc") + if err != nil { + return nil, nil, fmt.Errorf("failed to shoes client instance: %w", err) + } + + return raw.(shoes.Client), client.Kill, nil +} + +func generateSetupScript(ctx context.Context, flags *addFlags) (string, error) { + keyBytes, err := os.ReadFile(flags.githubPrivateKeyPath) + if err != nil { + return "", fmt.Errorf("failed to read private key: %w", err) + } + + appID, err := strconv.ParseInt(flags.githubAppID, 10, 64) + if err != nil { + return "", fmt.Errorf("failed to parse github-app-id: %w", err) + } + + block, _ := pem.Decode(keyBytes) + if block == nil { + return "", fmt.Errorf("failed to decode PEM block from private key") + } + + privateKey, err := x509.ParsePKCS1PrivateKey(block.Bytes) + if err != nil { + return "", fmt.Errorf("failed to parse private key: %w", err) + } + + config.Config.GitHub.AppID = appID + config.Config.GitHub.PEMByte = keyBytes + config.Config.GitHub.PEM = privateKey + + if flags.githubURL == "" { + config.Config.GitHubURL = "https://github.com" + } else { + config.Config.GitHubURL = flags.githubURL + } + + config.Config.RunnerUser = flags.runnerUser + config.Config.RunnerBaseDirectory = flags.runnerBaseDirectory + + if err := gh.InitializeCache(appID, keyBytes); err != nil { + return "", fmt.Errorf("failed to initialize GitHub client cache: %w", err) + } + + s := starter.New(nil, nil, flags.runnerVersion, nil) + return s.GetSetupScript(ctx, flags.scope, flags.runnerName) +} + +func parseLabels(labels string) []string { + if labels == "" { + return []string{} + } + parts := strings.Split(labels, ",") + result := make([]string, 0, len(parts)) + for _, p := range parts { + trimmed := strings.TrimSpace(p) + if trimmed != "" { + result = append(result, trimmed) + } + } + return result +} diff --git a/docs/03_how-to-develop-shoes.md b/docs/03_how-to-develop-shoes.md index cd6c597..9e9bf85 100644 --- a/docs/03_how-to-develop-shoes.md +++ b/docs/03_how-to-develop-shoes.md @@ -46,4 +46,76 @@ myshoes defined some machine type. you need to map machine spec for your resourc - xlarge - 2xlarge - 3xlarge -- 4xlarge \ No newline at end of file +- 4xlarge + +## Testing shoes provider + +`shoes-tester` is a CLI tool for testing shoes provider without running myshoes server. + +### Build + +```bash +go build -o shoes-tester ./cmd/shoes-tester +``` + +### Usage + +#### Add instance + +Simple mode (with setup script): + +```bash +./shoes-tester add \ + --plugin ./path/to/your-shoes-provider \ + --runner-name test-runner \ + --resource-type nano \ + --labels "label1,label2" \ + --setup-script "#!/bin/bash\necho 'setup'" +``` + +Script generation mode (generate setup script automatically): + +```bash +./shoes-tester add \ + --plugin ./path/to/your-shoes-provider \ + --runner-name test-runner \ + --resource-type nano \ + --generate-script \ + --scope owner/repo \ + --github-app-id 123456 \ + --github-private-key-path /path/to/key.pem \ + --runner-version latest +``` + +#### Delete instance + +```bash +./shoes-tester delete \ + --plugin ./path/to/your-shoes-provider \ + --cloud-id your-cloud-id \ + --labels "label1,label2" +``` + +#### Options + +Add command: +- `--plugin`: Path to shoes-provider binary (required) +- `--runner-name`: Runner name (required) +- `--resource-type`: Resource type (default: nano) +- `--labels`: Comma-separated labels +- `--setup-script`: Setup script (simple mode) +- `--generate-script`: Generate setup script automatically (script generation mode) +- `--scope`: Repository (owner/repo) or Organization (script generation mode) +- `--github-app-id`: GitHub App ID (script generation mode) +- `--github-private-key-path`: GitHub App private key path (script generation mode) +- `--runner-version`: Runner version (default: latest, script generation mode) +- `--runner-user`: Runner user (default: runner, script generation mode) +- `--runner-base-directory`: Runner base directory (default: /tmp, script generation mode) +- `--github-url`: GitHub Enterprise Server URL (script generation mode) +- `--json`: Output in JSON format + +Delete command: +- `--plugin`: Path to shoes-provider binary (required) +- `--cloud-id`: Cloud ID (required) +- `--labels`: Comma-separated labels +- `--json`: Output in JSON format \ No newline at end of file diff --git a/pkg/starter/scripts.go b/pkg/starter/scripts.go index 8fb0959..0ca78fd 100644 --- a/pkg/starter/scripts.go +++ b/pkg/starter/scripts.go @@ -27,7 +27,7 @@ type templateCompressedScriptValue struct { RunnerBaseDirectory string } -func (s *Starter) getSetupScript(ctx context.Context, targetScope, runnerName string) (string, error) { +func (s *Starter) GetSetupScript(ctx context.Context, targetScope, runnerName string) (string, error) { rawScript, err := s.getSetupRawScript(ctx, targetScope, runnerName) if err != nil { return "", fmt.Errorf("failed to get raw setup scripts: %w", err) diff --git a/pkg/starter/starter.go b/pkg/starter/starter.go index 3f9c362..2c92675 100644 --- a/pkg/starter/starter.go +++ b/pkg/starter/starter.go @@ -343,7 +343,7 @@ func (s *Starter) bung(ctx context.Context, job datastore.Job, target datastore. runnerName := runner.ToName(job.UUID.String()) targetScope := getTargetScope(target, job) - script, err := s.getSetupScript(ctx, targetScope, runnerName) + script, err := s.GetSetupScript(ctx, targetScope, runnerName) if err != nil { return "", "", "", datastore.ResourceTypeUnknown, fmt.Errorf("failed to get setup scripts: %w", err) }