Path: blob/main/components/content-service/pkg/service/content-service.go
2499 views
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package service56import (7"context"89"github.com/opentracing/opentracing-go"10"google.golang.org/grpc/codes"11"google.golang.org/grpc/status"1213"github.com/gitpod-io/gitpod/common-go/log"14"github.com/gitpod-io/gitpod/common-go/tracing"15"github.com/gitpod-io/gitpod/content-service/api"16"github.com/gitpod-io/gitpod/content-service/api/config"17"github.com/gitpod-io/gitpod/content-service/pkg/storage"18)1920// ContentService implements ContentServiceServer21type ContentService struct {22cfg config.StorageConfig23s storage.PresignedAccess2425api.UnimplementedContentServiceServer26}2728// NewContentService create a new content service29func NewContentService(cfg config.StorageConfig) (res *ContentService, err error) {30s, err := storage.NewPresignedAccess(&cfg)31if err != nil {32return nil, err33}34return &ContentService{cfg: cfg, s: s}, nil35}3637// DeleteUserContent deletes all content associated with a user.38func (cs *ContentService) DeleteUserContent(ctx context.Context, req *api.DeleteUserContentRequest) (resp *api.DeleteUserContentResponse, err error) {39span, ctx := opentracing.StartSpanFromContext(ctx, "DeleteUserContent")40span.SetTag("user", req.OwnerId)41defer tracing.FinishSpan(span, &err)4243bucket := cs.s.Bucket(req.OwnerId)44err = cs.s.DeleteBucket(ctx, req.OwnerId, bucket)45// TODO46if err == storage.ErrNotFound {47log.WithFields(log.OWI(req.OwnerId, "", "")).Debug("DeleteUserContent: NotFound")48return &api.DeleteUserContentResponse{}, nil49}50if err != nil {51log.WithFields(log.OWI(req.OwnerId, "", "")).WithError(err).Error("DeleteUserContent: failed")52return nil, status.Error(codes.Unknown, err.Error())53}54log.WithFields(log.OWI(req.OwnerId, "", "")).Debug("DeleteUserContent: done")55return &api.DeleteUserContentResponse{}, nil56}575859