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.
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.
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.
Index ¶
- type StorageAccessor
- type StorageAccessorImpl
- func (sa *StorageAccessorImpl) ApplyBucketLifecycleDeleteRule(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
- func (sa *StorageAccessorImpl) CreateGCSBucket(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
- func (sa *StorageAccessorImpl) DeleteGCSBucket(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
- func (sa *StorageAccessorImpl) ReadAnyFile(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)
- func (sa *StorageAccessorImpl) ReadGcsFile(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)
- func (sa *StorageAccessorImpl) UploadLocalFileToGCS(ctx context.Context, sc storageclient.StorageClient, ...) error
- func (sa *StorageAccessorImpl) WriteDataToGCS(ctx context.Context, sc storageclient.StorageClient, ...) error
- type StorageAccessorMock
- func (sam *StorageAccessorMock) ApplyBucketLifecycleDeleteRule(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
- func (sam *StorageAccessorMock) CreateGCSBucket(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
- func (sam *StorageAccessorMock) DeleteGCSBucket(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
- func (sam *StorageAccessorMock) ReadAnyFile(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)
- func (sam *StorageAccessorMock) ReadGcsFile(ctx context.Context, sc storageclient.StorageClient, filePath string) (string, error)
- func (sam *StorageAccessorMock) UploadLocalFileToGCS(ctx context.Context, sc storageclient.StorageClient, ...) error
- func (sam *StorageAccessorMock) WriteDataToGCS(ctx context.Context, sc storageclient.StorageClient, ...) error
- type StorageBucketMetadata
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 (sa *StorageAccessorImpl) CreateGCSBucket(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
func (*StorageAccessorImpl) DeleteGCSBucket ¶
func (sa *StorageAccessorImpl) DeleteGCSBucket(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
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 (sam *StorageAccessorMock) CreateGCSBucket(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
func (*StorageAccessorMock) DeleteGCSBucket ¶
func (sam *StorageAccessorMock) DeleteGCSBucket(ctx context.Context, sc storageclient.StorageClient, req StorageBucketMetadata) error
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