2025-03-21 18:38:43 +08:00
|
|
|
package contracts
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
|
|
// EncryptionManager is an envelope encryption service in charge of encrypting/decrypting secrets.
|
|
|
|
type EncryptionManager interface {
|
|
|
|
// Encrypt MUST NOT be used within database transactions, it may cause database locks.
|
|
|
|
// For those specific use cases where the encryption operation cannot be moved outside
|
|
|
|
// the database transaction, look at database-specific methods present at the specific
|
|
|
|
// implementation present at manager.EncryptionService.
|
2025-05-28 19:46:54 +08:00
|
|
|
Encrypt(ctx context.Context, namespace string, payload []byte) ([]byte, error)
|
2025-03-21 18:38:43 +08:00
|
|
|
Decrypt(ctx context.Context, namespace string, payload []byte) ([]byte, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type EncryptedValue struct {
|
|
|
|
Namespace string
|
2025-07-14 20:28:07 +08:00
|
|
|
Name string
|
|
|
|
Version int64
|
2025-03-21 18:38:43 +08:00
|
|
|
EncryptedData []byte
|
|
|
|
Created int64
|
|
|
|
Updated int64
|
|
|
|
}
|
|
|
|
|
2025-07-28 17:50:24 +08:00
|
|
|
// ListOpts defines pagination options for listing encrypted values.
|
|
|
|
type ListOpts struct {
|
|
|
|
Limit int64
|
|
|
|
Offset int64
|
|
|
|
}
|
|
|
|
|
2025-03-21 18:38:43 +08:00
|
|
|
type EncryptedValueStorage interface {
|
2025-07-14 20:28:07 +08:00
|
|
|
Create(ctx context.Context, namespace, name string, version int64, encryptedData []byte) (*EncryptedValue, error)
|
|
|
|
Update(ctx context.Context, namespace, name string, version int64, encryptedData []byte) error
|
|
|
|
Get(ctx context.Context, namespace, name string, version int64) (*EncryptedValue, error)
|
|
|
|
Delete(ctx context.Context, namespace, name string, version int64) error
|
2025-03-21 18:38:43 +08:00
|
|
|
}
|
2025-07-28 17:50:24 +08:00
|
|
|
|
|
|
|
type GlobalEncryptedValueStorage interface {
|
|
|
|
ListAll(ctx context.Context, opts ListOpts, untilTime *int64) ([]*EncryptedValue, error)
|
|
|
|
CountAll(ctx context.Context, untilTime *int64) (int64, error)
|
|
|
|
}
|
2025-07-31 21:45:59 +08:00
|
|
|
|
|
|
|
type ConsolidationService interface {
|
|
|
|
Consolidate(ctx context.Context) error
|
|
|
|
}
|