Documentation
¶
Index ¶
- Constants
- type Bucket
- type BucketConfig
- type BucketManager
- func (bm *BucketManager) CloseAll() error
- func (bm *BucketManager) GetBucket(name string) (*Bucket, error)
- func (bm *BucketManager) GetDefaultBucket() (*Bucket, error)
- func (bm *BucketManager) GetDefaultBucketName() string
- func (bm *BucketManager) ListBuckets() []string
- func (bm *BucketManager) RegisterBucket(ctx context.Context, name string, bucketCfg *BucketConfig) error
- func (bm *BucketManager) RemoveBucket(name string) error
- func (bm *BucketManager) SetDefault(name string) error
- func (bm *BucketManager) SetServers(servers map[string]*ServerConfig)
- type CommonPrefix
- type Config
- type Configurer
- type CopyRequest
- type CopyResponse
- type DeleteRequest
- type DeleteResponse
- type ErrorCode
- type ExistsRequest
- type ExistsResponse
- type GetMetadataRequest
- type GetMetadataResponse
- type GetPublicURLRequest
- type GetPublicURLResponse
- type ListBucketsRequest
- type ListBucketsResponse
- type ListObjectsRequest
- type ListObjectsResponse
- type Logger
- type MoveRequest
- type MoveResponse
- type ObjectInfo
- type Operations
- func (o *Operations) Copy(ctx context.Context, req *CopyRequest, resp *CopyResponse) error
- func (o *Operations) Delete(ctx context.Context, req *DeleteRequest, resp *DeleteResponse) error
- func (o *Operations) Exists(ctx context.Context, req *ExistsRequest, resp *ExistsResponse) error
- func (o *Operations) GetMetadata(ctx context.Context, req *GetMetadataRequest, resp *GetMetadataResponse) error
- func (o *Operations) GetPublicURL(ctx context.Context, req *GetPublicURLRequest, resp *GetPublicURLResponse) error
- func (o *Operations) ListObjects(ctx context.Context, req *ListObjectsRequest, resp *ListObjectsResponse) error
- func (o *Operations) Move(ctx context.Context, req *MoveRequest, resp *MoveResponse) error
- func (o *Operations) Read(ctx context.Context, req *ReadRequest, resp *ReadResponse) error
- func (o *Operations) SetVisibility(ctx context.Context, req *SetVisibilityRequest, resp *SetVisibilityResponse) error
- func (o *Operations) Write(ctx context.Context, req *WriteRequest, resp *WriteResponse) error
- type Plugin
- func (p *Plugin) Collects() []*dep.In
- func (p *Plugin) CompleteOperation()
- func (p *Plugin) GetBucketManager() *BucketManager
- func (p *Plugin) GetContext() context.Context
- func (p *Plugin) Init(cfg Configurer, log Logger) error
- func (p *Plugin) MetricsCollector() []prometheus.Collector
- func (p *Plugin) Name() string
- func (p *Plugin) RPC() interface{}
- func (p *Plugin) Serve() chan error
- func (p *Plugin) Stop(ctx context.Context) error
- func (p *Plugin) TrackOperation()
- func (p *Plugin) Weight() uint
- type ReadRequest
- type ReadResponse
- type RegisterBucketRequest
- type RegisterBucketResponse
- type S3Error
- func NewBucketNotFoundError(bucketName string) *S3Error
- func NewFileNotFoundError(pathname string) *S3Error
- func NewInvalidConfigError(reason string) *S3Error
- func NewInvalidPathnameError(pathname string, reason string) *S3Error
- func NewPermissionDeniedError(operation string) *S3Error
- func NewS3Error(code ErrorCode, message string, details string) *S3Error
- func NewS3OperationError(operation string, err error) *S3Error
- type ServerConfig
- type ServerCredentials
- type SetVisibilityRequest
- type SetVisibilityResponse
- type WriteRequest
- type WriteResponse
Constants ¶
const (
// PluginName is the name of the S3 plugin
PluginName = "s3"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket struct {
// Name is the bucket identifier in the plugin
Name string
// Config is the bucket configuration
Config *BucketConfig
// ServerConfig is the server configuration this bucket uses
ServerConfig *ServerConfig
// Client is the AWS S3 client
Client *s3.Client
// contains filtered or unexported fields
}
Bucket represents a single S3 bucket with its client and configuration
func (*Bucket) Acquire ¶
func (b *Bucket) Acquire()
Acquire acquires a semaphore slot for the bucket
func (*Bucket) GetFullPath ¶
GetFullPath returns the full S3 key including prefix
func (*Bucket) GetVisibility ¶
GetVisibility returns the ACL for the bucket
type BucketConfig ¶
type BucketConfig struct {
// Server is the reference to a server defined in the servers section
Server string `mapstructure:"server"`
// Bucket is the actual S3 bucket name
Bucket string `mapstructure:"bucket"`
// Prefix is the path prefix for all operations (optional)
// Example: "uploads/" - all files will be stored under this prefix
Prefix string `mapstructure:"prefix"`
// Visibility defines default ACL: "public" or "private"
Visibility string `mapstructure:"visibility"`
// MaxConcurrentOperations limits concurrent operations per bucket (default: 100)
MaxConcurrentOperations int `mapstructure:"max_concurrent_operations"`
// PartSize defines multipart upload part size in bytes (default: 5MB)
PartSize int64 `mapstructure:"part_size"`
// Concurrency defines number of goroutines for multipart uploads (default: 5)
Concurrency int `mapstructure:"concurrency"`
}
BucketConfig represents a single bucket configuration
func (*BucketConfig) GetFullPath ¶
func (bc *BucketConfig) GetFullPath(pathname string) string
GetFullPath returns the full path including prefix
func (*BucketConfig) GetServerConfig ¶
func (bc *BucketConfig) GetServerConfig(servers map[string]*ServerConfig) (*ServerConfig, error)
GetServerConfig returns the server configuration for this bucket
func (*BucketConfig) GetVisibility ¶
func (bc *BucketConfig) GetVisibility() string
GetVisibility returns the ACL string for S3 operations
func (*BucketConfig) Validate ¶
func (bc *BucketConfig) Validate(servers map[string]*ServerConfig) error
Validate validates a bucket configuration
type BucketManager ¶
type BucketManager struct {
// contains filtered or unexported fields
}
BucketManager manages all S3 bucket clients
func NewBucketManager ¶
func NewBucketManager(log *zap.Logger) *BucketManager
NewBucketManager creates a new bucket manager
func (*BucketManager) CloseAll ¶
func (bm *BucketManager) CloseAll() error
CloseAll closes all bucket clients
func (*BucketManager) GetBucket ¶
func (bm *BucketManager) GetBucket(name string) (*Bucket, error)
GetBucket retrieves a bucket by name
func (*BucketManager) GetDefaultBucket ¶
func (bm *BucketManager) GetDefaultBucket() (*Bucket, error)
GetDefaultBucket retrieves the default bucket
func (*BucketManager) GetDefaultBucketName ¶
func (bm *BucketManager) GetDefaultBucketName() string
GetDefaultBucketName returns the default bucket name
func (*BucketManager) ListBuckets ¶
func (bm *BucketManager) ListBuckets() []string
ListBuckets returns all registered bucket names
func (*BucketManager) RegisterBucket ¶
func (bm *BucketManager) RegisterBucket(ctx context.Context, name string, bucketCfg *BucketConfig) error
RegisterBucket registers a new bucket with S3 client initialization
func (*BucketManager) RemoveBucket ¶
func (bm *BucketManager) RemoveBucket(name string) error
RemoveBucket removes a bucket (used for dynamic buckets)
func (*BucketManager) SetDefault ¶
func (bm *BucketManager) SetDefault(name string) error
SetDefault sets the default bucket
func (*BucketManager) SetServers ¶
func (bm *BucketManager) SetServers(servers map[string]*ServerConfig)
SetServers sets the server configurations
type CommonPrefix ¶
type CommonPrefix struct {
Prefix string `json:"prefix"`
}
CommonPrefix represents a common prefix (directory-like structure)
type Config ¶
type Config struct {
// Default bucket name to use when none specified
Default string `mapstructure:"default"`
// Servers contains S3 server definitions (credentials and endpoints)
Servers map[string]*ServerConfig `mapstructure:"servers"`
// Buckets contains bucket definitions that reference servers
Buckets map[string]*BucketConfig `mapstructure:"buckets"`
}
Config represents the plugin configuration from .rr.yaml
type Configurer ¶
type Configurer interface {
// UnmarshalKey takes a single key and unmarshal it into a Struct
UnmarshalKey(name string, out interface{}) error
// Has checks if config section exists
Has(name string) bool
}
Configurer interface for configuration loading
type CopyRequest ¶
type CopyRequest struct {
SourceBucket string `json:"source_bucket"`
SourcePathname string `json:"source_pathname"`
DestBucket string `json:"dest_bucket"`
DestPathname string `json:"dest_pathname"`
Config map[string]string `json:"config,omitempty"`
Visibility string `json:"visibility,omitempty"`
}
CopyRequest represents a file copy request
type CopyResponse ¶
type CopyResponse struct {
Success bool `json:"success"`
Pathname string `json:"pathname"`
Size int64 `json:"size"`
LastModified int64 `json:"last_modified"`
}
CopyResponse represents the response from a copy operation
type DeleteRequest ¶
DeleteRequest represents a file deletion request
type DeleteResponse ¶
type DeleteResponse struct {
Success bool `json:"success"`
}
DeleteResponse represents the response from a delete operation
type ErrorCode ¶
type ErrorCode string
ErrorCode represents structured error codes for S3 operations
const ( // ErrBucketNotFound indicates the requested bucket doesn't exist ErrBucketNotFound ErrorCode = "BUCKET_NOT_FOUND" // ErrFileNotFound indicates the requested file doesn't exist ErrFileNotFound ErrorCode = "FILE_NOT_FOUND" // ErrInvalidConfig indicates invalid configuration ErrInvalidConfig ErrorCode = "INVALID_CONFIG" // ErrS3Operation indicates an S3 operation failed ErrS3Operation ErrorCode = "S3_OPERATION_FAILED" // ErrPermissionDenied indicates insufficient permissions ErrPermissionDenied ErrorCode = "PERMISSION_DENIED" // ErrInvalidPathname indicates invalid file path ErrInvalidPathname ErrorCode = "INVALID_PATHNAME" // ErrBucketAlreadyExists indicates bucket is already registered ErrBucketAlreadyExists ErrorCode = "BUCKET_ALREADY_EXISTS" // ErrInvalidVisibility indicates invalid visibility value ErrInvalidVisibility ErrorCode = "INVALID_VISIBILITY" // ErrOperationTimeout indicates operation exceeded timeout ErrOperationTimeout ErrorCode = "OPERATION_TIMEOUT" )
type ExistsRequest ¶
ExistsRequest represents a file existence check request
type ExistsResponse ¶
type ExistsResponse struct {
Exists bool `json:"exists"`
}
ExistsResponse represents the response from an exists check
type GetMetadataRequest ¶
GetMetadataRequest represents a request to get file metadata
type GetMetadataResponse ¶
type GetMetadataResponse struct {
Size int64 `json:"size"`
MimeType string `json:"mime_type"`
LastModified int64 `json:"last_modified"`
Visibility string `json:"visibility"`
ETag string `json:"etag,omitempty"`
}
GetMetadataResponse represents file metadata
type GetPublicURLRequest ¶
type GetPublicURLRequest struct {
Bucket string `json:"bucket"`
Pathname string `json:"pathname"`
ExpiresIn int64 `json:"expires_in,omitempty"` // Seconds, 0 for permanent
}
GetPublicURLRequest represents a request to generate a public URL
type GetPublicURLResponse ¶
type GetPublicURLResponse struct {
URL string `json:"url"`
ExpiresAt int64 `json:"expires_at,omitempty"` // Unix timestamp
}
GetPublicURLResponse represents the response with a public URL
type ListBucketsRequest ¶
type ListBucketsRequest struct{}
ListBucketsRequest represents the request to list all buckets
type ListBucketsResponse ¶
type ListBucketsResponse struct {
Buckets []string `json:"buckets"`
Default string `json:"default"`
}
ListBucketsResponse represents the response with all bucket names
type ListObjectsRequest ¶
type ListObjectsRequest struct {
Bucket string `json:"bucket"`
Prefix string `json:"prefix,omitempty"` // Filter by prefix
Delimiter string `json:"delimiter,omitempty"` // Delimiter for grouping (e.g., "/")
MaxKeys int32 `json:"max_keys,omitempty"` // Maximum number of keys to return (default: 1000)
ContinuationToken string `json:"continuation_token,omitempty"` // Token for pagination
}
ListObjectsRequest represents a request to list objects in a bucket
type ListObjectsResponse ¶
type ListObjectsResponse struct {
Objects []ObjectInfo `json:"objects"`
CommonPrefixes []CommonPrefix `json:"common_prefixes,omitempty"`
IsTruncated bool `json:"is_truncated"`
NextContinuationToken string `json:"next_continuation_token,omitempty"`
KeyCount int32 `json:"key_count"`
}
ListObjectsResponse represents the response from list objects operation
type MoveRequest ¶
type MoveRequest struct {
SourceBucket string `json:"source_bucket"`
SourcePathname string `json:"source_pathname"`
DestBucket string `json:"dest_bucket"`
DestPathname string `json:"dest_pathname"`
Config map[string]string `json:"config,omitempty"`
Visibility string `json:"visibility,omitempty"`
}
MoveRequest represents a file move request (copy + delete)
type MoveResponse ¶
type MoveResponse struct {
Success bool `json:"success"`
Pathname string `json:"pathname"`
Size int64 `json:"size"`
LastModified int64 `json:"last_modified"`
}
MoveResponse represents the response from a move operation
type ObjectInfo ¶
type ObjectInfo struct {
Key string `json:"key"`
Size int64 `json:"size"`
LastModified int64 `json:"last_modified"` // Unix timestamp
ETag string `json:"etag"`
StorageClass string `json:"storage_class,omitempty"`
}
ObjectInfo represents information about a single S3 object
type Operations ¶
type Operations struct {
// contains filtered or unexported fields
}
Operations handles all S3 file operations
func NewOperations ¶
func NewOperations(plugin *Plugin, log *zap.Logger) *Operations
NewOperations creates a new Operations instance
func (*Operations) Copy ¶
func (o *Operations) Copy(ctx context.Context, req *CopyRequest, resp *CopyResponse) error
Copy copies a file within or between buckets
func (*Operations) Delete ¶
func (o *Operations) Delete(ctx context.Context, req *DeleteRequest, resp *DeleteResponse) error
Delete deletes a file from S3
func (*Operations) Exists ¶
func (o *Operations) Exists(ctx context.Context, req *ExistsRequest, resp *ExistsResponse) error
Exists checks if a file exists in S3
func (*Operations) GetMetadata ¶
func (o *Operations) GetMetadata(ctx context.Context, req *GetMetadataRequest, resp *GetMetadataResponse) error
GetMetadata retrieves file metadata
func (*Operations) GetPublicURL ¶
func (o *Operations) GetPublicURL(ctx context.Context, req *GetPublicURLRequest, resp *GetPublicURLResponse) error
GetPublicURL generates a public or presigned URL for a file
func (*Operations) ListObjects ¶
func (o *Operations) ListObjects(ctx context.Context, req *ListObjectsRequest, resp *ListObjectsResponse) error
ListObjects lists objects in a bucket with optional filtering and pagination
func (*Operations) Move ¶
func (o *Operations) Move(ctx context.Context, req *MoveRequest, resp *MoveResponse) error
Move moves a file within or between buckets (copy + delete)
func (*Operations) Read ¶
func (o *Operations) Read(ctx context.Context, req *ReadRequest, resp *ReadResponse) error
Read downloads a file from S3
func (*Operations) SetVisibility ¶
func (o *Operations) SetVisibility(ctx context.Context, req *SetVisibilityRequest, resp *SetVisibilityResponse) error
SetVisibility changes file visibility (ACL)
func (*Operations) Write ¶
func (o *Operations) Write(ctx context.Context, req *WriteRequest, resp *WriteResponse) error
Write uploads a file to S3
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin represents the main S3 storage plugin structure
func (*Plugin) CompleteOperation ¶
func (p *Plugin) CompleteOperation()
CompleteOperation marks an operation as complete
func (*Plugin) GetBucketManager ¶
func (p *Plugin) GetBucketManager() *BucketManager
GetBucketManager returns the bucket manager (for internal use)
func (*Plugin) GetContext ¶
GetContext returns the plugin context
func (*Plugin) Init ¶
func (p *Plugin) Init(cfg Configurer, log Logger) error
Init initializes the plugin with dependencies
func (*Plugin) MetricsCollector ¶
func (p *Plugin) MetricsCollector() []prometheus.Collector
MetricsCollector implements the StatProvider interface for Prometheus metrics integration This method is called by the metrics plugin during its Serve phase to register all collectors Metrics are also registered directly in Init() to ensure availability even if this method isn't called
func (*Plugin) RPC ¶
func (p *Plugin) RPC() interface{}
RPC returns the RPC interface exposed to PHP
func (*Plugin) TrackOperation ¶
func (p *Plugin) TrackOperation()
TrackOperation adds an operation to the wait group
type ReadRequest ¶
ReadRequest represents a file read/download request
type ReadResponse ¶
type ReadResponse struct {
Content []byte `json:"content"`
Size int64 `json:"size"`
MimeType string `json:"mime_type"`
LastModified int64 `json:"last_modified"`
}
ReadResponse represents the response from a read operation
type RegisterBucketRequest ¶
type RegisterBucketRequest struct {
Name string `json:"name"`
Server string `json:"server"`
Bucket string `json:"bucket"`
Prefix string `json:"prefix"`
Visibility string `json:"visibility"`
}
RegisterBucketRequest represents the request to register a new bucket dynamically
type RegisterBucketResponse ¶
type RegisterBucketResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
}
RegisterBucketResponse represents the response from bucket registration
type S3Error ¶
type S3Error struct {
// Code is the error code
Code ErrorCode `json:"code"`
// Message is the human-readable error message
Message string `json:"message"`
// Details contains additional error context (optional)
Details string `json:"details,omitempty"`
}
S3Error represents a structured error returned to PHP
func NewBucketNotFoundError ¶
NewBucketNotFoundError creates a bucket not found error
func NewFileNotFoundError ¶
NewFileNotFoundError creates a file not found error
func NewInvalidConfigError ¶
NewInvalidConfigError creates an invalid config error
func NewInvalidPathnameError ¶
NewInvalidPathnameError creates an invalid pathname error
func NewPermissionDeniedError ¶
NewPermissionDeniedError creates a permission denied error
func NewS3Error ¶
NewS3Error creates a new S3Error
func NewS3OperationError ¶
NewS3OperationError creates an S3 operation error
type ServerConfig ¶
type ServerConfig struct {
// Region is the AWS region (e.g., "us-east-1", "fra1" for DigitalOcean)
Region string `mapstructure:"region"`
// Endpoint is the S3 endpoint URL (required for S3-compatible services)
// Example: "https://fra1.digitaloceanspaces.com"
// Leave empty for AWS S3 (will use default AWS endpoint)
Endpoint string `mapstructure:"endpoint"`
// Credentials contains authentication credentials for this server
Credentials ServerCredentials `mapstructure:"credentials"`
}
ServerConfig represents S3 server configuration (credentials and endpoint)
func (*ServerConfig) Validate ¶
func (sc *ServerConfig) Validate() error
Validate validates a server configuration
type ServerCredentials ¶
type ServerCredentials struct {
// Key is the Access Key ID
Key string `mapstructure:"key"`
// Secret is the Secret Access Key
Secret string `mapstructure:"secret"`
// Token is the Session Token (optional, for temporary credentials)
Token string `mapstructure:"token"`
}
ServerCredentials contains S3 authentication credentials
type SetVisibilityRequest ¶
type SetVisibilityRequest struct {
Bucket string `json:"bucket"`
Pathname string `json:"pathname"`
Visibility string `json:"visibility"`
}
SetVisibilityRequest represents a request to change file visibility
type SetVisibilityResponse ¶
type SetVisibilityResponse struct {
Success bool `json:"success"`
}
SetVisibilityResponse represents the response from visibility change