From 86a0f2f1b85d891ab06448170e2091700f4b36c2 Mon Sep 17 00:00:00 2001 From: Ihar Kryvanos Date: Tue, 26 Nov 2024 11:48:59 +0100 Subject: [PATCH 1/7] Add option to overwrite dial address --- services/httpoverrpc/httpoverrpc.pb.go | 210 ++++++++++++++------ services/httpoverrpc/httpoverrpc.proto | 7 + services/httpoverrpc/httpoverrpc_grpc.pb.go | 34 +++- services/httpoverrpc/server/server.go | 42 +++- services/httpoverrpc/server/server_test.go | 55 ++++- 5 files changed, 261 insertions(+), 87 deletions(-) diff --git a/services/httpoverrpc/httpoverrpc.pb.go b/services/httpoverrpc/httpoverrpc.pb.go index f5e40e8a..3299f9e5 100644 --- a/services/httpoverrpc/httpoverrpc.pb.go +++ b/services/httpoverrpc/httpoverrpc.pb.go @@ -15,8 +15,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.32.0 -// protoc v5.27.1 +// protoc-gen-go v1.34.2 +// protoc v5.28.1 // source: httpoverrpc.proto package httpoverrpc @@ -50,6 +50,8 @@ type HostHTTPRequest struct { Protocol string `protobuf:"bytes,4,opt,name=protocol,proto3" json:"protocol,omitempty"` // TLS Config for the request Tlsconfig *TLSConfig `protobuf:"bytes,5,opt,name=tlsconfig,proto3" json:"tlsconfig,omitempty"` + // Dial Config for request, if not provided uses default dialer configuration + Dialconfig *DialConfig `protobuf:"bytes,6,opt,name=dialconfig,proto3" json:"dialconfig,omitempty"` } func (x *HostHTTPRequest) Reset() { @@ -119,6 +121,13 @@ func (x *HostHTTPRequest) GetTlsconfig() *TLSConfig { return nil } +func (x *HostHTTPRequest) GetDialconfig() *DialConfig { + if x != nil { + return x.Dialconfig + } + return nil +} + type TLSConfig struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -167,6 +176,54 @@ func (x *TLSConfig) GetInsecureSkipVerify() bool { return false } +type DialConfig struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // address to dial to, if not provided uses original one + DialAddress string `protobuf:"bytes,1,opt,name=dialAddress,proto3" json:"dialAddress,omitempty"` +} + +func (x *DialConfig) Reset() { + *x = DialConfig{} + if protoimpl.UnsafeEnabled { + mi := &file_httpoverrpc_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DialConfig) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DialConfig) ProtoMessage() {} + +func (x *DialConfig) ProtoReflect() protoreflect.Message { + mi := &file_httpoverrpc_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 DialConfig.ProtoReflect.Descriptor instead. +func (*DialConfig) Descriptor() ([]byte, []int) { + return file_httpoverrpc_proto_rawDescGZIP(), []int{2} +} + +func (x *DialConfig) GetDialAddress() string { + if x != nil { + return x.DialAddress + } + return "" +} + type Header struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -179,7 +236,7 @@ type Header struct { func (x *Header) Reset() { *x = Header{} if protoimpl.UnsafeEnabled { - mi := &file_httpoverrpc_proto_msgTypes[2] + mi := &file_httpoverrpc_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -192,7 +249,7 @@ func (x *Header) String() string { func (*Header) ProtoMessage() {} func (x *Header) ProtoReflect() protoreflect.Message { - mi := &file_httpoverrpc_proto_msgTypes[2] + mi := &file_httpoverrpc_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -205,7 +262,7 @@ func (x *Header) ProtoReflect() protoreflect.Message { // Deprecated: Use Header.ProtoReflect.Descriptor instead. func (*Header) Descriptor() ([]byte, []int) { - return file_httpoverrpc_proto_rawDescGZIP(), []int{2} + return file_httpoverrpc_proto_rawDescGZIP(), []int{3} } func (x *Header) GetKey() string { @@ -237,7 +294,7 @@ type HTTPRequest struct { func (x *HTTPRequest) Reset() { *x = HTTPRequest{} if protoimpl.UnsafeEnabled { - mi := &file_httpoverrpc_proto_msgTypes[3] + mi := &file_httpoverrpc_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -250,7 +307,7 @@ func (x *HTTPRequest) String() string { func (*HTTPRequest) ProtoMessage() {} func (x *HTTPRequest) ProtoReflect() protoreflect.Message { - mi := &file_httpoverrpc_proto_msgTypes[3] + mi := &file_httpoverrpc_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -263,7 +320,7 @@ func (x *HTTPRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use HTTPRequest.ProtoReflect.Descriptor instead. func (*HTTPRequest) Descriptor() ([]byte, []int) { - return file_httpoverrpc_proto_rawDescGZIP(), []int{3} + return file_httpoverrpc_proto_rawDescGZIP(), []int{4} } func (x *HTTPRequest) GetMethod() string { @@ -308,7 +365,7 @@ type HTTPReply struct { func (x *HTTPReply) Reset() { *x = HTTPReply{} if protoimpl.UnsafeEnabled { - mi := &file_httpoverrpc_proto_msgTypes[4] + mi := &file_httpoverrpc_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -321,7 +378,7 @@ func (x *HTTPReply) String() string { func (*HTTPReply) ProtoMessage() {} func (x *HTTPReply) ProtoReflect() protoreflect.Message { - mi := &file_httpoverrpc_proto_msgTypes[4] + mi := &file_httpoverrpc_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -334,7 +391,7 @@ func (x *HTTPReply) ProtoReflect() protoreflect.Message { // Deprecated: Use HTTPReply.ProtoReflect.Descriptor instead. func (*HTTPReply) Descriptor() ([]byte, []int) { - return file_httpoverrpc_proto_rawDescGZIP(), []int{4} + return file_httpoverrpc_proto_rawDescGZIP(), []int{5} } func (x *HTTPReply) GetStatusCode() int32 { @@ -365,7 +422,7 @@ var file_httpoverrpc_proto_rawDesc = []byte{ 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0xc7, 0x01, 0x0a, 0x0f, 0x48, 0x6f, 0x73, 0x74, 0x48, 0x54, 0x54, 0x50, 0x52, + 0x74, 0x6f, 0x22, 0x80, 0x02, 0x0a, 0x0f, 0x48, 0x6f, 0x73, 0x74, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x32, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, @@ -377,39 +434,46 @@ var file_httpoverrpc_proto_rawDesc = []byte{ 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x34, 0x0a, 0x09, 0x74, 0x6c, 0x73, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x54, 0x4c, 0x53, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x52, 0x09, 0x74, 0x6c, 0x73, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x22, 0x3b, 0x0a, 0x09, - 0x54, 0x4c, 0x53, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x2e, 0x0a, 0x12, 0x69, 0x6e, 0x73, - 0x65, 0x63, 0x75, 0x72, 0x65, 0x53, 0x6b, 0x69, 0x70, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x53, - 0x6b, 0x69, 0x70, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x22, 0x37, 0x0a, 0x06, 0x48, 0x65, 0x61, - 0x64, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, - 0x02, 0x20, 0x03, 0x28, 0x09, 0x42, 0x03, 0x80, 0x01, 0x01, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x73, 0x22, 0x8e, 0x01, 0x0a, 0x0b, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x75, 0x72, 0x69, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x55, 0x72, 0x69, 0x12, 0x2d, 0x0a, 0x07, 0x68, - 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x48, - 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, - 0x72, 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x17, 0x0a, 0x04, 0x62, 0x6f, - 0x64, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x03, 0x80, 0x01, 0x01, 0x52, 0x04, 0x62, - 0x6f, 0x64, 0x79, 0x22, 0x6f, 0x0a, 0x09, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x70, 0x6c, 0x79, - 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, - 0x65, 0x12, 0x2d, 0x0a, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, - 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, - 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, - 0x62, 0x6f, 0x64, 0x79, 0x32, 0x4d, 0x0a, 0x0b, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, - 0x52, 0x50, 0x43, 0x12, 0x3e, 0x0a, 0x04, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x2e, 0x48, 0x54, - 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x48, 0x6f, 0x73, 0x74, 0x48, 0x54, - 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x48, 0x54, 0x54, 0x50, - 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x70, 0x6c, - 0x79, 0x22, 0x00, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x53, 0x6e, 0x6f, 0x77, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x2d, 0x4c, 0x61, 0x62, 0x73, - 0x2f, 0x73, 0x61, 0x6e, 0x73, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x6f, - 0x76, 0x65, 0x72, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x67, 0x52, 0x09, 0x74, 0x6c, 0x73, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x37, 0x0a, 0x0a, + 0x64, 0x69, 0x61, 0x6c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x17, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x44, + 0x69, 0x61, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0a, 0x64, 0x69, 0x61, 0x6c, 0x63, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x22, 0x3b, 0x0a, 0x09, 0x54, 0x4c, 0x53, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x12, 0x2e, 0x0a, 0x12, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x53, 0x6b, + 0x69, 0x70, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, + 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x53, 0x6b, 0x69, 0x70, 0x56, 0x65, 0x72, 0x69, + 0x66, 0x79, 0x22, 0x2e, 0x0a, 0x0a, 0x44, 0x69, 0x61, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x69, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x69, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x22, 0x37, 0x0a, 0x06, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1b, + 0x0a, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x42, 0x03, + 0x80, 0x01, 0x01, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, 0x8e, 0x01, 0x0a, 0x0b, + 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6d, + 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, + 0x68, 0x6f, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x75, + 0x72, 0x69, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x55, 0x72, 0x69, 0x12, 0x2d, 0x0a, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, + 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, + 0x52, 0x50, 0x43, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, + 0x65, 0x72, 0x73, 0x12, 0x17, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x0c, 0x42, 0x03, 0x80, 0x01, 0x01, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x22, 0x6f, 0x0a, 0x09, + 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, + 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x2d, 0x0a, 0x07, 0x68, 0x65, + 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x48, 0x54, + 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, + 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, + 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x32, 0x4d, 0x0a, + 0x0b, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x12, 0x3e, 0x0a, 0x04, + 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, + 0x50, 0x43, 0x2e, 0x48, 0x6f, 0x73, 0x74, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, + 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x31, 0x5a, 0x2f, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x53, 0x6e, 0x6f, 0x77, 0x66, + 0x6c, 0x61, 0x6b, 0x65, 0x2d, 0x4c, 0x61, 0x62, 0x73, 0x2f, 0x73, 0x61, 0x6e, 0x73, 0x73, 0x68, + 0x65, 0x6c, 0x6c, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x70, 0x63, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -424,26 +488,28 @@ func file_httpoverrpc_proto_rawDescGZIP() []byte { return file_httpoverrpc_proto_rawDescData } -var file_httpoverrpc_proto_msgTypes = make([]protoimpl.MessageInfo, 5) -var file_httpoverrpc_proto_goTypes = []interface{}{ +var file_httpoverrpc_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_httpoverrpc_proto_goTypes = []any{ (*HostHTTPRequest)(nil), // 0: HTTPOverRPC.HostHTTPRequest (*TLSConfig)(nil), // 1: HTTPOverRPC.TLSConfig - (*Header)(nil), // 2: HTTPOverRPC.Header - (*HTTPRequest)(nil), // 3: HTTPOverRPC.HTTPRequest - (*HTTPReply)(nil), // 4: HTTPOverRPC.HTTPReply + (*DialConfig)(nil), // 2: HTTPOverRPC.DialConfig + (*Header)(nil), // 3: HTTPOverRPC.Header + (*HTTPRequest)(nil), // 4: HTTPOverRPC.HTTPRequest + (*HTTPReply)(nil), // 5: HTTPOverRPC.HTTPReply } var file_httpoverrpc_proto_depIdxs = []int32{ - 3, // 0: HTTPOverRPC.HostHTTPRequest.request:type_name -> HTTPOverRPC.HTTPRequest + 4, // 0: HTTPOverRPC.HostHTTPRequest.request:type_name -> HTTPOverRPC.HTTPRequest 1, // 1: HTTPOverRPC.HostHTTPRequest.tlsconfig:type_name -> HTTPOverRPC.TLSConfig - 2, // 2: HTTPOverRPC.HTTPRequest.headers:type_name -> HTTPOverRPC.Header - 2, // 3: HTTPOverRPC.HTTPReply.headers:type_name -> HTTPOverRPC.Header - 0, // 4: HTTPOverRPC.HTTPOverRPC.Host:input_type -> HTTPOverRPC.HostHTTPRequest - 4, // 5: HTTPOverRPC.HTTPOverRPC.Host:output_type -> HTTPOverRPC.HTTPReply - 5, // [5:6] is the sub-list for method output_type - 4, // [4:5] 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 + 2, // 2: HTTPOverRPC.HostHTTPRequest.dialconfig:type_name -> HTTPOverRPC.DialConfig + 3, // 3: HTTPOverRPC.HTTPRequest.headers:type_name -> HTTPOverRPC.Header + 3, // 4: HTTPOverRPC.HTTPReply.headers:type_name -> HTTPOverRPC.Header + 0, // 5: HTTPOverRPC.HTTPOverRPC.Host:input_type -> HTTPOverRPC.HostHTTPRequest + 5, // 6: HTTPOverRPC.HTTPOverRPC.Host:output_type -> HTTPOverRPC.HTTPReply + 6, // [6:7] is the sub-list for method output_type + 5, // [5:6] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_httpoverrpc_proto_init() } @@ -452,7 +518,7 @@ func file_httpoverrpc_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_httpoverrpc_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_httpoverrpc_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*HostHTTPRequest); i { case 0: return &v.state @@ -464,7 +530,7 @@ func file_httpoverrpc_proto_init() { return nil } } - file_httpoverrpc_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_httpoverrpc_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*TLSConfig); i { case 0: return &v.state @@ -476,7 +542,19 @@ func file_httpoverrpc_proto_init() { return nil } } - file_httpoverrpc_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_httpoverrpc_proto_msgTypes[2].Exporter = func(v any, i int) any { + switch v := v.(*DialConfig); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_httpoverrpc_proto_msgTypes[3].Exporter = func(v any, i int) any { switch v := v.(*Header); i { case 0: return &v.state @@ -488,7 +566,7 @@ func file_httpoverrpc_proto_init() { return nil } } - file_httpoverrpc_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_httpoverrpc_proto_msgTypes[4].Exporter = func(v any, i int) any { switch v := v.(*HTTPRequest); i { case 0: return &v.state @@ -500,7 +578,7 @@ func file_httpoverrpc_proto_init() { return nil } } - file_httpoverrpc_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_httpoverrpc_proto_msgTypes[5].Exporter = func(v any, i int) any { switch v := v.(*HTTPReply); i { case 0: return &v.state @@ -519,7 +597,7 @@ func file_httpoverrpc_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_httpoverrpc_proto_rawDesc, NumEnums: 0, - NumMessages: 5, + NumMessages: 6, NumExtensions: 0, NumServices: 1, }, diff --git a/services/httpoverrpc/httpoverrpc.proto b/services/httpoverrpc/httpoverrpc.proto index 9a73c7fa..ec34f4ae 100644 --- a/services/httpoverrpc/httpoverrpc.proto +++ b/services/httpoverrpc/httpoverrpc.proto @@ -38,6 +38,8 @@ message HostHTTPRequest { string protocol = 4; // TLS Config for the request TLSConfig tlsconfig = 5; + // Dial Config for request, if not provided uses default dialer configuration + DialConfig dialconfig = 6; } message TLSConfig { @@ -45,6 +47,11 @@ message TLSConfig { bool insecureSkipVerify = 1; } +message DialConfig { + // address to dial to, if not provided uses original one + string dialAddress = 1; +} + message Header { string key = 1; repeated string values = 2 [debug_redact = true]; diff --git a/services/httpoverrpc/httpoverrpc_grpc.pb.go b/services/httpoverrpc/httpoverrpc_grpc.pb.go index 78343753..a696e5f8 100644 --- a/services/httpoverrpc/httpoverrpc_grpc.pb.go +++ b/services/httpoverrpc/httpoverrpc_grpc.pb.go @@ -15,8 +15,8 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.3.0 -// - protoc v5.27.1 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.28.1 // source: httpoverrpc.proto package httpoverrpc @@ -30,8 +30,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 ( HTTPOverRPC_Host_FullMethodName = "/HTTPOverRPC.HTTPOverRPC/Host" @@ -40,6 +40,8 @@ const ( // HTTPOverRPCClient is the client API for HTTPOverRPC service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// The HTTPOverRPC service definition type HTTPOverRPCClient interface { // Make an HTTP call to specified host Host(ctx context.Context, in *HostHTTPRequest, opts ...grpc.CallOption) (*HTTPReply, error) @@ -54,8 +56,9 @@ func NewHTTPOverRPCClient(cc grpc.ClientConnInterface) HTTPOverRPCClient { } func (c *hTTPOverRPCClient) Host(ctx context.Context, in *HostHTTPRequest, opts ...grpc.CallOption) (*HTTPReply, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(HTTPReply) - err := c.cc.Invoke(ctx, HTTPOverRPC_Host_FullMethodName, in, out, opts...) + err := c.cc.Invoke(ctx, HTTPOverRPC_Host_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -64,19 +67,25 @@ func (c *hTTPOverRPCClient) Host(ctx context.Context, in *HostHTTPRequest, opts // HTTPOverRPCServer is the server API for HTTPOverRPC service. // All implementations should embed UnimplementedHTTPOverRPCServer -// for forward compatibility +// for forward compatibility. +// +// The HTTPOverRPC service definition type HTTPOverRPCServer interface { // Make an HTTP call to specified host Host(context.Context, *HostHTTPRequest) (*HTTPReply, error) } -// UnimplementedHTTPOverRPCServer should be embedded to have forward compatible implementations. -type UnimplementedHTTPOverRPCServer struct { -} +// UnimplementedHTTPOverRPCServer should 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 UnimplementedHTTPOverRPCServer struct{} func (UnimplementedHTTPOverRPCServer) Host(context.Context, *HostHTTPRequest) (*HTTPReply, error) { return nil, status.Errorf(codes.Unimplemented, "method Host not implemented") } +func (UnimplementedHTTPOverRPCServer) testEmbeddedByValue() {} // UnsafeHTTPOverRPCServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to HTTPOverRPCServer will @@ -86,6 +95,13 @@ type UnsafeHTTPOverRPCServer interface { } func RegisterHTTPOverRPCServer(s grpc.ServiceRegistrar, srv HTTPOverRPCServer) { + // If the following call pancis, it indicates UnimplementedHTTPOverRPCServer 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(&HTTPOverRPC_ServiceDesc, srv) } diff --git a/services/httpoverrpc/server/server.go b/services/httpoverrpc/server/server.go index 87d864b8..3f527ce7 100644 --- a/services/httpoverrpc/server/server.go +++ b/services/httpoverrpc/server/server.go @@ -22,16 +22,19 @@ import ( "context" "crypto/tls" "fmt" + "io" + "net" + "net/http" + "strings" + + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/Snowflake-Labs/sansshell/services" pb "github.com/Snowflake-Labs/sansshell/services/httpoverrpc" sansshellserver "github.com/Snowflake-Labs/sansshell/services/sansshell/server" "github.com/Snowflake-Labs/sansshell/telemetry/metrics" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - "io" - "net/http" - "strings" ) // Metrics @@ -43,6 +46,8 @@ var ( // Server is used to implement the gRPC Server type server struct{} +type netDialerContextFn func(ctx context.Context, network, addr string) (net.Conn, error) + func (s *server) Host(ctx context.Context, req *pb.HostHTTPRequest) (*pb.HTTPReply, error) { recorder := metrics.RecorderFromContextOrNoop(ctx) @@ -73,13 +78,30 @@ func (s *server) Host(ctx context.Context, req *pb.HostHTTPRequest) (*pb.HTTPRep } client := &http.Client{} - if req.Tlsconfig != nil { - client.Transport = &http.Transport{ - TLSClientConfig: &tls.Config{ + + if req.Tlsconfig != nil || req.Dialconfig != nil { + transport := &http.Transport{} + + if req.Tlsconfig != nil { + transport.TLSClientConfig = &tls.Config{ InsecureSkipVerify: req.Tlsconfig.InsecureSkipVerify, - }, + } } + + if req.Dialconfig != nil { + transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { + dailAddress := addr + if req.Dialconfig.GetDialAddress() != "" { + dailAddress = req.Dialconfig.GetDialAddress() + } + + return net.Dial(network, dailAddress) + } + } + + client.Transport = transport } + client.CheckRedirect = func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse } httpResp, err := client.Do(httpReq) diff --git a/services/httpoverrpc/server/server_test.go b/services/httpoverrpc/server/server_test.go index 9a252861..0afe718d 100644 --- a/services/httpoverrpc/server/server_test.go +++ b/services/httpoverrpc/server/server_test.go @@ -29,14 +29,15 @@ import ( "strconv" "testing" - "github.com/Snowflake-Labs/sansshell/services/httpoverrpc" - "github.com/Snowflake-Labs/sansshell/testing/testutil" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/test/bufconn" "google.golang.org/protobuf/testing/protocmp" + + "github.com/Snowflake-Labs/sansshell/services/httpoverrpc" + "github.com/Snowflake-Labs/sansshell/testing/testutil" ) var ( @@ -286,4 +287,54 @@ func TestServer(t *testing.T) { t.Fatalf("Expected response body to be %q, got %q", customHostHeader, resp.Body) } }) + + t.Run("It should dail host provided in dialconfig and ignore host from url", func(t *testing.T) { + // ARRANGE + var err error + ctx := context.Background() + conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(bufDialer), grpc.WithTransportCredentials(insecure.NewCredentials())) + testutil.FatalOnErr("Failed to dial bufnet", err, t) + t.Cleanup(func() { conn.Close() }) + + client := httpoverrpc.NewHTTPOverRPCClient(conn) + + // Set up web server + m := http.NewServeMux() + uri := "/endpoint" + expectedResponse := "Ok" + m.HandleFunc(uri, func(httpResp http.ResponseWriter, httpReq *http.Request) { + _, _ = httpResp.Write([]byte(expectedResponse)) + }) + l, err := net.Listen("tcp4", "localhost:0") + if err != nil { + t.Fatal(err) + } + go func() { _ = http.Serve(l, m) }() + + addressToDial := l.Addr().String() + targetHost := "example.com" + targetPort := 8080 + + // ACT + resp, err := client.Host(ctx, &httpoverrpc.HostHTTPRequest{ + Request: &httpoverrpc.HTTPRequest{ + Method: "GET", + RequestUri: uri, + }, + Port: int32(targetPort), + Hostname: targetHost, + Protocol: "http", + Dialconfig: &httpoverrpc.DialConfig{ + DialAddress: addressToDial, + }, + }) + if err != nil { + t.Fatal(err) + } + + // ASSERT + if string(resp.Body) != expectedResponse { + t.Fatalf("Expected response body to be %q, got %q", expectedResponse, resp.Body) + } + }) } From 4e1cbab81946f07df1ae133d4cc637c10d90eec2 Mon Sep 17 00:00:00 2001 From: Ihar Kryvanos Date: Tue, 26 Nov 2024 12:27:33 +0100 Subject: [PATCH 2/7] Add readme and update client code --- services/httpoverrpc/README.md | 26 +++++++ services/httpoverrpc/client/client.go | 29 ++++++- services/httpoverrpc/client/utils.go | 18 ++++- services/httpoverrpc/httpoverrpc.pb.go | 90 +++++++++++----------- services/httpoverrpc/httpoverrpc.proto | 4 +- services/httpoverrpc/server/server.go | 2 +- services/httpoverrpc/server/server_test.go | 2 +- 7 files changed, 119 insertions(+), 52 deletions(-) create mode 100644 services/httpoverrpc/README.md diff --git a/services/httpoverrpc/README.md b/services/httpoverrpc/README.md new file mode 100644 index 00000000..c818e330 --- /dev/null +++ b/services/httpoverrpc/README.md @@ -0,0 +1,26 @@ +# HTTPOVERRPC +This directory contains the http over rpc services. It is a simple service that allows to send http requests to from target hosts + + +## Usage + +### sanssh httpoverrpc get +Make a HTTP(-S) request to a specified port on the remote host. + +```bash +sanssh get [-method ] [-header
] [-dialAddress ] [-insecure-skip-tls-verify] [-show-response-headers] [-body ] [-protocol ] [-hostname ] : +``` + +Where: +- `` body to send in request +- `` host:port to dial to. If not provided would dial to original host and port +- `
` Header to send in the request, may be specified multiple times. +- `` ip address or domain name to specify host (default "localhost") +- `` method to use in the HTTP request (default "GET") +- `` protocol to communicate with specified hostname (default "http") +- `` port to connect to on the remote host +- `` URI to request + +Flags: +- `-show-response-headers` If provided, print response code and headers +- `-insecure-skip-tls-verify` If provided, skip TLS verification diff --git a/services/httpoverrpc/client/client.go b/services/httpoverrpc/client/client.go index 210e88e9..eb578a39 100644 --- a/services/httpoverrpc/client/client.go +++ b/services/httpoverrpc/client/client.go @@ -35,6 +35,7 @@ import ( "github.com/Snowflake-Labs/sansshell/client" pb "github.com/Snowflake-Labs/sansshell/services/httpoverrpc" "github.com/Snowflake-Labs/sansshell/services/util" + "github.com/Snowflake-Labs/sansshell/services/util/validator" ) const subPackage = "httpoverrpc" @@ -226,16 +227,20 @@ type getCmd struct { protocol string hostname string insecureSkipVerify bool + dialAddress string } func (*getCmd) Name() string { return "get" } -func (*getCmd) Synopsis() string { return "Makes a HTTP call to a port on a remote host" } +func (*getCmd) Synopsis() string { return "Makes a HTTP(-S) call to a port on a remote host" } func (*getCmd) Usage() string { - return `get [-method METHOD] [-header Header...] [-body body] [-protocol Protocol] [-hostname Hostname] remoteport request_uri: + return `get [-method METHOD] [-header Header...] [-dialAddress dialAddress] [-body body] [-protocol Protocol] [-hostname Hostname] remoteport request_uri: Make a HTTP request to a specified port on the remote host. - Example: + Examples: + # send get request to https://localhost:9090/hello httpoverrpc get --hostname 10.1.23.4 --protocol https 9090 /hello + # send get request with url http://example.com:9090/hello, but deal to localhost:9090 + httpoverrpc get --hostname example.com --dialAddress localhost:9090 9090 /hello Note: 1. The prefix / in request_uri is always needed, even there is nothing to put @@ -252,6 +257,7 @@ func (g *getCmd) SetFlags(f *flag.FlagSet) { f.StringVar(&g.body, "body", "", "Body to send in request") f.BoolVar(&g.showResponseHeaders, "show-response-headers", false, "If true, print response code and headers") f.BoolVar(&g.insecureSkipVerify, "insecure-skip-tls-verify", false, "If true, skip TLS cert verification") + f.StringVar(&g.dialAddress, "dial-address", "", "host:port to dial to. If not provided would dial to original host and port") } func (g *getCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { @@ -270,6 +276,14 @@ func (g *getCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface return subcommands.ExitUsageError } + if g.dialAddress != "" { + _, _, err := validator.ParseHostAndPort(g.dialAddress) + if err != nil { + fmt.Fprintf(os.Stderr, "Unable to parse dial address \"%q\": %v\n", g.dialAddress, err) + return subcommands.ExitUsageError + } + } + var reqHeaders []*pb.Header for _, v := range g.headers { split := strings.SplitN(v, ":", 2) @@ -280,7 +294,12 @@ func (g *getCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface reqHeaders = append(reqHeaders, &pb.Header{Key: split[0], Values: []string{strings.TrimSpace(split[1])}}) } - proxy := pb.NewHTTPOverRPCClientProxy(state.Conn) + var dialConfig *pb.DialConfig = nil + if g.dialAddress != "" { + dialConfig = &pb.DialConfig{ + DialAddress: &g.dialAddress, + } + } req := &pb.HostHTTPRequest{ Request: &pb.HTTPRequest{ @@ -295,8 +314,10 @@ func (g *getCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface Tlsconfig: &pb.TLSConfig{ InsecureSkipVerify: g.insecureSkipVerify, }, + Dialconfig: dialConfig, } + proxy := pb.NewHTTPOverRPCClientProxy(state.Conn) resp, err := proxy.HostOneMany(ctx, req) retCode := subcommands.ExitSuccess if err != nil { diff --git a/services/httpoverrpc/client/utils.go b/services/httpoverrpc/client/utils.go index f6f81023..1d6e4e86 100644 --- a/services/httpoverrpc/client/utils.go +++ b/services/httpoverrpc/client/utils.go @@ -38,13 +38,16 @@ var ( errInvalidURLMissingHost = fmt.Errorf("no host in the request URL") ) +// HTTPTransporter implementation of [http.RoundTripper], which proxy HTTP requests over RPC to target host to send request from it type HTTPTransporter struct { conn *proxy.Conn insecureSkipVerify bool + dialConfigFactory func(req http.Request) *pb.DialConfig } type httpTransporterOptions struct { insecureSkipVerify bool + dialConfigFactory func(req http.Request) *pb.DialConfig } type Option interface { @@ -63,7 +66,13 @@ func WithInsecureSkipVerify(insecureSkipVerify bool) Option { }) } -func NewHTTPTransporter(conn *proxy.Conn, opts ...Option) *HTTPTransporter { +func WithCustomDialConfig(dialConfigFactory func(req http.Request) *pb.DialConfig) Option { + return optionFunc(func(o *httpTransporterOptions) { + o.dialConfigFactory = dialConfigFactory + }) +} + +func NewHTTPTransporter(conn *proxy.Conn, opts ...Option) http.RoundTripper { options := &httpTransporterOptions{ insecureSkipVerify: false, } @@ -74,6 +83,7 @@ func NewHTTPTransporter(conn *proxy.Conn, opts ...Option) *HTTPTransporter { return &HTTPTransporter{ conn: conn, insecureSkipVerify: options.insecureSkipVerify, + dialConfigFactory: options.dialConfigFactory, } } @@ -152,6 +162,11 @@ func (c *HTTPTransporter) RoundTrip(req *http.Request) (*http.Response, error) { return nil, err } } + + var dialConfig *pb.DialConfig = nil + if c.dialConfigFactory != nil { + dialConfig = c.dialConfigFactory(*req) + } reqPb := &pb.HostHTTPRequest{ Request: &pb.HTTPRequest{ RequestUri: req.URL.RequestURI(), @@ -164,6 +179,7 @@ func (c *HTTPTransporter) RoundTrip(req *http.Request) (*http.Response, error) { Tlsconfig: &pb.TLSConfig{ InsecureSkipVerify: c.insecureSkipVerify, }, + Dialconfig: dialConfig, } port, errPort := getPort(req, reqPb.Protocol) diff --git a/services/httpoverrpc/httpoverrpc.pb.go b/services/httpoverrpc/httpoverrpc.pb.go index 3299f9e5..1011ec0f 100644 --- a/services/httpoverrpc/httpoverrpc.pb.go +++ b/services/httpoverrpc/httpoverrpc.pb.go @@ -51,7 +51,7 @@ type HostHTTPRequest struct { // TLS Config for the request Tlsconfig *TLSConfig `protobuf:"bytes,5,opt,name=tlsconfig,proto3" json:"tlsconfig,omitempty"` // Dial Config for request, if not provided uses default dialer configuration - Dialconfig *DialConfig `protobuf:"bytes,6,opt,name=dialconfig,proto3" json:"dialconfig,omitempty"` + Dialconfig *DialConfig `protobuf:"bytes,6,opt,name=dialconfig,proto3,oneof" json:"dialconfig,omitempty"` } func (x *HostHTTPRequest) Reset() { @@ -182,7 +182,7 @@ type DialConfig struct { unknownFields protoimpl.UnknownFields // address to dial to, if not provided uses original one - DialAddress string `protobuf:"bytes,1,opt,name=dialAddress,proto3" json:"dialAddress,omitempty"` + DialAddress *string `protobuf:"bytes,1,opt,name=dialAddress,proto3,oneof" json:"dialAddress,omitempty"` } func (x *DialConfig) Reset() { @@ -218,8 +218,8 @@ func (*DialConfig) Descriptor() ([]byte, []int) { } func (x *DialConfig) GetDialAddress() string { - if x != nil { - return x.DialAddress + if x != nil && x.DialAddress != nil { + return *x.DialAddress } return "" } @@ -422,7 +422,7 @@ var file_httpoverrpc_proto_rawDesc = []byte{ 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x22, 0x80, 0x02, 0x0a, 0x0f, 0x48, 0x6f, 0x73, 0x74, 0x48, 0x54, 0x54, 0x50, 0x52, + 0x74, 0x6f, 0x22, 0x94, 0x02, 0x0a, 0x0f, 0x48, 0x6f, 0x73, 0x74, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x32, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, @@ -434,46 +434,48 @@ var file_httpoverrpc_proto_rawDesc = []byte{ 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x34, 0x0a, 0x09, 0x74, 0x6c, 0x73, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x54, 0x4c, 0x53, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x52, 0x09, 0x74, 0x6c, 0x73, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x37, 0x0a, 0x0a, + 0x67, 0x52, 0x09, 0x74, 0x6c, 0x73, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x3c, 0x0a, 0x0a, 0x64, 0x69, 0x61, 0x6c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x44, - 0x69, 0x61, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0a, 0x64, 0x69, 0x61, 0x6c, 0x63, - 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x22, 0x3b, 0x0a, 0x09, 0x54, 0x4c, 0x53, 0x43, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x12, 0x2e, 0x0a, 0x12, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x53, 0x6b, - 0x69, 0x70, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, - 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x53, 0x6b, 0x69, 0x70, 0x56, 0x65, 0x72, 0x69, - 0x66, 0x79, 0x22, 0x2e, 0x0a, 0x0a, 0x44, 0x69, 0x61, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x69, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x69, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x65, - 0x73, 0x73, 0x22, 0x37, 0x0a, 0x06, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, - 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1b, - 0x0a, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x42, 0x03, - 0x80, 0x01, 0x01, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x22, 0x8e, 0x01, 0x0a, 0x0b, - 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6d, - 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, - 0x68, 0x6f, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x75, - 0x72, 0x69, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x55, 0x72, 0x69, 0x12, 0x2d, 0x0a, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, - 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, - 0x52, 0x50, 0x43, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, - 0x65, 0x72, 0x73, 0x12, 0x17, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, - 0x0c, 0x42, 0x03, 0x80, 0x01, 0x01, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x22, 0x6f, 0x0a, 0x09, - 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, - 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x2d, 0x0a, 0x07, 0x68, 0x65, - 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x48, 0x54, - 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, - 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, - 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x32, 0x4d, 0x0a, - 0x0b, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x12, 0x3e, 0x0a, 0x04, - 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, - 0x50, 0x43, 0x2e, 0x48, 0x6f, 0x73, 0x74, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, - 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x31, 0x5a, 0x2f, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x53, 0x6e, 0x6f, 0x77, 0x66, - 0x6c, 0x61, 0x6b, 0x65, 0x2d, 0x4c, 0x61, 0x62, 0x73, 0x2f, 0x73, 0x61, 0x6e, 0x73, 0x73, 0x68, - 0x65, 0x6c, 0x6c, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x70, 0x63, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x69, 0x61, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x48, 0x00, 0x52, 0x0a, 0x64, 0x69, 0x61, + 0x6c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x88, 0x01, 0x01, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x64, + 0x69, 0x61, 0x6c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x22, 0x3b, 0x0a, 0x09, 0x54, 0x4c, 0x53, + 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x2e, 0x0a, 0x12, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, + 0x72, 0x65, 0x53, 0x6b, 0x69, 0x70, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x12, 0x69, 0x6e, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x53, 0x6b, 0x69, 0x70, + 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x22, 0x43, 0x0a, 0x0a, 0x44, 0x69, 0x61, 0x6c, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x12, 0x25, 0x0a, 0x0b, 0x64, 0x69, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, + 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0b, 0x64, 0x69, 0x61, + 0x6c, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x88, 0x01, 0x01, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, + 0x64, 0x69, 0x61, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x37, 0x0a, 0x06, 0x48, + 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x42, 0x03, 0x80, 0x01, 0x01, 0x52, 0x06, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x73, 0x22, 0x8e, 0x01, 0x0a, 0x0b, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x1f, 0x0a, 0x0b, + 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x75, 0x72, 0x69, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x55, 0x72, 0x69, 0x12, 0x2d, 0x0a, + 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, + 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x48, 0x65, 0x61, + 0x64, 0x65, 0x72, 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x17, 0x0a, 0x04, + 0x62, 0x6f, 0x64, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x03, 0x80, 0x01, 0x01, 0x52, + 0x04, 0x62, 0x6f, 0x64, 0x79, 0x22, 0x6f, 0x0a, 0x09, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, + 0x6f, 0x64, 0x65, 0x12, 0x2d, 0x0a, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x02, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, + 0x50, 0x43, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, + 0x72, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, + 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x32, 0x4d, 0x0a, 0x0b, 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, + 0x65, 0x72, 0x52, 0x50, 0x43, 0x12, 0x3e, 0x0a, 0x04, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1c, 0x2e, + 0x48, 0x54, 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x48, 0x6f, 0x73, 0x74, + 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x48, 0x54, + 0x54, 0x50, 0x4f, 0x76, 0x65, 0x72, 0x52, 0x50, 0x43, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, + 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x31, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x53, 0x6e, 0x6f, 0x77, 0x66, 0x6c, 0x61, 0x6b, 0x65, 0x2d, 0x4c, 0x61, + 0x62, 0x73, 0x2f, 0x73, 0x61, 0x6e, 0x73, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x2f, 0x68, 0x74, 0x74, + 0x70, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -591,6 +593,8 @@ func file_httpoverrpc_proto_init() { } } } + file_httpoverrpc_proto_msgTypes[0].OneofWrappers = []any{} + file_httpoverrpc_proto_msgTypes[2].OneofWrappers = []any{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/services/httpoverrpc/httpoverrpc.proto b/services/httpoverrpc/httpoverrpc.proto index ec34f4ae..3eeed858 100644 --- a/services/httpoverrpc/httpoverrpc.proto +++ b/services/httpoverrpc/httpoverrpc.proto @@ -39,7 +39,7 @@ message HostHTTPRequest { // TLS Config for the request TLSConfig tlsconfig = 5; // Dial Config for request, if not provided uses default dialer configuration - DialConfig dialconfig = 6; + optional DialConfig dialconfig = 6; } message TLSConfig { @@ -49,7 +49,7 @@ message TLSConfig { message DialConfig { // address to dial to, if not provided uses original one - string dialAddress = 1; + optional string dialAddress = 1; } message Header { diff --git a/services/httpoverrpc/server/server.go b/services/httpoverrpc/server/server.go index 3f527ce7..38846341 100644 --- a/services/httpoverrpc/server/server.go +++ b/services/httpoverrpc/server/server.go @@ -88,7 +88,7 @@ func (s *server) Host(ctx context.Context, req *pb.HostHTTPRequest) (*pb.HTTPRep } } - if req.Dialconfig != nil { + if req.GetDialconfig() != nil { transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) { dailAddress := addr if req.Dialconfig.GetDialAddress() != "" { diff --git a/services/httpoverrpc/server/server_test.go b/services/httpoverrpc/server/server_test.go index 0afe718d..ee72bf4c 100644 --- a/services/httpoverrpc/server/server_test.go +++ b/services/httpoverrpc/server/server_test.go @@ -325,7 +325,7 @@ func TestServer(t *testing.T) { Hostname: targetHost, Protocol: "http", Dialconfig: &httpoverrpc.DialConfig{ - DialAddress: addressToDial, + DialAddress: &addressToDial, }, }) if err != nil { From f6a18956cd902995b54f9eeeac5334bd89c68037 Mon Sep 17 00:00:00 2001 From: Ihar Kryvanos Date: Tue, 26 Nov 2024 12:29:24 +0100 Subject: [PATCH 3/7] Fix linting issue --- services/httpoverrpc/server/server.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/httpoverrpc/server/server.go b/services/httpoverrpc/server/server.go index 38846341..cdec4cac 100644 --- a/services/httpoverrpc/server/server.go +++ b/services/httpoverrpc/server/server.go @@ -46,8 +46,6 @@ var ( // Server is used to implement the gRPC Server type server struct{} -type netDialerContextFn func(ctx context.Context, network, addr string) (net.Conn, error) - func (s *server) Host(ctx context.Context, req *pb.HostHTTPRequest) (*pb.HTTPReply, error) { recorder := metrics.RecorderFromContextOrNoop(ctx) From 539c8b13854a5e74894ad3b08b2d1a6559a16d2f Mon Sep 17 00:00:00 2001 From: Ihar Kryvanos Date: Tue, 26 Nov 2024 20:07:27 +0100 Subject: [PATCH 4/7] Fix linting issue --- services/httpoverrpc/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/services/httpoverrpc/README.md b/services/httpoverrpc/README.md index c818e330..86589620 100644 --- a/services/httpoverrpc/README.md +++ b/services/httpoverrpc/README.md @@ -24,3 +24,17 @@ Where: Flags: - `-show-response-headers` If provided, print response code and headers - `-insecure-skip-tls-verify` If provided, skip TLS verification + + +Note: +1. The prefix / in request_uri is always needed, even there is nothing to put +2. If we use `--hostname` to send requests to a specified host instead of the default localhost, and want to use sansshell proxy action + to proxy requests, don't forget to add `--allow-any-host` for proxy action + +Examples: +```bash +# send get request to https://localhost:9090/hello +httpoverrpc get --hostname 10.1.23.4 --protocol https 9090 /hello +# send get request with url http://example.com:9090/hello, but deal to localhost:9090 +httpoverrpc get --hostname example.com --dialAddress localhost:9090 9090 /hello +``` From b913a3c9de752665532e27df1e1a5fe090e1382e Mon Sep 17 00:00:00 2001 From: Ihar Kryvanos Date: Tue, 26 Nov 2024 21:20:02 +0100 Subject: [PATCH 5/7] SNOW-1665684 Update utils interface --- services/httpoverrpc/README.md | 2 +- services/httpoverrpc/client/client.go | 2 +- services/httpoverrpc/client/utils.go | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/services/httpoverrpc/README.md b/services/httpoverrpc/README.md index 86589620..1e1eaa0e 100644 --- a/services/httpoverrpc/README.md +++ b/services/httpoverrpc/README.md @@ -8,7 +8,7 @@ This directory contains the http over rpc services. It is a simple service that Make a HTTP(-S) request to a specified port on the remote host. ```bash -sanssh get [-method ] [-header
] [-dialAddress ] [-insecure-skip-tls-verify] [-show-response-headers] [-body ] [-protocol ] [-hostname ] : +sanssh get [-method ] [-header
] [-dial-address ] [-insecure-skip-tls-verify] [-show-response-headers] [-body ] [-protocol ] [-hostname ] : ``` Where: diff --git a/services/httpoverrpc/client/client.go b/services/httpoverrpc/client/client.go index eb578a39..88d890aa 100644 --- a/services/httpoverrpc/client/client.go +++ b/services/httpoverrpc/client/client.go @@ -233,7 +233,7 @@ type getCmd struct { func (*getCmd) Name() string { return "get" } func (*getCmd) Synopsis() string { return "Makes a HTTP(-S) call to a port on a remote host" } func (*getCmd) Usage() string { - return `get [-method METHOD] [-header Header...] [-dialAddress dialAddress] [-body body] [-protocol Protocol] [-hostname Hostname] remoteport request_uri: + return `get [-method METHOD] [-header Header...] [-dial-address dialAddress] [-body body] [-protocol Protocol] [-hostname Hostname] remoteport request_uri: Make a HTTP request to a specified port on the remote host. Examples: diff --git a/services/httpoverrpc/client/utils.go b/services/httpoverrpc/client/utils.go index 1d6e4e86..421fa924 100644 --- a/services/httpoverrpc/client/utils.go +++ b/services/httpoverrpc/client/utils.go @@ -42,14 +42,16 @@ var ( type HTTPTransporter struct { conn *proxy.Conn insecureSkipVerify bool - dialConfigFactory func(req http.Request) *pb.DialConfig + dialConfigFactory DialConfigFactory } type httpTransporterOptions struct { insecureSkipVerify bool - dialConfigFactory func(req http.Request) *pb.DialConfig + dialConfigFactory DialConfigFactory } +type DialConfigFactory func(req *http.Request) *pb.DialConfig + type Option interface { apply(*httpTransporterOptions) } @@ -66,7 +68,7 @@ func WithInsecureSkipVerify(insecureSkipVerify bool) Option { }) } -func WithCustomDialConfig(dialConfigFactory func(req http.Request) *pb.DialConfig) Option { +func WithCustomDialConfig(dialConfigFactory DialConfigFactory) Option { return optionFunc(func(o *httpTransporterOptions) { o.dialConfigFactory = dialConfigFactory }) @@ -165,7 +167,7 @@ func (c *HTTPTransporter) RoundTrip(req *http.Request) (*http.Response, error) { var dialConfig *pb.DialConfig = nil if c.dialConfigFactory != nil { - dialConfig = c.dialConfigFactory(*req) + dialConfig = c.dialConfigFactory(req) } reqPb := &pb.HostHTTPRequest{ Request: &pb.HTTPRequest{ From 37d351ffbfa0589e432f57a43bd86a7cafcf5d15 Mon Sep 17 00:00:00 2001 From: Ihar Kryvanos Date: Wed, 27 Nov 2024 12:05:30 +0100 Subject: [PATCH 6/7] SNOW-1665684 fix typo --- services/httpoverrpc/client/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/httpoverrpc/client/client.go b/services/httpoverrpc/client/client.go index 88d890aa..7497d037 100644 --- a/services/httpoverrpc/client/client.go +++ b/services/httpoverrpc/client/client.go @@ -239,7 +239,7 @@ func (*getCmd) Usage() string { Examples: # send get request to https://localhost:9090/hello httpoverrpc get --hostname 10.1.23.4 --protocol https 9090 /hello - # send get request with url http://example.com:9090/hello, but deal to localhost:9090 + # send get request with url http://example.com:9090/hello, but dial to localhost:9090 httpoverrpc get --hostname example.com --dialAddress localhost:9090 9090 /hello Note: From 81defb667f4cd01a92bc32907e4b117305040922 Mon Sep 17 00:00:00 2001 From: Ihar Kryvanos Date: Thu, 28 Nov 2024 10:54:51 +0100 Subject: [PATCH 7/7] SNOW-1665684 fix typo --- services/httpoverrpc/README.md | 2 +- services/httpoverrpc/client/client.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/httpoverrpc/README.md b/services/httpoverrpc/README.md index 1e1eaa0e..8070a227 100644 --- a/services/httpoverrpc/README.md +++ b/services/httpoverrpc/README.md @@ -33,7 +33,7 @@ Note: Examples: ```bash -# send get request to https://localhost:9090/hello +# send get request to https://10.1.23.4:9090/hello httpoverrpc get --hostname 10.1.23.4 --protocol https 9090 /hello # send get request with url http://example.com:9090/hello, but deal to localhost:9090 httpoverrpc get --hostname example.com --dialAddress localhost:9090 9090 /hello diff --git a/services/httpoverrpc/client/client.go b/services/httpoverrpc/client/client.go index 7497d037..01c19f0e 100644 --- a/services/httpoverrpc/client/client.go +++ b/services/httpoverrpc/client/client.go @@ -237,7 +237,7 @@ func (*getCmd) Usage() string { Make a HTTP request to a specified port on the remote host. Examples: - # send get request to https://localhost:9090/hello + # send get request to https://10.1.23.4:9090/hello httpoverrpc get --hostname 10.1.23.4 --protocol https 9090 /hello # send get request with url http://example.com:9090/hello, but dial to localhost:9090 httpoverrpc get --hostname example.com --dialAddress localhost:9090 9090 /hello