common

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 14 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 (
	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}"
	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")
)
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 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 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

MintObjectIDFromChecksum returns a deterministic UUID for a checksum. The generated UUID is scoped to the first lexical "org/project" authorization when available, which avoids cross-project collisions for identical content.

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 WithRequestID

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

Types

type AuthzContextKey

type AuthzContextKey string
const (
	// UserAuthzKey is the context key for the user's authorized resources list
	UserAuthzKey AuthzContextKey = "user_authz"
	// UserPrivilegesKey stores method-aware privileges (resource -> method -> allowed).
	UserPrivilegesKey AuthzContextKey = "user_privileges"
	// AuthHeaderPresentKey indicates whether the incoming request had an Authorization header.
	AuthHeaderPresentKey AuthzContextKey = "auth_header_present"
	// AuthModeKey contains the configured server mode: local or gen3.
	AuthModeKey AuthzContextKey = "auth_mode"

	// 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"

	// SubjectKey is the context key for the authenticated subject (user/principal)
	SubjectKey AuthzContextKey = "subject"
	// ClaimsKey is the context key for the authenticated claims (map[string]interface{})
	ClaimsKey AuthzContextKey = "claims"
)
const RequestIDKey AuthzContextKey = "request_id"

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