github.com/containerd/containerd@v22.0.0-20200918172823-438c87b8e050+incompatible/services/introspection/introspection.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 introspection 18 19 import ( 20 context "context" 21 22 api "github.com/containerd/containerd/api/services/introspection/v1" 23 "github.com/containerd/containerd/errdefs" 24 ptypes "github.com/gogo/protobuf/types" 25 ) 26 27 type Service interface { 28 Plugins(context.Context, []string) (*api.PluginsResponse, error) 29 Server(context.Context, *ptypes.Empty) (*api.ServerResponse, error) 30 } 31 32 type introspectionRemote struct { 33 client api.IntrospectionClient 34 } 35 36 var _ = (Service)(&introspectionRemote{}) 37 38 func NewIntrospectionServiceFromClient(c api.IntrospectionClient) Service { 39 return &introspectionRemote{client: c} 40 } 41 42 func (i *introspectionRemote) Plugins(ctx context.Context, filters []string) (*api.PluginsResponse, error) { 43 resp, err := i.client.Plugins(ctx, &api.PluginsRequest{ 44 Filters: filters, 45 }) 46 47 if err != nil { 48 return nil, errdefs.FromGRPC(err) 49 } 50 51 return resp, nil 52 } 53 54 func (i *introspectionRemote) Server(ctx context.Context, in *ptypes.Empty) (*api.ServerResponse, error) { 55 resp, err := i.client.Server(ctx, in) 56 57 if err != nil { 58 return nil, errdefs.FromGRPC(err) 59 } 60 61 return resp, nil 62 }