common

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	S3Provider    = "s3"
	GCSProvider   = "gcs"
	AzureProvider = "azure"
	FileProvider  = "file"

	S3Prefix    = "s3://"
	GCSPrefix   = "gs://"
	AzurePrefix = "azblob://"
	DRSPrefix   = "drs://"
)
View Source
const (
	// BucketControlResource is the resource path for internal bucket management.
	BucketControlResource = "/services/internal/buckets"
	// MetricsIngestResource is the resource path for trusted provider metrics ingestion.
	MetricsIngestResource = "/services/internal/metrics"
)
View Source
const (
	RouteInternalDownload          = "/data/download/{file_id}"
	RouteInternalDownloadPart      = "/data/download/{file_id}/part"
	RouteInternalUpload            = "/data/upload"
	RouteInternalUploadURL         = "/data/upload/{file_id}"
	RouteInternalUploadBulk        = "/data/upload/bulk"
	RouteInternalMultipartInit     = "/data/multipart/init"
	RouteInternalMultipartUpload   = "/data/multipart/upload"
	RouteInternalMultipartComplete = "/data/multipart/complete"
	RouteInternalBuckets           = "/data/buckets"
	RouteInternalBucketDetail      = "/data/buckets/{bucket}"
	RouteInternalBucketScopes      = "/data/buckets/{bucket}/scopes"

	RouteInternalIndex                       = "/index"
	RouteInternalIndexDetail                 = "/index/{id}"
	RouteInternalIndexControlledAccessRemove = "/index/{id}/controlled-access/remove"
	RouteInternalBulkHashes                  = "/index/bulk/hashes"
	RouteInternalBulkDeleteHashes            = "/index/bulk/delete"
	RouteInternalBulkSHA256                  = "/index/bulk/sha256/validity"
	RouteInternalBulkCreate                  = "/index/bulk"
	RouteInternalBulkDocs                    = "/index/bulk/documents"
)
View Source
const RequestIDHeader = "X-Request-Id"

Variables

View Source
var (
	ErrNotFound     = errors.New("not found")
	ErrUnauthorized = errors.New("unauthorized")
	ErrConflict     = errors.New("conflict")
	ErrInvalidInput = errors.New("invalid input")
)
View Source
var ErrNoValidSHA256 = errors.New("no valid sha256 values provided")

Functions

func AuditS3CredentialAccess

func AuditS3CredentialAccess(ctx context.Context, action string, bucket string, err error)

AuditS3CredentialAccess logs credential access events with request/mode context.

func BucketToURL

func BucketToURL(bucket, key string) string

BucketToURL converts a bucket and key to an s3:// URL.

func CanonicalSHA256

func CanonicalSHA256(checksums []drs.Checksum) (string, bool)

CanonicalSHA256 pulls the sha256 value from a list of checksums if it exists.

func ContentDispositionAttachment added in v0.2.8

func ContentDispositionAttachment(name string) string

ContentDispositionAttachment returns a conservative attachment disposition for a download filename, including RFC 5987 UTF-8 encoding.

func DerefString

func DerefString(p *string) string

DerefString is a legacy alias for StringVal.

func DerefStringSlice

func DerefStringSlice(p *[]string) []string

DerefStringSlice returns a copy of the slice or nil when the pointer is nil.

func DownloadFilename added in v0.2.8

func DownloadFilename(name string) string

DownloadFilename returns the basename to present to clients for downloads. Object names may carry storage-relative paths; download UX should not.

func FloatVal

func FloatVal(p *float64) float64

FloatVal returns the float64 value if not nil, otherwise 0.0.

func GetRequestID

func GetRequestID(ctx context.Context) string

func Int64Val

func Int64Val(p *int64) int64

Int64Val returns the int64 value if not nil, otherwise 0.

func IntVal

func IntVal(p *int) int

IntVal returns the int value if not nil, otherwise 0.

func IsNotFoundError

func IsNotFoundError(err error) bool

func IsUnauthorizedError

func IsUnauthorizedError(err error) bool

func LooksLikeSHA256

func LooksLikeSHA256(v string) bool

LooksLikeSHA256 checks if a string matches the format of a SHA256 hash.

func MergeAdditionalChecksums

func MergeAdditionalChecksums(existing []drs.Checksum, additions []drs.Checksum) []drs.Checksum

MergeAdditionalChecksums merges new checksums into an existing set, avoiding duplicate types.

func MintObjectIDFromChecksum

