github.com/cs3org/reva/v2@v2.27.7/internal/grpc/services/gateway/publicshareprovider.go (about)

     1  // Copyright 2018-2021 CERN
     2  //
     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  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // In applying this license, CERN does not waive the privileges and immunities
    16  // granted to it by virtue of its status as an Intergovernmental Organization
    17  // or submit itself to any jurisdiction.
    18  
    19  package gateway
    20  
    21  import (
    22  	"context"
    23  
    24  	gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
    25  	rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
    26  	link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
    27  	"github.com/cs3org/reva/v2/pkg/appctx"
    28  	"github.com/cs3org/reva/v2/pkg/errtypes"
    29  	"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
    30  	"github.com/pkg/errors"
    31  )
    32  
    33  func (s *svc) CreatePublicShare(ctx context.Context, req *link.CreatePublicShareRequest) (*link.CreatePublicShareResponse, error) {
    34  	log := appctx.GetLogger(ctx)
    35  	log.Info().Msg("create public share")
    36  
    37  	c, err := pool.GetPublicShareProviderClient(s.c.PublicShareProviderEndpoint)
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  
    42  	return c.CreatePublicShare(ctx, req)
    43  }
    44  
    45  func (s *svc) RemovePublicShare(ctx context.Context, req *link.RemovePublicShareRequest) (*link.RemovePublicShareResponse, error) {
    46  	log := appctx.GetLogger(ctx)
    47  	log.Info().Msg("remove public share")
    48  
    49  	driver, err := pool.GetPublicShareProviderClient(s.c.PublicShareProviderEndpoint)
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  	return driver.RemovePublicShare(ctx, req)
    54  }
    55  
    56  func (s *svc) GetPublicShareByToken(ctx context.Context, req *link.GetPublicShareByTokenRequest) (*link.GetPublicShareByTokenResponse, error) {
    57  	log := appctx.GetLogger(ctx)
    58  	log.Info().Msg("get public share by token")
    59  
    60  	driver, err := pool.GetPublicShareProviderClient(s.c.PublicShareProviderEndpoint)
    61  	if err != nil {
    62  		return nil, err
    63  	}
    64  
    65  	res, err := driver.GetPublicShareByToken(ctx, req)
    66  	if err != nil {
    67  		return nil, err
    68  	}
    69  
    70  	return res, nil
    71  }
    72  
    73  func (s *svc) GetPublicShare(ctx context.Context, req *link.GetPublicShareRequest) (*link.GetPublicShareResponse, error) {
    74  	log := appctx.GetLogger(ctx)
    75  	log.Info().Msg("get public share")
    76  
    77  	pClient, err := pool.GetPublicShareProviderClient(s.c.PublicShareProviderEndpoint)
    78  	if err != nil {
    79  		log.Err(err).Msg("error connecting to a public share provider")
    80  		return &link.GetPublicShareResponse{
    81  			Status: &rpc.Status{
    82  				Code: rpc.Code_CODE_INTERNAL,
    83  			},
    84  		}, nil
    85  	}
    86  
    87  	return pClient.GetPublicShare(ctx, req)
    88  }
    89  
    90  func (s *svc) ListPublicShares(ctx context.Context, req *link.ListPublicSharesRequest) (*link.ListPublicSharesResponse, error) {
    91  	log := appctx.GetLogger(ctx)
    92  	log.Info().Msg("listing public shares")
    93  
    94  	pClient, err := pool.GetPublicShareProviderClient(s.c.PublicShareProviderEndpoint)
    95  	if err != nil {
    96  		log.Err(err).Msg("error connecting to a public share provider")
    97  		return &link.ListPublicSharesResponse{
    98  			Status: &rpc.Status{
    99  				Code: rpc.Code_CODE_INTERNAL,
   100  			},
   101  		}, nil
   102  	}
   103  
   104  	res, err := pClient.ListPublicShares(ctx, req)
   105  	if err != nil {
   106  		return nil, errors.Wrap(err, "error listing shares")
   107  	}
   108  
   109  	return res, nil
   110  }
   111  
   112  func (s *svc) ListExistingPublicShares(_ context.Context, _ *link.ListPublicSharesRequest) (*gateway.ListExistingPublicSharesResponse, error) {
   113  	return nil, errtypes.NotSupported("method ListExistingPublicShares not implemented")
   114  }
   115  
   116  func (s *svc) UpdatePublicShare(ctx context.Context, req *link.UpdatePublicShareRequest) (*link.UpdatePublicShareResponse, error) {
   117  	log := appctx.GetLogger(ctx)
   118  	log.Info().Msg("update public share")
   119  
   120  	pClient, err := pool.GetPublicShareProviderClient(s.c.PublicShareProviderEndpoint)
   121  	if err != nil {
   122  		log.Err(err).Msg("error connecting to a public share provider")
   123  		return &link.UpdatePublicShareResponse{
   124  			Status: &rpc.Status{
   125  				Code: rpc.Code_CODE_INTERNAL,
   126  			},
   127  		}, nil
   128  	}
   129  
   130  	return pClient.UpdatePublicShare(ctx, req)
   131  }