Dragonfly2
59 строк · 1.6 Кб
1/*
2* Copyright 2022 The Dragonfly 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
17package service
18
19import (
20"context"
21"errors"
22
23"d7y.io/dragonfly/v2/manager/types"
24"d7y.io/dragonfly/v2/pkg/objectstorage"
25)
26
27var ErrObjectStorageDisabled = errors.New("object storage is disabled")
28
29func (s *service) CreateBucket(ctx context.Context, json types.CreateBucketRequest) error {
30if s.objectStorage == nil {
31return ErrObjectStorageDisabled
32}
33
34return s.objectStorage.CreateBucket(ctx, json.Name)
35}
36
37func (s *service) DestroyBucket(ctx context.Context, id string) error {
38if s.objectStorage == nil {
39return ErrObjectStorageDisabled
40}
41
42return s.objectStorage.DeleteBucket(ctx, id)
43}
44
45func (s *service) GetBucket(ctx context.Context, id string) (*objectstorage.BucketMetadata, error) {
46if s.objectStorage == nil {
47return nil, ErrObjectStorageDisabled
48}
49
50return s.objectStorage.GetBucketMetadata(ctx, id)
51}
52
53func (s *service) GetBuckets(ctx context.Context) ([]*objectstorage.BucketMetadata, error) {
54if s.objectStorage == nil {
55return nil, ErrObjectStorageDisabled
56}
57
58return s.objectStorage.ListBucketMetadatas(ctx)
59}
60