func MintObjectIDFromChecksum(checksum string, authz []string) (string, error)

MintObjectIDFromChecksum returns a deterministic UUID for a checksum and a single canonical project scope. The generated UUID is stable across instances for the same sha256 and normalized project resource path.

func NormalizeChecksum

func NormalizeChecksum(cs string) string

NormalizeChecksum removes any "sha256:" prefixes if present.

func NormalizeChecksumType

func NormalizeChecksumType(checksumType string) string

NormalizeChecksumType cleans up a checksum type string (lowercase, remove hyphens).

func NormalizeProvider

func NormalizeProvider(p string, fallback string) string

func NormalizeSHA256

func NormalizeSHA256(values []string) []string

NormalizeSHA256 cleans and dedups a list of potential SHA256 hashes.

func NormalizeStoragePath

func NormalizeStoragePath(rawPath, bucket string) (string, error)

func NormalizeUploadKey

func NormalizeUploadKey(inputKey, id string) string

NormalizeUploadKey ensures a key is valid for upload and defaults to ID if empty.

func ObjectHasChecksumTypeAndValue

func ObjectHasChecksumTypeAndValue(obj models.InternalObject, hashType string, hashValue string) bool

func ObjectURLForCredential

func ObjectURLForCredential(cred *models.S3Credential, key string) (string, error)

func ParseBucketProvider

func ParseBucketProvider(raw string) (string, error)

ParseBucketProvider returns a canonical bucket provider name or an error for unsupported values.

func ParseHashQuery

func ParseHashQuery(rawHash string, rawType string) (string, string)

ParseHashQuery parses a checksum string that might be in "type:value" format.

func ParseS3URL

func ParseS3URL(raw string) (bucket string, key string, ok bool)

ParseS3URL extracts bucket/key pairs from an s3:// URL.

func ProviderFromScheme

func ProviderFromScheme(scheme string) string

func ProviderToScheme

func ProviderToScheme(p string) string

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to the value passed in.

func SchemeFromURL

func SchemeFromURL(raw string) string

SchemeFromURL extracts the scheme from a URL string.

func StringVal

func StringVal(p *string) string

StringVal returns the string value if not nil, otherwise empty string.

func TimeVal

func TimeVal(p *time.Time) time.Time

TimeVal returns the time value if not nil, otherwise zero time.

func UniqueStrings

func UniqueStrings(values []string) []string

UniqueStrings returns a deduped slice of strings, preserving order.

func UniqueStringsCaseInsensitive

func UniqueStringsCaseInsensitive(values []string) []string

UniqueStringsCaseInsensitive returns a deduped slice of strings based on lowercase comparison, preserving the first-seen original string.

func Val

func Val[T any](p *T, def T) T

Val returns the value of the pointer if not nil, otherwise the default value.

func ValidateBucketName

func ValidateBucketName(providerName, bucketName string) error

ValidateBucketName validates a bucket/container name for the given provider.

The rules are intentionally provider-specific: - s3 and azure share the stricter DNS-style naming rules. - gcs permits dots and underscores but still requires a DNS-safe shape.

func ValidateBucketNameWithEndpoint added in v0.2.8

func ValidateBucketNameWithEndpoint(providerName, bucketName, endpoint string) error

ValidateBucketNameWithEndpoint validates a bucket/container name for the given provider and endpoint. S3-compatible backends with a custom endpoint may allow bucket names that would be invalid for AWS virtual-hosted DNS names.

func WithRequestID

func WithRequestID(ctx context.Context, requestID string) context.Context

Types

type AuthorizationError added in v0.2.8

type AuthorizationError struct {
	Method             string
	RecordID           string
	Resources          []string
	DeniedRecords      int
	TotalRecords       int
	TruncatedResources int
}

func (*AuthorizationError) Error added in v0.2.8

func (e *AuthorizationError) Error() string

func (*AuthorizationError) PublicMessage added in v0.2.8

func (e *AuthorizationError) PublicMessage() string

func (*AuthorizationError) Unwrap added in v0.2.8

func (e *AuthorizationError) Unwrap() error

type AuthzContextKey

type AuthzContextKey string
const RequestIDKey AuthzContextKey = "request_id"

type PublicError added in v0.2.8

type PublicError interface {
	PublicMessage() string
}

type ResourceScope

type ResourceScope struct {
	Organization string
	Project      string
}

func ParseResourcePath

func ParseResourcePath(path string) ResourceScope

Jump to

Keyboard shortcuts

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