introspection.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. Copyright The containerd Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package introspection
  14. import (
  15. context "context"
  16. api "github.com/containerd/containerd/api/services/introspection/v1"
  17. "github.com/containerd/containerd/errdefs"
  18. "github.com/containerd/containerd/log"
  19. ptypes "github.com/gogo/protobuf/types"
  20. )
  21. // Service defines the instrospection service interface
  22. type Service interface {
  23. Plugins(context.Context, []string) (*api.PluginsResponse, error)
  24. Server(context.Context, *ptypes.Empty) (*api.ServerResponse, error)
  25. }
  26. type introspectionRemote struct {
  27. client api.IntrospectionClient
  28. }
  29. var _ = (Service)(&introspectionRemote{})
  30. // NewIntrospectionServiceFromClient creates a new introspection service from an API client
  31. func NewIntrospectionServiceFromClient(c api.IntrospectionClient) Service {
  32. return &introspectionRemote{client: c}
  33. }
  34. func (i *introspectionRemote) Plugins(ctx context.Context, filters []string) (*api.PluginsResponse, error) {
  35. log.G(ctx).WithField("filters", filters).Debug("remote introspection plugin filters")
  36. resp, err := i.client.Plugins(ctx, &api.PluginsRequest{
  37. Filters: filters,
  38. })
  39. if err != nil {
  40. return nil, errdefs.FromGRPC(err)
  41. }
  42. return resp, nil
  43. }
  44. func (i *introspectionRemote) Server(ctx context.Context, in *ptypes.Empty) (*api.ServerResponse, error) {
  45. resp, err := i.client.Server(ctx, in)
  46. if err != nil {
  47. return nil, errdefs.FromGRPC(err)
  48. }
  49. return resp, nil
  50. }