Documentation ¶
Index ¶
- func TranslateToError(code int, message string) error
- type CryptStore
- func (m CryptStore) Create(ctx context.Context, key string) error
- func (m CryptStore) Delete(ctx context.Context, key string) error
- func (m CryptStore) List(ctx context.Context) ([]string, error)
- func (m CryptStore) Put(ctx context.Context, key string, entry []byte) error
- func (m CryptStore) Read(ctx context.Context, key string) ([]byte, error)
- func (m CryptStore) ReadAll(ctx context.Context, key string) ([][]byte, error)
- type DecryptionError
- type EntryError
- type Error
- type ErrorCode
- type InMemoryOps
- func (ops *InMemoryOps) Create(ctx context.Context, key string) error
- func (ops *InMemoryOps) Delete(ctx context.Context, key string) error
- func (ops *InMemoryOps) List(ctx context.Context) ([]string, error)
- func (ops *InMemoryOps) Put(ctx context.Context, key string, entry []byte) error
- func (ops *InMemoryOps) Read(ctx context.Context, key string) ([]byte, error)
- func (ops *InMemoryOps) ReadAll(ctx context.Context, key string) ([][]byte, error)
- type KeyError
- type KeyNotFoundError
- type LocationError
- type Ops
- type OpsInternalError
- type S3Ops
- func (s *S3Ops) Create(ctx context.Context, key string) error
- func (s *S3Ops) Delete(ctx context.Context, key string) error
- func (s *S3Ops) List(ctx context.Context) ([]string, error)
- func (s *S3Ops) Put(ctx context.Context, key string, entry []byte) error
- func (s *S3Ops) Read(ctx context.Context, key string) ([]byte, error)
- func (s *S3Ops) ReadAll(ctx context.Context, key string) ([][]byte, error)
- type TimestampError
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TranslateToError ¶
Types ¶
type CryptStore ¶
type CryptStore struct {
// contains filtered or unexported fields
}
func (CryptStore) Create ¶
func (m CryptStore) Create(ctx context.Context, key string) error
Create implements libstore.Ops.
func (CryptStore) Delete ¶
func (m CryptStore) Delete(ctx context.Context, key string) error
Delete implements libstore.Ops.
func (CryptStore) List ¶
func (m CryptStore) List(ctx context.Context) ([]string, error)
List implements libstore.Ops.
type DecryptionError ¶
type DecryptionError string
func (DecryptionError) Error ¶
func (e DecryptionError) Error() string
type EntryError ¶
type EntryError string
func (EntryError) Error ¶
func (e EntryError) Error() string
type InMemoryOps ¶
type InMemoryOps struct {
// contains filtered or unexported fields
}
InMemoryOps is an in-memory implementation of the Ops interface.
func NewInMemoryOps ¶
func NewInMemoryOps() *InMemoryOps
NewInMemoryOps creates a new InMemoryOps instance.
func (*InMemoryOps) Create ¶
func (ops *InMemoryOps) Create(ctx context.Context, key string) error
Create creates a new key in the store.
func (*InMemoryOps) Delete ¶
func (ops *InMemoryOps) Delete(ctx context.Context, key string) error
Delete deletes the key and all its associated entries.
func (*InMemoryOps) List ¶
func (ops *InMemoryOps) List(ctx context.Context) ([]string, error)
List lists all keys in the store.
type KeyNotFoundError ¶
type KeyNotFoundError string
func (KeyNotFoundError) Error ¶
func (e KeyNotFoundError) Error() string
type LocationError ¶
type LocationError string
func (LocationError) Error ¶
func (e LocationError) Error() string
type Ops ¶
type Ops interface { // Create creates a new key. // It returns an error if the key already exists or if there is an issue creating the key. Create(ctx context.Context, key string) error // ReadAll reads the entire content of the given key. // It returns the content as a byte slice or an error if the content cannot be read. ReadAll(ctx context.Context, key string) ([][]byte, error) // Read reads the last entry of the given key. // It returns the last entry or an error if the file cannot be read. Read(ctx context.Context, key string) ([]byte, error) // Put replaces an entry to the file with the given key. // It returns an error if the file cannot be opened or written to. Put(ctx context.Context, key string, entry []byte) error // Delete deletes the given key and associated content. // It returns an error if the key or associated content cannot be deleted. Delete(ctx context.Context, key string) error // List lists all keys in the bucket-scope. // It returns a slice of key names or an error if the bucket-scope cannot be read. List(ctx context.Context) ([]string, error) }
Ops defines the interface for data operations.
func NewCryptStoreCBC ¶
func NewCryptStoreCBC(ops Ops, encyptionKey []byte, integrityKey []byte, calculateMAC func() hash.Hash, rand io.Reader) (Ops, error)
NewCryptStoreCBC initializes a new CryptStore instance using CBC-HMAC encryption.
Parameters:
- ops: An instance of Ops that defines the underlying storage operations.
- encryptionKey: A byte slice representing the encryption key used for the CBC encryption.
- integrityKey: A byte slice representing the key used for HMAC integrity checks.
- calculateMAC: A function returning a new hash.Hash used for generating the MAC.
- rand: An io.Reader used as a source of randomness, typically crypto/rand.Reader.
Returns:
- An Ops instance that wraps the provided storage operations with CBC-HMAC encryption.
- An error if the encryption or decryption setup fails.
The function sets up an encryptor and decryptor using the specified keys and MAC function. It then returns a CryptStore that applies these operations on the provided Ops.
func NewCryptStoreGCM ¶
NewCryptStoreGCM initializes a new CryptStore instance using GCM encryption.
Parameters:
- ops: An instance of Ops that defines the underlying storage operations.
- encryptionKey: A byte slice representing the encryption key used for GCM encryption.
- rand: An io.Reader used as a source of randomness, typically crypto/rand.Reader.
Returns:
- An Ops instance that wraps the provided storage operations with GCM encryption.
- An error if the encryption or decryption setup fails.
The function sets up an encryptor and decryptor using the specified encryption key. It then returns a CryptStore that applies these operations on the provided Ops.
func NewDBOps ¶
NewDBOps initializes a new dbOps instance with a connection to a PostgreSQL database.
Parameters:
- ctx: Context for managing request lifecycles.
- conn: Connection string for connecting to the PostgreSQL database.
Returns:
- An initialized dbOps instance that implements the Ops interface.
- An error if the database connection fails or if the table cannot be created.
The function opens a connection to the PostgreSQL database using the provided connection string, and ensures that the necessary table ('FILES') exists by creating it if it does not.
Note: The function returns an OpsInternalError if any step of the initialization fails.
func NewFileOps ¶
NewFileOps initializes a new Ops instance with an OS filesystem-based implementation. It returns an error if the provided location is invalid.
type OpsInternalError ¶
type OpsInternalError string
func (OpsInternalError) Error ¶
func (e OpsInternalError) Error() string
type S3Ops ¶
type S3Ops struct {
// contains filtered or unexported fields
}
S3Ops provides operations for AWS S3 bucket interactions.
func NewS3Ops ¶
NewS3Ops initializes an S3Ops instance with AWS S3 client authorization.
Parameters:
- ctx: Context for managing request lifecycles.
- bucket: The name of the AWS S3 bucket to interact with.
Returns:
- A pointer to an initialized S3Ops instance.
- An error if the AWS configuration cannot be loaded or if the specified bucket cannot be accessed.
Environment Variables:
- AWS_ACCESS_KEY_ID: AWS access key ID.
- AWS_SECRET_ACCESS_KEY: AWS secret access key.
- AWS_REGION: AWS region.
Note: These environment variables are required for the AWS SDK to authenticate and perform operations on the S3 bucket.
type TimestampError ¶
type TimestampError string
func (TimestampError) Error ¶
func (e TimestampError) Error() string
type ValidationError ¶
type ValidationError string
func (ValidationError) Error ¶
func (e ValidationError) Error() string