github.com/demonoid81/containerd@v1.3.4/services/events/ttrpc.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package events 18 19 import ( 20 "context" 21 22 api "github.com/containerd/containerd/api/services/ttrpc/events/v1" 23 "github.com/containerd/containerd/errdefs" 24 "github.com/containerd/containerd/events" 25 "github.com/containerd/containerd/events/exchange" 26 ptypes "github.com/gogo/protobuf/types" 27 ) 28 29 type ttrpcService struct { 30 events *exchange.Exchange 31 } 32 33 func (s *ttrpcService) Forward(ctx context.Context, r *api.ForwardRequest) (*ptypes.Empty, error) { 34 if err := s.events.Forward(ctx, fromTProto(r.Envelope)); err != nil { 35 return nil, errdefs.ToGRPC(err) 36 } 37 38 return &ptypes.Empty{}, nil 39 } 40 41 func fromTProto(env *api.Envelope) *events.Envelope { 42 return &events.Envelope{ 43 Timestamp: env.Timestamp, 44 Namespace: env.Namespace, 45 Topic: env.Topic, 46 Event: env.Event, 47 } 48 }