diff --git a/containers/v1/containers.pb.go b/containers/v1/containers.pb.go index b71a9507f..97fe22b51 100644 --- a/containers/v1/containers.pb.go +++ b/containers/v1/containers.pb.go @@ -1198,6 +1198,108 @@ func (x *ListResponse) GetContainers() []*Container { return nil } +type LogsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ContainerId string `protobuf:"bytes,1,opt,name=container_id,json=containerId,proto3" json:"container_id,omitempty"` + Follow bool `protobuf:"varint,2,opt,name=follow,proto3" json:"follow,omitempty"` +} + +func (x *LogsRequest) Reset() { + *x = LogsRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_containers_v1_containers_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LogsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LogsRequest) ProtoMessage() {} + +func (x *LogsRequest) ProtoReflect() protoreflect.Message { + mi := &file_containers_v1_containers_proto_msgTypes[19] + 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 LogsRequest.ProtoReflect.Descriptor instead. +func (*LogsRequest) Descriptor() ([]byte, []int) { + return file_containers_v1_containers_proto_rawDescGZIP(), []int{19} +} + +func (x *LogsRequest) GetContainerId() string { + if x != nil { + return x.ContainerId + } + return "" +} + +func (x *LogsRequest) GetFollow() bool { + if x != nil { + return x.Follow + } + return false +} + +type LogsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Logs []byte `protobuf:"bytes,1,opt,name=logs,proto3" json:"logs,omitempty"` +} + +func (x *LogsResponse) Reset() { + *x = LogsResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_containers_v1_containers_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LogsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LogsResponse) ProtoMessage() {} + +func (x *LogsResponse) ProtoReflect() protoreflect.Message { + mi := &file_containers_v1_containers_proto_msgTypes[20] + 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 LogsResponse.ProtoReflect.Descriptor instead. +func (*LogsResponse) Descriptor() ([]byte, []int) { + return file_containers_v1_containers_proto_rawDescGZIP(), []int{20} +} + +func (x *LogsResponse) GetLogs() []byte { + if x != nil { + return x.Logs + } + return nil +} + var File_containers_v1_containers_proto protoreflect.FileDescriptor var file_containers_v1_containers_proto_rawDesc = []byte{ @@ -1316,60 +1418,73 @@ var file_containers_v1_containers_proto_rawDesc = []byte{ 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x52, 0x0a, - 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x32, 0x99, 0x06, 0x0a, 0x0a, 0x43, - 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x12, 0x5d, 0x0a, 0x04, 0x4c, 0x69, 0x73, - 0x74, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, - 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, - 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, - 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x63, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, - 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x2c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x43, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x60, 0x0a, - 0x05, 0x53, 0x74, 0x61, 0x72, 0x74, 0x12, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, - 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, - 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x61, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, - 0x31, 0x2e, 0x53, 0x74, 0x61, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x5d, 0x0a, 0x04, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, - 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, - 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, - 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5d, - 0x0a, 0x04, 0x4b, 0x69, 0x6c, 0x6c, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, - 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, - 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4b, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, - 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, - 0x2e, 0x4b, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x63, 0x0a, - 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, - 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, - 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, - 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, - 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x63, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x2b, 0x2e, 0x63, - 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, - 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, - 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5d, 0x0a, 0x04, 0x45, 0x78, 0x65, 0x63, 0x12, + 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x22, 0x48, 0x0a, 0x0b, 0x4c, 0x6f, + 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, + 0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x66, 0x6f, + 0x6c, 0x6c, 0x6f, 0x77, 0x22, 0x22, 0x0a, 0x0c, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x6f, 0x67, 0x73, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x04, 0x6c, 0x6f, 0x67, 0x73, 0x32, 0xfa, 0x06, 0x0a, 0x0a, 0x43, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x12, 0x5d, 0x0a, 0x04, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x45, - 0x78, 0x65, 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, + 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x28, 0x5a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x63, 0x0a, 0x06, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, + 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, + 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x60, 0x0a, 0x05, 0x53, + 0x74, 0x61, 0x72, 0x74, 0x12, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, + 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, + 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x61, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, + 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, + 0x53, 0x74, 0x61, 0x72, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5d, 0x0a, + 0x04, 0x53, 0x74, 0x6f, 0x70, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, + 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x74, 0x6f, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, + 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, + 0x53, 0x74, 0x6f, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5d, 0x0a, 0x04, + 0x4b, 0x69, 0x6c, 0x6c, 0x12, 0x29, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, + 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, + 0x2e, 0x76, 0x31, 0x2e, 0x4b, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4b, + 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x63, 0x0a, 0x06, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, + 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, + 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, + 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x63, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x2b, 0x2e, 0x63, 0x6f, 0x6d, + 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, + 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5d, 0x0a, 0x04, 0x45, 0x78, 0x65, 0x63, 0x12, 0x29, 0x2e, + 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x65, + 0x63, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, + 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, + 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5f, 0x0a, 0x04, 0x4c, 0x6f, 0x67, 0x73, 0x12, 0x29, 0x2e, 0x63, + 0x6f, 0x6d, 0x2e, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x6f, 0x67, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2a, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x64, 0x6f, + 0x63, 0x6b, 0x65, 0x72, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x30, 0x01, 0x42, 0x28, 0x5a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x6f, 0x63, 0x6b, 0x65, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1384,7 +1499,7 @@ func file_containers_v1_containers_proto_rawDescGZIP() []byte { return file_containers_v1_containers_proto_rawDescData } -var file_containers_v1_containers_proto_msgTypes = make([]protoimpl.MessageInfo, 20) +var file_containers_v1_containers_proto_msgTypes = make([]protoimpl.MessageInfo, 22) var file_containers_v1_containers_proto_goTypes = []interface{}{ (*Port)(nil), // 0: com.docker.api.containers.v1.Port (*Container)(nil), // 1: com.docker.api.containers.v1.Container @@ -1405,12 +1520,14 @@ var file_containers_v1_containers_proto_goTypes = []interface{}{ (*KillResponse)(nil), // 16: com.docker.api.containers.v1.KillResponse (*ListRequest)(nil), // 17: com.docker.api.containers.v1.ListRequest (*ListResponse)(nil), // 18: com.docker.api.containers.v1.ListResponse - nil, // 19: com.docker.api.containers.v1.CreateRequest.LabelsEntry + (*LogsRequest)(nil), // 19: com.docker.api.containers.v1.LogsRequest + (*LogsResponse)(nil), // 20: com.docker.api.containers.v1.LogsResponse + nil, // 21: com.docker.api.containers.v1.CreateRequest.LabelsEntry } var file_containers_v1_containers_proto_depIdxs = []int32{ 0, // 0: com.docker.api.containers.v1.Container.ports:type_name -> com.docker.api.containers.v1.Port 3, // 1: com.docker.api.containers.v1.CreateRequest.mounts:type_name -> com.docker.api.containers.v1.Mount - 19, // 2: com.docker.api.containers.v1.CreateRequest.labels:type_name -> com.docker.api.containers.v1.CreateRequest.LabelsEntry + 21, // 2: com.docker.api.containers.v1.CreateRequest.labels:type_name -> com.docker.api.containers.v1.CreateRequest.LabelsEntry 1, // 3: com.docker.api.containers.v1.ListResponse.containers:type_name -> com.docker.api.containers.v1.Container 17, // 4: com.docker.api.containers.v1.Containers.List:input_type -> com.docker.api.containers.v1.ListRequest 2, // 5: com.docker.api.containers.v1.Containers.Create:input_type -> com.docker.api.containers.v1.CreateRequest @@ -1420,16 +1537,18 @@ var file_containers_v1_containers_proto_depIdxs = []int32{ 7, // 9: com.docker.api.containers.v1.Containers.Delete:input_type -> com.docker.api.containers.v1.DeleteRequest 5, // 10: com.docker.api.containers.v1.Containers.Update:input_type -> com.docker.api.containers.v1.UpdateRequest 13, // 11: com.docker.api.containers.v1.Containers.Exec:input_type -> com.docker.api.containers.v1.ExecRequest - 18, // 12: com.docker.api.containers.v1.Containers.List:output_type -> com.docker.api.containers.v1.ListResponse - 4, // 13: com.docker.api.containers.v1.Containers.Create:output_type -> com.docker.api.containers.v1.CreateResponse - 10, // 14: com.docker.api.containers.v1.Containers.Start:output_type -> com.docker.api.containers.v1.StartResponse - 12, // 15: com.docker.api.containers.v1.Containers.Stop:output_type -> com.docker.api.containers.v1.StopResponse - 16, // 16: com.docker.api.containers.v1.Containers.Kill:output_type -> com.docker.api.containers.v1.KillResponse - 8, // 17: com.docker.api.containers.v1.Containers.Delete:output_type -> com.docker.api.containers.v1.DeleteResponse - 6, // 18: com.docker.api.containers.v1.Containers.Update:output_type -> com.docker.api.containers.v1.UpdateResponse - 14, // 19: com.docker.api.containers.v1.Containers.Exec:output_type -> com.docker.api.containers.v1.ExecResponse - 12, // [12:20] is the sub-list for method output_type - 4, // [4:12] is the sub-list for method input_type + 19, // 12: com.docker.api.containers.v1.Containers.Logs:input_type -> com.docker.api.containers.v1.LogsRequest + 18, // 13: com.docker.api.containers.v1.Containers.List:output_type -> com.docker.api.containers.v1.ListResponse + 4, // 14: com.docker.api.containers.v1.Containers.Create:output_type -> com.docker.api.containers.v1.CreateResponse + 10, // 15: com.docker.api.containers.v1.Containers.Start:output_type -> com.docker.api.containers.v1.StartResponse + 12, // 16: com.docker.api.containers.v1.Containers.Stop:output_type -> com.docker.api.containers.v1.StopResponse + 16, // 17: com.docker.api.containers.v1.Containers.Kill:output_type -> com.docker.api.containers.v1.KillResponse + 8, // 18: com.docker.api.containers.v1.Containers.Delete:output_type -> com.docker.api.containers.v1.DeleteResponse + 6, // 19: com.docker.api.containers.v1.Containers.Update:output_type -> com.docker.api.containers.v1.UpdateResponse + 14, // 20: com.docker.api.containers.v1.Containers.Exec:output_type -> com.docker.api.containers.v1.ExecResponse + 20, // 21: com.docker.api.containers.v1.Containers.Logs:output_type -> com.docker.api.containers.v1.LogsResponse + 13, // [13:22] is the sub-list for method output_type + 4, // [4:13] 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 @@ -1669,6 +1788,30 @@ func file_containers_v1_containers_proto_init() { return nil } } + file_containers_v1_containers_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LogsRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_containers_v1_containers_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LogsResponse); 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{ @@ -1676,7 +1819,7 @@ func file_containers_v1_containers_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_containers_v1_containers_proto_rawDesc, NumEnums: 0, - NumMessages: 20, + NumMessages: 22, NumExtensions: 0, NumServices: 1, }, @@ -1710,6 +1853,7 @@ type ContainersClient interface { Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*DeleteResponse, error) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*UpdateResponse, error) Exec(ctx context.Context, in *ExecRequest, opts ...grpc.CallOption) (*ExecResponse, error) + Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Containers_LogsClient, error) } type containersClient struct { @@ -1792,6 +1936,38 @@ func (c *containersClient) Exec(ctx context.Context, in *ExecRequest, opts ...gr return out, nil } +func (c *containersClient) Logs(ctx context.Context, in *LogsRequest, opts ...grpc.CallOption) (Containers_LogsClient, error) { + stream, err := c.cc.NewStream(ctx, &_Containers_serviceDesc.Streams[0], "/com.docker.api.containers.v1.Containers/Logs", opts...) + if err != nil { + return nil, err + } + x := &containersLogsClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type Containers_LogsClient interface { + Recv() (*LogsResponse, error) + grpc.ClientStream +} + +type containersLogsClient struct { + grpc.ClientStream +} + +func (x *containersLogsClient) Recv() (*LogsResponse, error) { + m := new(LogsResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + // ContainersServer is the server API for Containers service. type ContainersServer interface { List(context.Context, *ListRequest) (*ListResponse, error) @@ -1802,6 +1978,7 @@ type ContainersServer interface { Delete(context.Context, *DeleteRequest) (*DeleteResponse, error) Update(context.Context, *UpdateRequest) (*UpdateResponse, error) Exec(context.Context, *ExecRequest) (*ExecResponse, error) + Logs(*LogsRequest, Containers_LogsServer) error } // UnimplementedContainersServer can be embedded to have forward compatible implementations. @@ -1832,6 +2009,9 @@ func (*UnimplementedContainersServer) Update(context.Context, *UpdateRequest) (* func (*UnimplementedContainersServer) Exec(context.Context, *ExecRequest) (*ExecResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Exec not implemented") } +func (*UnimplementedContainersServer) Logs(*LogsRequest, Containers_LogsServer) error { + return status.Errorf(codes.Unimplemented, "method Logs not implemented") +} func RegisterContainersServer(s *grpc.Server, srv ContainersServer) { s.RegisterService(&_Containers_serviceDesc, srv) @@ -1981,6 +2161,27 @@ func _Containers_Exec_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } +func _Containers_Logs_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(LogsRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(ContainersServer).Logs(m, &containersLogsServer{stream}) +} + +type Containers_LogsServer interface { + Send(*LogsResponse) error + grpc.ServerStream +} + +type containersLogsServer struct { + grpc.ServerStream +} + +func (x *containersLogsServer) Send(m *LogsResponse) error { + return x.ServerStream.SendMsg(m) +} + var _Containers_serviceDesc = grpc.ServiceDesc{ ServiceName: "com.docker.api.containers.v1.Containers", HandlerType: (*ContainersServer)(nil), @@ -2018,6 +2219,12 @@ var _Containers_serviceDesc = grpc.ServiceDesc{ Handler: _Containers_Exec_Handler, }, }, - Streams: []grpc.StreamDesc{}, + Streams: []grpc.StreamDesc{ + { + StreamName: "Logs", + Handler: _Containers_Logs_Handler, + ServerStreams: true, + }, + }, Metadata: "containers/v1/containers.proto", } diff --git a/containers/v1/containers.proto b/containers/v1/containers.proto index d3a41e5d4..8bf63d400 100644 --- a/containers/v1/containers.proto +++ b/containers/v1/containers.proto @@ -40,6 +40,7 @@ service Containers { rpc Delete(DeleteRequest) returns (DeleteResponse); rpc Update(UpdateRequest) returns (UpdateResponse); rpc Exec(ExecRequest) returns (ExecResponse); + rpc Logs(LogsRequest) returns (stream LogsResponse); } message Port { @@ -154,3 +155,12 @@ message ListRequest { message ListResponse { repeated Container containers = 1; } + +message LogsRequest { + string container_id = 1; + bool follow = 2; +} + +message LogsResponse { + bytes logs = 1; +} diff --git a/go.mod b/go.mod index 907c7c7c0..3f7c826b9 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee // indirect github.com/gobwas/pool v0.2.0 // indirect github.com/gobwas/ws v1.0.3 - github.com/golang/protobuf v1.4.0 + github.com/golang/protobuf v1.4.1 github.com/gorilla/mux v1.7.4 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/hashicorp/go-multierror v1.1.0 @@ -43,7 +43,7 @@ require ( golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect golang.org/x/text v0.3.2 // indirect google.golang.org/grpc v1.29.1 - google.golang.org/protobuf v1.21.0 + google.golang.org/protobuf v1.22.0 gotest.tools v2.2.0+incompatible gotest.tools/v3 v3.0.2 ) diff --git a/go.sum b/go.sum index dbdc66cb7..ea77a4a4b 100644 --- a/go.sum +++ b/go.sum @@ -117,6 +117,8 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -339,6 +341,8 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0 h1:qdOKuR/EIArgaWNjetjgTzgVTAZ+S/WXVrq9HW9zimw= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0 h1:cJv5/xdbk1NnMPR1VP9+HU6gupuG9MLBoH1r6RHZ2MY= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/moby/backend.go b/moby/backend.go index c4645793f..b813a310f 100644 --- a/moby/backend.go +++ b/moby/backend.go @@ -143,6 +143,7 @@ func (ms *mobyService) Logs(ctx context.Context, containerName string, request c r, err := ms.apiClient.ContainerLogs(ctx, containerName, types.ContainerLogsOptions{ ShowStdout: true, ShowStderr: true, + Follow: request.Follow, }) if err != nil { return err diff --git a/server/proxy/containers.go b/server/proxy/containers.go index 5a6494127..5100b4dbc 100644 --- a/server/proxy/containers.go +++ b/server/proxy/containers.go @@ -101,3 +101,13 @@ func (p *proxyContainerAPI) Update(_ context.Context, _ *v1.UpdateRequest) (*v1. func (p *proxyContainerAPI) Exec(_ context.Context, _ *v1.ExecRequest) (*v1.ExecResponse, error) { panic("not implemented") // TODO: Implement } + +func (p *proxyContainerAPI) Logs(request *v1.LogsRequest, stream v1.Containers_LogsServer) error { + ctx := stream.Context() + c := Client(ctx) + + return c.ContainerService().Logs(ctx, request.GetContainerId(), containers.LogsRequest{ + Follow: request.Follow, + Writer: &streamWriter{stream}, + }) +} diff --git a/server/proxy/streamwriter.go b/server/proxy/streamwriter.go new file mode 100644 index 000000000..bada557b0 --- /dev/null +++ b/server/proxy/streamwriter.go @@ -0,0 +1,23 @@ +package proxy + +import ( + "io" + + v1 "github.com/docker/api/containers/v1" +) + +type streamWriter struct { + stream v1.Containers_LogsServer +} + +func newStreamWriter(stream v1.Containers_LogsServer) io.Writer { + return &streamWriter{ + stream: stream, + } +} + +func (w *streamWriter) Write(p []byte) (n int, err error) { + return len(p), w.stream.Send(&v1.LogsResponse{ + Logs: p, + }) +} diff --git a/server/proxy/streamwriter_test.go b/server/proxy/streamwriter_test.go new file mode 100644 index 000000000..b169766b2 --- /dev/null +++ b/server/proxy/streamwriter_test.go @@ -0,0 +1,55 @@ +package proxy + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "google.golang.org/grpc/metadata" + + v1 "github.com/docker/api/containers/v1" +) + +type logServer struct { + logs []byte +} + +func (ls *logServer) Send(response *v1.LogsResponse) error { + ls.logs = response.Logs + return nil +} + +func (ls *logServer) SetHeader(metadata.MD) error { + return nil +} + +func (ls *logServer) SendHeader(metadata.MD) error { + return nil +} + +func (ls *logServer) SetTrailer(metadata.MD) { +} + +func (ls *logServer) Context() context.Context { + return nil +} + +func (ls *logServer) SendMsg(m interface{}) error { + return nil +} + +func (ls *logServer) RecvMsg(m interface{}) error { + return nil +} + +func TestStreamWriter(t *testing.T) { + ls := &logServer{} + sw := newStreamWriter(ls) + in := []byte{104, 101, 108, 108, 111} + + l, err := sw.Write(in) + + assert.Nil(t, err) + assert.Equal(t, len(in), l) + assert.Equal(t, in, ls.logs) +} diff --git a/server/server.go b/server/server.go index 2f83f9e30..d3a050f81 100644 --- a/server/server.go +++ b/server/server.go @@ -51,7 +51,10 @@ func New(ctx context.Context) *grpc.Server { unaryMeta(ctx), unary, ), - grpc.StreamInterceptor(stream), + grpc.ChainStreamInterceptor( + grpc.StreamServerInterceptor(stream), + grpc.StreamServerInterceptor(streamMeta(ctx)), + ), ) hs := health.NewServer() grpc_health_v1.RegisterHealthServer(s, hs) @@ -76,32 +79,91 @@ func stream(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, func unaryMeta(clictx context.Context) func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - md, ok := metadata.FromIncomingContext(ctx) - if !ok { - return handler(ctx, req) + configuredCtx, err := configureContext(ctx, clictx) + if err != nil { + return nil, err } - key, ok := md[apicontext.Key] - if !ok { - return handler(ctx, req) - } - - if len(key) == 1 { - s := store.ContextStore(clictx) - ctx = store.WithContextStore(ctx, s) - ctx = apicontext.WithCurrentContext(ctx, key[0]) - - c, err := client.New(ctx) - if err != nil { - return nil, err - } - - ctx, err = proxy.WithClient(ctx, c) - if err != nil { - return nil, err - } - } - - return handler(ctx, req) + return handler(configuredCtx, req) } } + +func streamMeta(clictx context.Context) func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { + return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { + ctx, err := configureContext(ss.Context(), clictx) + if err != nil { + return err + } + + nss := newServerStream(ctx, ss) + + return handler(srv, nss) + } +} + +// nolint: golint +func configureContext(ctx context.Context, clictx context.Context) (context.Context, error) { + md, ok := metadata.FromIncomingContext(ctx) + if !ok { + return ctx, nil + } + + key, ok := md[apicontext.Key] + if !ok { + return ctx, nil + } + + if len(key) == 1 { + s := store.ContextStore(clictx) + ctx = store.WithContextStore(ctx, s) + ctx = apicontext.WithCurrentContext(ctx, key[0]) + + c, err := client.New(ctx) + if err != nil { + return nil, err + } + + ctx, err = proxy.WithClient(ctx, c) + if err != nil { + return nil, err + } + } + + return ctx, nil +} + +type contextServerStream struct { + s grpc.ServerStream + ctx context.Context +} + +func newServerStream(ctx context.Context, s grpc.ServerStream) grpc.ServerStream { + return &contextServerStream{ + s: s, + ctx: ctx, + } +} + +func (css *contextServerStream) SetHeader(md metadata.MD) error { + return css.s.SetHeader(md) +} + +func (css *contextServerStream) SendHeader(md metadata.MD) error { + return css.s.SendHeader(md) +} + +func (css *contextServerStream) SetTrailer(md metadata.MD) { + css.s.SetTrailer(md) +} + +func (css *contextServerStream) Context() context.Context { + return css.ctx +} + +func (css *contextServerStream) SendMsg(m interface{}) error { + return css.s.SendMsg(m) +} + +func (css *contextServerStream) RecvMsg(m interface{}) error { + return css.s.RecvMsg(m) +} diff --git a/tests/node-client/index.ts b/tests/node-client/index.ts index eee27ce4f..a6bee4593 100644 --- a/tests/node-client/index.ts +++ b/tests/node-client/index.ts @@ -1,26 +1,35 @@ -import * as grpc from '@grpc/grpc-js'; +import * as grpc from "@grpc/grpc-js"; import * as continersPb from "./grpc/containers_grpc_pb"; -import { IContainersClient } from './grpc/containers_grpc_pb'; +import { IContainersClient } from "./grpc/containers_grpc_pb"; import { ListRequest, ListResponse } from "./grpc/containers_pb"; let address = process.argv[3] || "unix:///tmp/backend.sock"; - -const ContainersServiceClient = grpc.makeClientConstructor(continersPb["com.docker.api.containers.v1.Containers"], "ContainersClient"); -const client = new ContainersServiceClient(address, grpc.credentials.createInsecure()) as unknown as IContainersClient; +const ContainersServiceClient = grpc.makeClientConstructor( + continersPb["com.docker.api.containers.v1.Containers"], + "ContainersClient" +); +const client = (new ContainersServiceClient( + address, + grpc.credentials.createInsecure() +) as unknown) as IContainersClient; let backend = process.argv[2] || "moby"; const meta = new grpc.Metadata(); meta.set("CONTEXT_KEY", backend); client.list(new ListRequest(), meta, (err: any, response: ListResponse) => { - if (err != null) { - console.error(err); - return; - } + if (err != null) { + console.error(err); + return; + } - const containers = response.getContainersList(); + const containers = response.getContainersList(); - containers.forEach(container => { - console.log(container.getId(), container.getImage()); - }); + containers.forEach((container) => { + console.log(container.getId(), container.getImage()); + }); }); + +function arrayBufferToString(buffer: Uint8Array): string { + return String.fromCharCode.apply(null, Array.from(buffer)); +}