cloudstorage

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const SourceType string = "cloud-storage"

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name    string `yaml:"name" validate:"required"`
	Type    string `yaml:"type" validate:"required"`
	Project string `yaml:"project" validate:"required"`
}

func (Config) Initialize

func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error)

func (Config) SourceConfigType

func (r Config) SourceConfigType() string

type Source

type Source struct {
	Config
	// contains filtered or unexported fields
}

func (*Source) CopyObject

func (s *Source) CopyObject(ctx context.Context, sourceBucket, sourceObject, destinationBucket, destinationObject string) (map[string]any, error)

CopyObject copies an object to a destination object. The destination may be in the same bucket or a different bucket. Existing destination objects are replaced, matching Cloud Storage's copy semantics without preconditions.

func (*Source) CreateBucket

func (s *Source) CreateBucket(ctx context.Context, bucket, location string, uniformBucketLevelAccess bool) (map[string]any, error)

CreateBucket creates a Cloud Storage bucket in the source project and returns its freshly-read metadata. When location is empty, Cloud Storage applies its service default.

func (*Source) DeleteBucket

func (s *Source) DeleteBucket(ctx context.Context, bucket string) (map[string]any, error)

DeleteBucket deletes an empty Cloud Storage bucket.

func (*Source) DeleteObject

func (s *Source) DeleteObject(ctx context.Context, bucket, object string) (map[string]any, error)

DeleteObject deletes a GCS object.

func (*Source) DownloadObject

func (s *Source) DownloadObject(ctx context.Context, bucket, object, destination string, overwrite bool) (map[string]any, error)

DownloadObject streams a GCS object to destination on the local filesystem. Unlike ReadObject there is no size cap and no UTF-8 check — the bytes go to disk, not into the LLM context, so binary payloads are fine. When overwrite is false, a pre-existing destination returns cloudstoragecommon.ErrDestinationExists (mapped to AgentError so the caller can retry with overwrite=true).

func (*Source) GetBucketIAMPolicy

func (s *Source) GetBucketIAMPolicy(ctx context.Context, bucket string) (map[string]any, error)

GetBucketIAMPolicy returns bucket IAM bindings in a stable, agent-friendly shape while preserving conditional bindings when present.

func (*Source) GetBucketMetadata

func (s *Source) GetBucketMetadata(ctx context.Context, bucket string) (*storage.BucketAttrs, error)

GetBucketMetadata returns raw bucket metadata from the Cloud Storage client.

func (*Source) GetObjectMetadata

func (s *Source) GetObjectMetadata(ctx context.Context, bucket, object string) (*storage.ObjectAttrs, error)

GetObjectMetadata returns the raw *storage.ObjectAttrs for an object, giving callers the full field set the GCS client exposes (name, size, contentType, hashes, timestamps, user metadata, etc.) without a curated subset.

func (*Source) GetProjectID

func (s *Source) GetProjectID() string

func (*Source) ListBuckets

func (s *Source) ListBuckets(ctx context.Context, project, prefix string, maxResults int, pageToken string) (map[string]any, error)

ListBuckets lists buckets in a project. When project is empty, the source's configured project is used. maxResults == 0 returns up to the GCS per-page default (1000). A non-empty pageToken resumes listing. The returned map contains "buckets" ([]*storage.BucketAttrs) and "nextPageToken" (empty when there are no more results).

func (*Source) ListObjects

func (s *Source) ListObjects(ctx context.Context, bucket, prefix, delimiter string, maxResults int, pageToken string) (map[string]any, error)

ListObjects lists objects in a bucket with optional prefix and delimiter filtering. maxResults == 0 means return up to one page as returned by the GCS API. A non-empty pageToken resumes listing from a prior call. The returned map contains "objects" (raw *storage.ObjectAttrs entries as returned by the GCS client), "prefixes" (common prefixes when a delimiter is set), and "nextPageToken" (empty when there are no more results).

func (*Source) MoveObject

func (s *Source) MoveObject(ctx context.Context, bucket, sourceObject, destinationObject string) (map[string]any, error)

MoveObject atomically renames or moves an object within the same bucket using Cloud Storage's native move API. Cross-bucket moves should be modeled as CopyObject followed by DeleteObject.

func (*Source) ReadObject

func (s *Source) ReadObject(ctx context.Context, bucket, object string, offset, length int64) (map[string]any, error)

ReadObject fetches an object's bytes and returns a map with the UTF-8 content, its content type, and the number of bytes read. offset and length follow storage.ObjectHandle.NewRangeReader semantics: length == -1 means "read to end of object"; a negative offset means "suffix from end" (in which case length must be -1). Reads larger than defaultMaxReadBytes are rejected with cloudstoragecommon.ErrReadSizeLimitExceeded so the caller can narrow the range. Objects whose bytes are not valid UTF-8 are rejected with cloudstoragecommon.ErrBinaryContent.

TODO: MCP tool results only carry text today, so we gate this tool on utf8.Valid. When the toolbox supports non-text MCP content (embedded resources, images, blobs), expand this to detect content type and return binary payloads natively.

func (*Source) SourceType

func (s *Source) SourceType() string

func (*Source) StorageClient

func (s *Source) StorageClient() *storage.Client

func (*Source) ToConfig

func (s *Source) ToConfig() sources.SourceConfig

func (*Source) UploadObject

func (s *Source) UploadObject(ctx context.Context, bucket, object, source, contentType string) (map[string]any, error)

UploadObject streams a local file into a GCS object. When contentType is empty, mime.TypeByExtension is consulted; if inference still fails the writer's ContentType is left unset so GCS content-sniffs the first 512 bytes. The returned contentType is the post-Close value from w.Attrs(), i.e. what GCS actually recorded.

func (*Source) WriteObject

func (s *Source) WriteObject(ctx context.Context, bucket, object, content, contentType string) (map[string]any, error)

WriteObject writes text content directly into a GCS object. When contentType is empty, the writer's ContentType is left unset so Cloud Storage detects it from the first 512 bytes. The returned contentType is the post-Close value from w.Attrs(), i.e. what GCS actually recorded.

Jump to

Keyboard shortcuts

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