Skip to content

Commit

Permalink
add gcp storage wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
Amruta Kale committed Jan 16, 2024
1 parent b945668 commit 6a2c0aa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
54 changes: 54 additions & 0 deletions pkg/kopialib/storage/gcp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2024 The Kanister Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package storage

import (
"context"

"github.com/kanisterio/kanister/pkg/kopialib"
"github.com/kanisterio/kanister/pkg/utils"
"github.com/kopia/kopia/repo/blob"
"github.com/kopia/kopia/repo/blob/gcs"
)

var _ Storage = &gcpStorage{}

type gcpStorage struct {
Options *gcs.Options
Create bool
}

func (g *gcpStorage) Connect() (blob.Storage, error) {
return gcs.New(context.Background(), g.Options, g.Create)
}

func (g *gcpStorage) WithOptions(opts gcs.Options) {
g.Options = &opts
}

func (g *gcpStorage) WithCreate(create bool) {
g.Create = create
}

func (g *gcpStorage) SetOptions(ctx context.Context, options map[string]string) error {
g.Options = &gcs.Options{
Prefix: options[kopialib.PrefixKey],
BucketName: options[kopialib.BucketKey],
ServiceAccountCredentialsFile: options[kopialib.GCPServiceAccountCredentialsFile],
}

g.Options.ReadOnly, _ = utils.GetBoolOrDefault(options[kopialib.GCPReadOnly], false)
return nil
}
2 changes: 2 additions & 0 deletions pkg/kopialib/storage/storage_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func New(storageType StorageType) Storage {
switch storageType {
case TypeS3:
return &s3Storage{}
case TypeGCP:
return &gcpStorage{}
default:
return nil
}
Expand Down

0 comments on commit 6a2c0aa

Please sign in to comment.