From 31e91dea98cf2a7012d800929609ef90eced4b5a Mon Sep 17 00:00:00 2001 From: Shinnosuke Sawada-Dazai Date: Wed, 25 Sep 2024 14:28:33 +0900 Subject: [PATCH] Add InstallTool RPC method for PluginService (#5218) Signed-off-by: Shinnosuke Sawada-Dazai --- .../pipedv1/cmd/piped/service/service.pb.go | 207 +++++++++++++-- .../cmd/piped/service/service.pb.validate.go | 239 ++++++++++++++++++ .../pipedv1/cmd/piped/service/service.proto | 31 +++ .../cmd/piped/service/service_grpc.pb.go | 40 +++ 4 files changed, 501 insertions(+), 16 deletions(-) diff --git a/pkg/app/pipedv1/cmd/piped/service/service.pb.go b/pkg/app/pipedv1/cmd/piped/service/service.pb.go index 0446436b93..4805116003 100644 --- a/pkg/app/pipedv1/cmd/piped/service/service.pb.go +++ b/pkg/app/pipedv1/cmd/piped/service/service.pb.go @@ -129,6 +129,134 @@ func (x *DecryptSecretResponse) GetDecryptedSecret() string { return "" } +type InstallToolRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Name of the tool. + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // Version of the tool. + Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` + // Install script to install the tool. + // This script is templated with the following variables: + // - {{ .Name }}: name of the tool. + // - {{ .Version }}: version of the tool. + // - {{ .OutPath }}: file path where the tool will be installed. + // - {{ .TmpDir }}: directory where the tool will be downloaded and extracted. + // - {{ .Arch }}: GOARCH of the current machine. + // - {{ .Os }}: GOOS of the current machine. + // + // The script should return 0 if the installation is successful. + // Otherwise, it should return a non-zero value. + // + // The tool should be placed at {{ .OutPath }} + // e.g.) cp path/to/kubectl {{ .OutPath }} + // Then piped move it to the correct directory / filename and make it executable. + InstallScript string `protobuf:"bytes,3,opt,name=install_script,json=installScript,proto3" json:"install_script,omitempty"` +} + +func (x *InstallToolRequest) Reset() { + *x = InstallToolRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_pkg_app_pipedv1_cmd_piped_service_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *InstallToolRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InstallToolRequest) ProtoMessage() {} + +func (x *InstallToolRequest) ProtoReflect() protoreflect.Message { + mi := &file_pkg_app_pipedv1_cmd_piped_service_service_proto_msgTypes[2] + 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 InstallToolRequest.ProtoReflect.Descriptor instead. +func (*InstallToolRequest) Descriptor() ([]byte, []int) { + return file_pkg_app_pipedv1_cmd_piped_service_service_proto_rawDescGZIP(), []int{2} +} + +func (x *InstallToolRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *InstallToolRequest) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + +func (x *InstallToolRequest) GetInstallScript() string { + if x != nil { + return x.InstallScript + } + return "" +} + +type InstallToolResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Installed path of the tool. + InstalledPath string `protobuf:"bytes,1,opt,name=installed_path,json=installedPath,proto3" json:"installed_path,omitempty"` +} + +func (x *InstallToolResponse) Reset() { + *x = InstallToolResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_pkg_app_pipedv1_cmd_piped_service_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *InstallToolResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InstallToolResponse) ProtoMessage() {} + +func (x *InstallToolResponse) ProtoReflect() protoreflect.Message { + mi := &file_pkg_app_pipedv1_cmd_piped_service_service_proto_msgTypes[3] + 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 InstallToolResponse.ProtoReflect.Descriptor instead. +func (*InstallToolResponse) Descriptor() ([]byte, []int) { + return file_pkg_app_pipedv1_cmd_piped_service_service_proto_rawDescGZIP(), []int{3} +} + +func (x *InstallToolResponse) GetInstalledPath() string { + if x != nil { + return x.InstalledPath + } + return "" +} + var File_pkg_app_pipedv1_cmd_piped_service_service_proto protoreflect.FileDescriptor var file_pkg_app_pipedv1_cmd_piped_service_service_proto_rawDesc = []byte{ @@ -145,19 +273,38 @@ var file_pkg_app_pipedv1_cmd_piped_service_service_proto_rawDesc = []byte{ 0x70, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x64, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65, 0x64, 0x5f, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x64, 0x65, 0x63, 0x72, - 0x79, 0x70, 0x74, 0x65, 0x64, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x32, 0x77, 0x0a, 0x0d, 0x50, - 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x66, 0x0a, 0x0d, - 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x12, 0x28, 0x2e, + 0x79, 0x70, 0x74, 0x65, 0x64, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x22, 0x84, 0x01, 0x0a, 0x12, + 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x54, 0x6f, 0x6f, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, + 0x21, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, + 0x6f, 0x6e, 0x12, 0x2e, 0x0a, 0x0e, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x5f, 0x73, 0x63, + 0x72, 0x69, 0x70, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, + 0x02, 0x10, 0x01, 0x52, 0x0d, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x53, 0x63, 0x72, 0x69, + 0x70, 0x74, 0x22, 0x3c, 0x0a, 0x13, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x54, 0x6f, 0x6f, + 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x69, 0x6e, 0x73, + 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0d, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x50, 0x61, 0x74, 0x68, + 0x32, 0xd9, 0x01, 0x0a, 0x0d, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x12, 0x66, 0x0a, 0x0d, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, 0x53, 0x65, 0x63, + 0x72, 0x65, 0x74, 0x12, 0x28, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x70, 0x69, 0x70, 0x65, 0x64, + 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, + 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x70, 0x69, 0x70, 0x65, 0x64, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x44, 0x65, 0x63, 0x72, 0x79, 0x70, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x70, - 0x69, 0x70, 0x65, 0x64, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x44, 0x65, 0x63, - 0x72, 0x79, 0x70, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x22, 0x00, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x2d, 0x63, 0x64, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x63, - 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x64, 0x76, - 0x31, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x60, 0x0a, 0x0b, 0x49, 0x6e, + 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x54, 0x6f, 0x6f, 0x6c, 0x12, 0x26, 0x2e, 0x67, 0x72, 0x70, 0x63, + 0x2e, 0x70, 0x69, 0x70, 0x65, 0x64, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x49, + 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x54, 0x6f, 0x6f, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x27, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x70, 0x69, 0x70, 0x65, 0x64, 0x2e, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x54, 0x6f, + 0x6f, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x3d, 0x5a, 0x3b, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x2d, + 0x63, 0x64, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x63, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, + 0x70, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x64, 0x76, 0x31, 0x2f, 0x63, 0x6d, 0x64, 0x2f, 0x70, 0x69, + 0x70, 0x65, 0x64, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -172,16 +319,20 @@ func file_pkg_app_pipedv1_cmd_piped_service_service_proto_rawDescGZIP() []byte { return file_pkg_app_pipedv1_cmd_piped_service_service_proto_rawDescData } -var file_pkg_app_pipedv1_cmd_piped_service_service_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_pkg_app_pipedv1_cmd_piped_service_service_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_pkg_app_pipedv1_cmd_piped_service_service_proto_goTypes = []interface{}{ (*DecryptSecretRequest)(nil), // 0: grpc.piped.service.DecryptSecretRequest (*DecryptSecretResponse)(nil), // 1: grpc.piped.service.DecryptSecretResponse + (*InstallToolRequest)(nil), // 2: grpc.piped.service.InstallToolRequest + (*InstallToolResponse)(nil), // 3: grpc.piped.service.InstallToolResponse } var file_pkg_app_pipedv1_cmd_piped_service_service_proto_depIdxs = []int32{ 0, // 0: grpc.piped.service.PluginService.DecryptSecret:input_type -> grpc.piped.service.DecryptSecretRequest - 1, // 1: grpc.piped.service.PluginService.DecryptSecret:output_type -> grpc.piped.service.DecryptSecretResponse - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type + 2, // 1: grpc.piped.service.PluginService.InstallTool:input_type -> grpc.piped.service.InstallToolRequest + 1, // 2: grpc.piped.service.PluginService.DecryptSecret:output_type -> grpc.piped.service.DecryptSecretResponse + 3, // 3: grpc.piped.service.PluginService.InstallTool:output_type -> grpc.piped.service.InstallToolResponse + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -217,6 +368,30 @@ func file_pkg_app_pipedv1_cmd_piped_service_service_proto_init() { return nil } } + file_pkg_app_pipedv1_cmd_piped_service_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*InstallToolRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_pkg_app_pipedv1_cmd_piped_service_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*InstallToolResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -224,7 +399,7 @@ func file_pkg_app_pipedv1_cmd_piped_service_service_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_pkg_app_pipedv1_cmd_piped_service_service_proto_rawDesc, NumEnums: 0, - NumMessages: 2, + NumMessages: 4, NumExtensions: 0, NumServices: 1, }, diff --git a/pkg/app/pipedv1/cmd/piped/service/service.pb.validate.go b/pkg/app/pipedv1/cmd/piped/service/service.pb.validate.go index 2bf6916868..a81734ec1a 100644 --- a/pkg/app/pipedv1/cmd/piped/service/service.pb.validate.go +++ b/pkg/app/pipedv1/cmd/piped/service/service.pb.validate.go @@ -251,3 +251,242 @@ var _ interface { Cause() error ErrorName() string } = DecryptSecretResponseValidationError{} + +// Validate checks the field values on InstallToolRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *InstallToolRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on InstallToolRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// InstallToolRequestMultiError, or nil if none found. +func (m *InstallToolRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *InstallToolRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if utf8.RuneCountInString(m.GetName()) < 1 { + err := InstallToolRequestValidationError{ + field: "Name", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } + + if utf8.RuneCountInString(m.GetVersion()) < 1 { + err := InstallToolRequestValidationError{ + field: "Version", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } + + if utf8.RuneCountInString(m.GetInstallScript()) < 1 { + err := InstallToolRequestValidationError{ + field: "InstallScript", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } + + if len(errors) > 0 { + return InstallToolRequestMultiError(errors) + } + + return nil +} + +// InstallToolRequestMultiError is an error wrapping multiple validation errors +// returned by InstallToolRequest.ValidateAll() if the designated constraints +// aren't met. +type InstallToolRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m InstallToolRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m InstallToolRequestMultiError) AllErrors() []error { return m } + +// InstallToolRequestValidationError is the validation error returned by +// InstallToolRequest.Validate if the designated constraints aren't met. +type InstallToolRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e InstallToolRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e InstallToolRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e InstallToolRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e InstallToolRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e InstallToolRequestValidationError) ErrorName() string { + return "InstallToolRequestValidationError" +} + +// Error satisfies the builtin error interface +func (e InstallToolRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sInstallToolRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = InstallToolRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = InstallToolRequestValidationError{} + +// Validate checks the field values on InstallToolResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *InstallToolResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on InstallToolResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// InstallToolResponseMultiError, or nil if none found. +func (m *InstallToolResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *InstallToolResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + // no validation rules for InstalledPath + + if len(errors) > 0 { + return InstallToolResponseMultiError(errors) + } + + return nil +} + +// InstallToolResponseMultiError is an error wrapping multiple validation +// errors returned by InstallToolResponse.ValidateAll() if the designated +// constraints aren't met. +type InstallToolResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m InstallToolResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m InstallToolResponseMultiError) AllErrors() []error { return m } + +// InstallToolResponseValidationError is the validation error returned by +// InstallToolResponse.Validate if the designated constraints aren't met. +type InstallToolResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e InstallToolResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e InstallToolResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e InstallToolResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e InstallToolResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e InstallToolResponseValidationError) ErrorName() string { + return "InstallToolResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e InstallToolResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sInstallToolResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = InstallToolResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = InstallToolResponseValidationError{} diff --git a/pkg/app/pipedv1/cmd/piped/service/service.proto b/pkg/app/pipedv1/cmd/piped/service/service.proto index 83d7f8a76e..777ae9d3eb 100644 --- a/pkg/app/pipedv1/cmd/piped/service/service.proto +++ b/pkg/app/pipedv1/cmd/piped/service/service.proto @@ -23,6 +23,9 @@ import "validate/validate.proto"; service PluginService { // DecryptSecret decrypts the given secret. rpc DecryptSecret(DecryptSecretRequest) returns (DecryptSecretResponse) {} + // InstallTool installs the given tool. + // installed binary's filename becomes `name-version`. + rpc InstallTool(InstallToolRequest) returns (InstallToolResponse) {} } message DecryptSecretRequest { @@ -32,3 +35,31 @@ message DecryptSecretRequest { message DecryptSecretResponse { string decrypted_secret = 1; } + +message InstallToolRequest { + // Name of the tool. + string name = 1 [(validate.rules).string.min_len = 1]; + // Version of the tool. + string version = 2 [(validate.rules).string.min_len = 1]; + // Install script to install the tool. + // This script is templated with the following variables: + // - {{ .Name }}: name of the tool. + // - {{ .Version }}: version of the tool. + // - {{ .OutPath }}: file path where the tool will be installed. + // - {{ .TmpDir }}: directory where the tool will be downloaded and extracted. + // - {{ .Arch }}: GOARCH of the current machine. + // - {{ .Os }}: GOOS of the current machine. + // + // The script should return 0 if the installation is successful. + // Otherwise, it should return a non-zero value. + // + // The tool should be placed at {{ .OutPath }} + // e.g.) cp path/to/kubectl {{ .OutPath }} + // Then piped move it to the correct directory / filename and make it executable. + string install_script = 3 [(validate.rules).string.min_len = 1]; +} + +message InstallToolResponse { + // Installed path of the tool. + string installed_path = 1; +} diff --git a/pkg/app/pipedv1/cmd/piped/service/service_grpc.pb.go b/pkg/app/pipedv1/cmd/piped/service/service_grpc.pb.go index 62538ebf0c..9ccc290e02 100644 --- a/pkg/app/pipedv1/cmd/piped/service/service_grpc.pb.go +++ b/pkg/app/pipedv1/cmd/piped/service/service_grpc.pb.go @@ -24,6 +24,9 @@ const _ = grpc.SupportPackageIsVersion7 type PluginServiceClient interface { // DecryptSecret decrypts the given secret. DecryptSecret(ctx context.Context, in *DecryptSecretRequest, opts ...grpc.CallOption) (*DecryptSecretResponse, error) + // InstallTool installs the given tool. + // installed binary's filename becomes `name-version`. + InstallTool(ctx context.Context, in *InstallToolRequest, opts ...grpc.CallOption) (*InstallToolResponse, error) } type pluginServiceClient struct { @@ -43,12 +46,24 @@ func (c *pluginServiceClient) DecryptSecret(ctx context.Context, in *DecryptSecr return out, nil } +func (c *pluginServiceClient) InstallTool(ctx context.Context, in *InstallToolRequest, opts ...grpc.CallOption) (*InstallToolResponse, error) { + out := new(InstallToolResponse) + err := c.cc.Invoke(ctx, "/grpc.piped.service.PluginService/InstallTool", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // PluginServiceServer is the server API for PluginService service. // All implementations must embed UnimplementedPluginServiceServer // for forward compatibility type PluginServiceServer interface { // DecryptSecret decrypts the given secret. DecryptSecret(context.Context, *DecryptSecretRequest) (*DecryptSecretResponse, error) + // InstallTool installs the given tool. + // installed binary's filename becomes `name-version`. + InstallTool(context.Context, *InstallToolRequest) (*InstallToolResponse, error) mustEmbedUnimplementedPluginServiceServer() } @@ -59,6 +74,9 @@ type UnimplementedPluginServiceServer struct { func (UnimplementedPluginServiceServer) DecryptSecret(context.Context, *DecryptSecretRequest) (*DecryptSecretResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method DecryptSecret not implemented") } +func (UnimplementedPluginServiceServer) InstallTool(context.Context, *InstallToolRequest) (*InstallToolResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method InstallTool not implemented") +} func (UnimplementedPluginServiceServer) mustEmbedUnimplementedPluginServiceServer() {} // UnsafePluginServiceServer may be embedded to opt out of forward compatibility for this service. @@ -90,6 +108,24 @@ func _PluginService_DecryptSecret_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } +func _PluginService_InstallTool_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(InstallToolRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PluginServiceServer).InstallTool(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/grpc.piped.service.PluginService/InstallTool", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PluginServiceServer).InstallTool(ctx, req.(*InstallToolRequest)) + } + return interceptor(ctx, in, info, handler) +} + // PluginService_ServiceDesc is the grpc.ServiceDesc for PluginService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -101,6 +137,10 @@ var PluginService_ServiceDesc = grpc.ServiceDesc{ MethodName: "DecryptSecret", Handler: _PluginService_DecryptSecret_Handler, }, + { + MethodName: "InstallTool", + Handler: _PluginService_InstallTool_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "pkg/app/pipedv1/cmd/piped/service/service.proto",