remote

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigSchemaVersion  = "pinax.cloud.config.v1"
	SessionSchemaVersion = "pinax.cloud.session.v1"
)
View Source
const CreateIfAbsentRevision = "__pinax_create_if_absent__"
View Source
const CryptoEnvelopeSchemaVersion = "pinax.cloud.envelope.v1"
View Source
const ManifestSchemaVersion = "pinax.cloud.manifest.v1"
View Source
const MaxManifestFileBytes = 100 * 1024 * 1024

Variables

View Source
var (
	ErrObjectNotFound = errors.New("object not found")
	ErrConflict       = errors.New("revision conflict")
)
View Source
var ErrNotConfigured = errors.New("cloud not configured")

Functions

func BlobID

func BlobID(content []byte) string

func DecryptBlob

func DecryptBlob(key CryptoKey, envelope EncryptedEnvelope, aad []byte) ([]byte, error)

func EncryptionSecretRef

func EncryptionSecretRef(config Config) string

func IsNotConfigured

func IsNotConfigured(err error) bool

func IsSupportedScheme

func IsSupportedScheme(scheme string) bool

IsSupportedScheme returns true if the scheme has a registered factory.

func Logout

func Logout(root string) error

func PathHash

func PathHash(path string) string

func RedactedData

func RedactedData(state State) map[string]any

func Register

func Register(scheme string, factory StoreFactory)

Register registers a new BlobStore factory for a URI scheme.

Types

type BlobStore

type BlobStore interface {
	// Get retrieves the object. If not found, returns ErrObjectNotFound.
	Get(ctx context.Context, key string) (data []byte, rev string, err error)

	// Put uploads the object. baseRev is the expected current revision.
	// If baseRev is CreateIfAbsentRevision, the object must not exist.
	// If baseRev is not empty and doesn't match, returns ErrConflict.
	// Returns the new revision string.
	Put(ctx context.Context, key string, data []byte, baseRev string) (newRev string, err error)

	// Stat retrieves the revision of the object. If not found, returns ErrObjectNotFound.
	Stat(ctx context.Context, key string) (rev string, err error)

	// Delete removes the object.
	Delete(ctx context.Context, key string) error
}

BlobStore abstracts the underlying blind storage system (S3, File, etc.).

func NewStore

func NewStore(ctx context.Context, endpoint string) (BlobStore, error)

NewStore instantiates a BlobStore based on the endpoint URI scheme.

type CachedBlobStore

type CachedBlobStore struct {
	// contains filtered or unexported fields
}

CachedBlobStore decorates a BlobStore with local file caching for Get operations.

func NewCachedBlobStore

func NewCachedBlobStore(inner BlobStore, cacheDir string, maxSize int64) *CachedBlobStore

NewCachedBlobStore creates a new caching decorator.

func (*CachedBlobStore) Delete

func (c *CachedBlobStore) Delete(ctx context.Context, key string) error

Delete delegates to inner store and invalidates cache.

func (*CachedBlobStore) Get

func (c *CachedBlobStore) Get(ctx context.Context, key string) ([]byte, string, error)

Get retrieves the object, using cache when available.

func (*CachedBlobStore) Put

func (c *CachedBlobStore) Put(ctx context.Context, key string, data []byte, baseRev string) (string, error)

Put delegates to inner store and invalidates cache.

func (*CachedBlobStore) Stat

func (c *CachedBlobStore) Stat(ctx context.Context, key string) (string, error)

Stat delegates to inner store.

type ConditionalWriteCapability

type ConditionalWriteCapability interface {
	SupportsConditionalWrites() bool
}

ConditionalWriteCapability reports whether Put enforces baseRev preconditions durably.

type Config

