storageaccessor

package
v1.0.1-0...-b7ad348 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright 2024 Google LLC

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.

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.

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StorageAccessor

type StorageAccessor interface {
	// Create a GCS bucket with the given name in the input projectId and location. If ttl is > 0,
	// also apply a delete lifecycle rule with the input ttl and prefixes. Set @ttl to 0 to skip creating lifecycle rules.
	CreateGCSBucket(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
	// Applies the bucket lifecycle with delete rule. Only accepts the Age and prefix rule conditions as it is only used for the Datastream destination
	// bucket currently.
	ApplyBucketLifecycleDeleteRule(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
	// UploadLocalFileToGCS uploads a local file at @localFilePath to a gcs file path @filePath with name @fileName.
	UploadLocalFileToGCS(ctx context.Context, sc storageclient.StorageClient, filePath, fileName, localFilePath string) error
	// Uploads a gcs object to gs://@filePath/@fileName with @data as content.
	WriteDataToGCS(ctx context.Context, sc storageclient.StorageClient, filePath, fileName, data string) error
	// Read a Gcs file path and returns the contents as a string.
	ReadGcsFile(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)
	// Read a local or gcs file path. Files starting with a 'gs://' are treated as GCS files.
	ReadAnyFile(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)
	// Delete a given gcs bucket
	DeleteGCSBucket(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
}

The StorageAccessor provides methods that internally use a storage client. Methods should only contain generic logic here that can be used by multiple workflows.

type StorageAccessorImpl

type StorageAccessorImpl struct{}

This implements the StorageAccessor interface. This is the primary implementation that should be used in all places other than tests.

func (*StorageAccessorImpl) ApplyBucketLifecycleDeleteRule

func (sa *StorageAccessorImpl) ApplyBucketLifecycleDeleteRule(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error

func (*StorageAccessorImpl) CreateGCSBucket

func (*StorageAccessorImpl) DeleteGCSBucket

func (*StorageAccessorImpl) ReadAnyFile

func (sa *StorageAccessorImpl) ReadAnyFile(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)

func (*StorageAccessorImpl) ReadGcsFile

func (sa *StorageAccessorImpl) ReadGcsFile(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)

func (*StorageAccessorImpl) UploadLocalFileToGCS

func (sa *StorageAccessorImpl) UploadLocalFileToGCS(ctx context.Context, sc storageclient.StorageClient, filePath, fileName, localFilePath string) error

func (*StorageAccessorImpl) WriteDataToGCS

func (sa *StorageAccessorImpl) WriteDataToGCS(ctx context.Context, sc storageclient.StorageClient, filePath, fileName, data string) error

type StorageAccessorMock

type StorageAccessorMock struct {
	CreateGCSBucketMock                func(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
	ApplyBucketLifecycleDeleteRuleMock func(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
	UploadLocalFileToGCSMock           func(ctx context.Context, sc storageclient.StorageClient, filePath, fileName, localFilePath string) error
	WriteDataToGCSMock                 func(ctx context.Context, sc storageclient.StorageClient, filePath, fileName, data string) error
	ReadGcsFileMock                    func(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)
	ReadAnyFileMock                    func(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)
	DeleteGCSBucketMock                func(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
}

Mock that implements the StorageAccessor interface. Pass in unit tests where StorageAccessor is an input parameter.

func (*StorageAccessorMock) ApplyBucketLifecycleDeleteRule

func (sam *StorageAccessorMock) ApplyBucketLifecycleDeleteRule(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error

func (*StorageAccessorMock) CreateGCSBucket

func (*StorageAccessorMock) DeleteGCSBucket

func (*StorageAccessorMock) ReadAnyFile

func (sam *StorageAccessorMock) ReadAnyFile(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)

func (*StorageAccessorMock) ReadGcsFile

func (sam *StorageAccessorMock) ReadGcsFile(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)

func (*StorageAccessorMock) UploadLocalFileToGCS

func (sam *StorageAccessorMock) UploadLocalFileToGCS(ctx context.Context, sc storageclient.StorageClient, filePath, fileName, localFilePath string) error

func (*StorageAccessorMock) WriteDataToGCS

func (sam *StorageAccessorMock) WriteDataToGCS(ctx context.Context, sc storageclient.StorageClient, filePath, fileName, data string) error

type StorageBucketMetadata

type StorageBucketMetadata struct {
	BucketName string
	// Not required for Updates.
	ProjectID string
	// Not required for Updates.
	Location      string
	Ttl           int64
	MatchesPrefix []string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL