Documentation
¶
Index ¶
- Constants
- Variables
- func AgenticScanResultKey(agenticScanUUID string) string
- func IsGCSURI(s string) bool
- func NativeScanResultKey(scanUUID string) string
- func NormalizeGCSURI(s string) string
- func ParseGCSPath(uri string) (projectUUID, key string, err error)
- func ResolveGCSSource(storageCfg *config.StorageConfig, sourcePath, projectUUID string) (extractedPath string, cleanup func(), err error)
- func StorageURL(projectUUID, key string) string
- func StripBucketPrefix(uri, bucket string) string
- func UGCKey(filename string) string
- func ValidateKey(key string) (string, error)
- func ValidateProjectUUID(projectUUID string) error
- type Client
- func (c *Client) BundleAndUploadFiles(ctx context.Context, projectUUID, key string, filePaths map[string]string) (string, error)
- func (c *Client) BundleAndUploadResults(ctx context.Context, projectUUID, key, sourceDir string) (string, error)
- func (c *Client) Delete(ctx context.Context, projectUUID, key string) error
- func (c *Client) Download(ctx context.Context, projectUUID, key string) (io.ReadCloser, error)
- func (c *Client) DownloadAndExtractSource(ctx context.Context, projectUUID, key string) (string, string, error)
- func (c *Client) DownloadToFile(ctx context.Context, projectUUID, key, destPath string) error
- func (c *Client) List(ctx context.Context, projectUUID, prefix string) ([]ObjectInfo, error)
- func (c *Client) PresignedGetURL(ctx context.Context, projectUUID, key string, expiry time.Duration) (string, error)
- func (c *Client) PresignedPutURL(ctx context.Context, projectUUID, key string, expiry time.Duration) (string, error)
- func (c *Client) Stat(ctx context.Context, projectUUID, key string) (ObjectInfo, error)
- func (c *Client) Upload(ctx context.Context, projectUUID, key string, reader io.Reader, size int64, ...) error
- func (c *Client) UploadFile(ctx context.Context, projectUUID, key, filePath string) error
- type ObjectInfo
Constants ¶
const ( // SchemeGCS is the canonical Google Cloud Storage URI scheme used by // gsutil and emitted by every URL we generate (StorageURL, exports, etc.). SchemeGCS = "gs://" // SchemeGCSAlias is accepted on input as a synonym for SchemeGCS so users // who type "gcs://" (the service abbreviation) get the same behavior. // Output is always normalized to SchemeGCS. SchemeGCSAlias = "gcs://" PathNativeScans = "native-scans" PathAgenticScans = "agentic-scans" PathUGC = "ugc" ResultsBundleName = "results.tar.gz" )
Variables ¶
var ErrObjectNotFound = errors.New("object not found")
ErrObjectNotFound is returned by Stat when the object is absent. Callers distinguish it from a transport/credential failure so a genuine outage isn't reported to the client as a 404.
var ErrPathTraversal = fmt.Errorf("path contains traversal or invalid characters")
Functions ¶
func AgenticScanResultKey ¶
AgenticScanResultKey returns the storage key for an agentic scan result bundle.
func IsGCSURI ¶
IsGCSURI reports whether s starts with the canonical SchemeGCS prefix or the SchemeGCSAlias synonym. Use this instead of strings.HasPrefix(s, "gs://") at any user-input boundary so "gcs://" works interchangeably.
func NativeScanResultKey ¶
NativeScanResultKey returns the storage key for a native scan result bundle.
func NormalizeGCSURI ¶
NormalizeGCSURI rewrites a "gcs://" prefix to "gs://" so downstream code can keep matching a single canonical form. URIs that already use the canonical prefix (or neither) are returned unchanged.
func ParseGCSPath ¶
ParseGCSPath parses a gs://<project-uuid>/<key> URI into project UUID and key. The "gcs://" alias is accepted and normalized to the canonical "gs://" form before parsing. Returns empty strings if the URI doesn't match the expected format.
func ResolveGCSSource ¶
func ResolveGCSSource(storageCfg *config.StorageConfig, sourcePath, projectUUID string) (extractedPath string, cleanup func(), err error)
ResolveGCSSource downloads and extracts a gs://<project>/<key> archive into a temp directory. The returned cleanup must be invoked once the run is done to remove the temp tree. When projectUUID is empty, it falls back to the project component parsed from the URI.
func StorageURL ¶
StorageURL builds a gs:// URL from project UUID and key.
func StripBucketPrefix ¶
StripBucketPrefix collapses gsutil-style "gs://<bucket>/<rest>" URIs to the project-relative "gs://<rest>" form expected by ParseGCSPath. The console's upload path emits gs://<bucket>/<projectUUID>/<key> (lib/storage-shared.ts), while ParseGCSPath expects gs://<projectUUID>/<key>; without this collapse the two layers disagree on whether the first segment is the bucket or the project. URIs whose first segment doesn't match bucket — and non-gs:// URIs — are returned unchanged.
func ValidateKey ¶
ValidateKey rejects keys that attempt path traversal or project scope escape. Returns the cleaned key or an error.
func ValidateProjectUUID ¶
ValidateProjectUUID rejects project UUIDs that contain path separators or traversal.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps minio-go to provide project-scoped object storage operations.
func NewClient ¶
func NewClient(cfg *config.StorageConfig) (*Client, error)
NewClient creates a storage client from the StorageConfig.
func (*Client) BundleAndUploadFiles ¶
func (c *Client) BundleAndUploadFiles(ctx context.Context, projectUUID, key string, filePaths map[string]string) (string, error)
BundleAndUploadFiles creates a tar.gz of specific files and uploads it. filePaths is a map of arcName → localPath.
func (*Client) BundleAndUploadResults ¶
func (c *Client) BundleAndUploadResults(ctx context.Context, projectUUID, key, sourceDir string) (string, error)
BundleAndUploadResults creates a tar.gz of the given directory and uploads it.
func (*Client) Download ¶
Download returns a reader for the specified object. Caller must close the returned reader.
func (*Client) DownloadAndExtractSource ¶
func (c *Client) DownloadAndExtractSource(ctx context.Context, projectUUID, key string) (string, string, error)
DownloadAndExtractSource downloads an archive from storage and extracts it to a temp directory. The format is dispatched off the key's extension to match the formats the console upload route accepts (zip, tar.gz/tgz, tar). Returns the path to the extracted source and the temp root directory. Callers should defer os.RemoveAll(tmpRoot) to clean up.
func (*Client) DownloadToFile ¶
func (*Client) PresignedGetURL ¶
func (*Client) PresignedPutURL ¶
func (*Client) Stat ¶
Stat returns metadata for a single object without transferring its body.
It doubles as the existence probe: minio's GetObject is lazy and only fails on first Read, so a caller that needs to fall back to another key on a miss — or to answer 404 before committing response headers — must ask first, and Stat's size is what a streaming download needs for Content-Length. One StatObject round trip serves both.