type Config struct {
	SchemaVersion       string    `json:"schema_version" yaml:"schema_version"`
	BackendKind         string    `json:"backend_kind,omitempty" yaml:"backend_kind,omitempty"`
	Endpoint            string    `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
	WorkspaceID         string    `json:"workspace_id" yaml:"workspace_id"`
	DeviceID            string    `json:"device_id" yaml:"device_id"`
	SecretRef           string    `json:"secret_ref,omitempty" yaml:"secret_ref,omitempty"`
	EncryptionSecretRef string    `json:"encryption_secret_ref,omitempty" yaml:"encryption_secret_ref,omitempty"`
	S3                  *S3Config `json:"s3,omitempty" yaml:"s3,omitempty"`
	CreatedAt           string    `json:"created_at" yaml:"created_at"`
	UpdatedAt           string    `json:"updated_at" yaml:"updated_at"`
}

type CryptoKey

type CryptoKey struct {
	KeyID string
	// contains filtered or unexported fields
}

func DeriveKey

func DeriveKey(secretRef string) (CryptoKey, error)

type DeviceSession

type DeviceSession struct {
	SchemaVersion string `json:"schema_version"`
	SessionID     string `json:"session_id"`
	DeviceID      string `json:"device_id"`
	Status        string `json:"status"`
	IssuedAt      string `json:"issued_at"`
	UpdatedAt     string `json:"updated_at"`
}

type DoctorResult

type DoctorResult struct {
	Configured   bool   `json:"configured"`
	Status       string `json:"status"`
	Code         string `json:"code,omitempty"`
	Message      string `json:"message"`
	BackendKind  string `json:"backend_kind,omitempty"`
	AuthBoundary string `json:"auth_boundary,omitempty"`
	ServerAudit  bool   `json:"server_audit"`
	Endpoint     string `json:"endpoint,omitempty"`
	Workspace    string `json:"workspace_id,omitempty"`
	DeviceID     string `json:"device_id,omitempty"`
}

func Doctor

func Doctor(root string) DoctorResult

type EncryptedEnvelope

type EncryptedEnvelope struct {
	SchemaVersion string `json:"schema_version"`
	Alg           string `json:"alg"`
	KeyID         string `json:"key_id"`
	Nonce         string `json:"nonce"`
	Ciphertext    string `json:"ciphertext"`
	PlainSHA256   string `json:"plain_sha256"`
}

func EncryptBlob

func EncryptBlob(key CryptoKey, plaintext, aad []byte) (EncryptedEnvelope, error)

func EncryptManifest

func EncryptManifest(key CryptoKey, manifest Manifest) (EncryptedEnvelope, error)

type ExtendedBlobStore

type ExtendedBlobStore interface {
	BlobStore
	List(ctx context.Context, prefix string) ([]ObjectInfo, error)
	Exists(ctx context.Context, key string) (bool, error)
	BatchStat(ctx context.Context, keys []string) (map[string]string, error)
}

ExtendedBlobStore extends BlobStore with list and batch operations.

type FakeBlobCheckRequest

type FakeBlobCheckRequest struct {
	BlobIDs []string `json:"blob_ids"`
}

type FakeBlobCheckResponse

type FakeBlobCheckResponse struct {
	MissingBlobIDs []string `json:"missing_blob_ids"`
}

type FakeContractError

type FakeContractError struct {
	Code      string `json:"code"`
	Message   string `json:"message"`
	Retryable bool   `json:"retryable"`
}

type FakeContractErrorResponse

type FakeContractErrorResponse struct {
	Error FakeContractError `json:"error"`
}

type FakeErrorResponse

type FakeErrorResponse struct {
	Code            string `json:"code"`
	Message         string `json:"message"`
	CurrentRevision string `json:"current_revision,omitempty"`
}

type FakeManifestPutRequest

type FakeManifestPutRequest struct {
	BaseRevision string         `json:"base_revision"`
	Manifest     map[string]any `json:"manifest"`
}

type FakeManifestResponse

type FakeManifestResponse struct {
	Revision string         `json:"revision"`
	Manifest map[string]any `json:"manifest,omitempty"`
}

type FakeRevisionCommitRequest

type FakeRevisionCommitRequest struct {
	BaseRevision   string   `json:"base_revision"`
	RevisionID     string   `json:"revision_id,omitempty"`
	ManifestBlobID string   `json:"manifest_blob_id"`
	BlobIDs        []string `json:"blob_ids,omitempty"`
	DeviceID       string   `json:"device_id,omitempty"`
}

type FakeRevisionCommitResponse

type FakeRevisionCommitResponse struct {
	RevisionID     string `json:"revision_id"`
	ManifestBlobID string `json:"manifest_blob_id"`
}

type FakeRevisionResponse

type FakeRevisionResponse struct {
	RevisionID     string `json:"revision_id"`
	ManifestBlobID string `json:"manifest_blob_id"`
}

type FakeServer

type FakeServer struct {
	URL string
	// contains filtered or unexported fields
}

func NewFakeServer

func NewFakeServer() *FakeServer

func (*FakeServer) Close

func (s *FakeServer) Close()

type FileBackend

type FileBackend struct {
	// contains filtered or unexported fields
}

func NewFileBackend

func NewFileBackend(baseDir string) (*FileBackend, error)

func (*FileBackend) BatchStat

func (b *FileBackend) BatchStat(ctx context.Context, keys []string) (map[string]string, error)

BatchStat returns revisions for multiple keys.

func (*FileBackend) Delete

func (b *FileBackend) Delete(ctx context.Context, key string) error

func (*FileBackend) Exists

func (b *FileBackend) Exists(ctx context.Context, key string) (bool, error)

Exists checks if an object exists.

func (*FileBackend) Get

func (b *FileBackend) Get(ctx context.Context, key string) ([]byte, string, error)

func (*FileBackend) List

func (b *FileBackend) List(ctx context.Context, prefix string) ([]ObjectInfo, error)

List returns objects under the given prefix.

func (*FileBackend) Put

func (b *FileBackend) Put(ctx context.Context, key string, data []byte, baseRev string) (string, error)

func (*FileBackend) Stat

func (b *FileBackend) Stat(ctx context.Context, key string) (string, error)

func (*FileBackend) SupportsConditionalWrites

func (b *FileBackend) SupportsConditionalWrites() bool

type LoginRequest

type LoginRequest struct {
	Endpoint            string
	WorkspaceID         string
	DeviceID            string
	SecretRef           string
	EncryptionSecretRef string
	BackendKind         string
	S3                  *S3Config
	Now                 time.Time
}

type Manifest

type Manifest struct {
	SchemaVersion string           `json:"schema_version"`
	GeneratedAt   string           `json:"generated_at"`
	EntryCount    int              `json:"entry_count"`
	Entries       []ManifestEntry  `json:"entries"`
	Deletes       []ManifestDelete `json:"deletes,omitempty"`
}

func BuildManifest

func BuildManifest(root string) (Manifest, error)

func DecryptManifest

func DecryptManifest(key CryptoKey, envelope EncryptedEnvelope) (Manifest, error)

type ManifestDelete added in v0.1.3

type ManifestDelete struct {
	PathHash    string `json:"path_hash"`
	ObjectKind  string `json:"object_kind"`
	ObjectID    string `json:"object_id,omitempty"`
	TombstoneID string `json:"tombstone_id"`
	DeletedAt   string `json:"deleted_at,omitempty"`
	TrashBlobID string `json:"trash_blob_id,omitempty"`
}

type ManifestEntry

type ManifestEntry struct {
	Path       string `json:"path"`
	PathHash   string `json:"path_hash"`
	BlobID     string `json:"blob_id"`
	Size       int64  `json:"size"`
	SHA256     string `json:"sha256"`
	ObjectKind string `json:"object_kind,omitempty"`
	Mode       uint32 `json:"mode,omitempty"`
	MediaType  string `json:"media_type,omitempty"`
}

type ManifestFileTooLargeError added in v0.1.3

type ManifestFileTooLargeError struct {
	Path  string
	Size  int64
	Limit int64
}

func (*ManifestFileTooLargeError) Error added in v0.1.3

func (e *ManifestFileTooLargeError) Error() string

type ManifestUnsafePathError added in v0.1.3

type ManifestUnsafePathError struct{ Path string }

func (*ManifestUnsafePathError) Error added in v0.1.3

func (e *ManifestUnsafePathError) Error() string

type ObjectInfo

type ObjectInfo struct {
	Key          string
	Size         int64
	Revision     string
	LastModified time.Time
}

ObjectInfo describes a remote object.

type RcloneBackend

type RcloneBackend struct {
	// contains filtered or unexported fields
}

func NewRcloneBackend

func NewRcloneBackend(endpoint string) (*RcloneBackend, error)

func (*RcloneBackend) BatchStat

func (b *RcloneBackend) BatchStat(ctx context.Context, keys []string) (map[string]string, error)

func (*RcloneBackend) Delete

func (b *RcloneBackend) Delete(ctx context.Context, key string) error

func (*RcloneBackend) Exists

func (b *RcloneBackend) Exists(ctx context.Context, key string) (bool, error)

func (*RcloneBackend) Get

func (b *RcloneBackend) Get(ctx context.Context, key string) ([]byte, string, error)

func (*RcloneBackend) List

func (b *RcloneBackend) List(ctx context.Context, prefix string) ([]ObjectInfo, error)

func (*RcloneBackend) Put

func (b *RcloneBackend) Put(ctx context.Context, key string, data []byte, _ string) (string, error)

func (*RcloneBackend) Stat

func (b *RcloneBackend) Stat(ctx context.Context, key string) (string, error)

func (*RcloneBackend) SupportsConditionalWrites

func (b *RcloneBackend) SupportsConditionalWrites() bool

type S3Backend

type S3Backend struct {
	// contains filtered or unexported fields
}

func NewS3Backend

func NewS3Backend(ctx context.Context, bucket string, prefix string) (*S3Backend, error)

func NewS3BackendWithOptions

func NewS3BackendWithOptions(ctx context.Context, bucket string, prefix string, options S3BackendOptions) (*S3Backend, error)

func (*S3Backend) BatchStat

func (s *S3Backend) BatchStat(ctx context.Context, keys []string) (map[string]string, error)

BatchStat returns revisions for multiple keys.

func (*S3Backend) Delete

func (s *S3Backend) Delete(ctx context.Context, key string) error

func (*S3Backend) Exists

func (s *S3Backend) Exists(ctx context.Context, key string) (bool, error)

Exists checks if an object exists.

func (*S3Backend) Get

func (s *S3Backend) Get(ctx context.Context, key string) ([]byte, string, error)

func (*S3Backend) List

func (s *S3Backend) List(ctx context.Context, prefix string) ([]ObjectInfo, error)

List returns objects with the given prefix.

func (*S3Backend) Put

func (s *S3Backend) Put(ctx context.Context, key string, data []byte, baseRev string) (string, error)

func (*S3Backend) Stat

func (s *S3Backend) Stat(ctx context.Context, key string) (string, error)

func (*S3Backend) SupportsConditionalWrites

func (s *S3Backend) SupportsConditionalWrites() bool

type S3BackendOptions

type S3BackendOptions struct {
	EndpointURL string
	Region      string
	Profile     string
	PathStyle   bool
	PathMode    string
	API         string
}

type S3Config

type S3Config struct {
	Bucket          string `json:"bucket" yaml:"bucket"`
	Prefix          string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
	Endpoint        string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
	Region          string `json:"region,omitempty" yaml:"region,omitempty"`
	Profile         string `json:"profile,omitempty" yaml:"profile,omitempty"`
	AddressingStyle string `json:"addressing_style,omitempty" yaml:"addressing_style,omitempty"`
	PathStyle       bool   `json:"path_style,omitempty" yaml:"path_style,omitempty"`
}

type State

type State struct {
	Config  Config        `json:"config"`
	Session DeviceSession `json:"session"`
}

func Load

func Load(root string) (State, error)

func Login

func Login(root string, req LoginRequest) (State, error)

func (State) GetStore

func (s State) GetStore(ctx context.Context) (BlobStore, error)

type StoreFactory

type StoreFactory func(ctx context.Context, endpoint string) (BlobStore, error)

StoreFactory is a function signature for building a BlobStore.

Jump to

Keyboard shortcuts

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