github.com/demonoid81/containerd@v1.3.4/services/images/service.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 images
    18  
    19  import (
    20  	"context"
    21  
    22  	imagesapi "github.com/containerd/containerd/api/services/images/v1"
    23  	"github.com/containerd/containerd/plugin"
    24  	"github.com/containerd/containerd/services"
    25  	ptypes "github.com/gogo/protobuf/types"
    26  	"github.com/pkg/errors"
    27  	"google.golang.org/grpc"
    28  )
    29  
    30  func init() {
    31  	plugin.Register(&plugin.Registration{
    32  		Type: plugin.GRPCPlugin,
    33  		ID:   "images",
    34  		Requires: []plugin.Type{
    35  			plugin.ServicePlugin,
    36  		},
    37  		InitFn: func(ic *plugin.InitContext) (interface{}, error) {
    38  			plugins, err := ic.GetByType(plugin.ServicePlugin)
    39  			if err != nil {
    40  				return nil, err
    41  			}
    42  			p, ok := plugins[services.ImagesService]
    43  			if !ok {
    44  				return nil, errors.New("images service not found")
    45  			}
    46  			i, err := p.Instance()
    47  			if err != nil {
    48  				return nil, err
    49  			}
    50  			return &service{local: i.(imagesapi.ImagesClient)}, nil
    51  		},
    52  	})
    53  }
    54  
    55  type service struct {
    56  	local imagesapi.ImagesClient
    57  }
    58  
    59  var _ imagesapi.ImagesServer = &service{}
    60  
    61  func (s *service) Register(server *grpc.Server) error {
    62  	imagesapi.RegisterImagesServer(server, s)
    63  	return nil
    64  }
    65  
    66  func (s *service) Get(ctx context.Context, req *imagesapi.GetImageRequest) (*imagesapi.GetImageResponse, error) {
    67  	return s.local.Get(ctx, req)
    68  }
    69  
    70  func (s *service) List(ctx context.Context, req *imagesapi.ListImagesRequest) (*imagesapi.ListImagesResponse, error) {
    71  	return s.local.List(ctx, req)
    72  }
    73  
    74  func (s *service) Create(ctx context.Context, req *imagesapi.CreateImageRequest) (*imagesapi.CreateImageResponse, error) {
    75  	return s.local.Create(ctx, req)
    76  }
    77  
    78  func (s *service) Update(ctx context.Context, req *imagesapi.UpdateImageRequest) (*imagesapi.UpdateImageResponse, error) {
    79  	return s.local.Update(ctx, req)
    80  }
    81  
    82  func (s *service) Delete(ctx context.Context, req *imagesapi.DeleteImageRequest) (*ptypes.Empty, error) {
    83  	return s.local.Delete(ctx, req)
    84  }