Documentation ¶
Index ¶
- Variables
- func DeserializeJSON[D any](data []byte, obj *D) error
- func SerializeJSON[D any](obj *D) ([]byte, error)
- type DefaultTypedSecretStorage
- func (s *DefaultTypedSecretStorage[ID, D]) Delete(ctx context.Context, id *ID) error
- func (s *DefaultTypedSecretStorage[ID, D]) Examine(ctx context.Context) error
- func (s *DefaultTypedSecretStorage[ID, D]) Get(ctx context.Context, id *ID) (*D, error)
- func (s *DefaultTypedSecretStorage[ID, D]) Initialize(ctx context.Context) error
- func (s *DefaultTypedSecretStorage[ID, D]) Store(ctx context.Context, id *ID, data *D) error
- type SecretID
- type SecretStorage
- type TestSecretStorage
- func (t TestSecretStorage) Delete(ctx context.Context, key SecretID) error
- func (t TestSecretStorage) Examine(ctx context.Context) error
- func (t TestSecretStorage) Get(ctx context.Context, key SecretID) ([]byte, error)
- func (t TestSecretStorage) Initialize(ctx context.Context) error
- func (t TestSecretStorage) Store(ctx context.Context, key SecretID, data []byte) error
- type TypedSecretStorage
Constants ¶
This section is empty.
Variables ¶
var NotFoundError = errors.New("not found")
Functions ¶
func DeserializeJSON ¶
DeserializeJSON is a thin wrapper around Unmarshal function of encoding/json.
func SerializeJSON ¶
SerializeJSON is a thin wrapper around Marshal function of encoding/json.
Types ¶
type DefaultTypedSecretStorage ¶
type DefaultTypedSecretStorage[ID any, D any] struct { // DataTypeName is the human-readable name of the data type that is being stored. This is used // in error messages. DataTypeName string // SecretStorage is the underlying secret storage used for the actual operations against the persistent // storage. This must be initialized explicitly before it is used in this token storage instance. SecretStorage SecretStorage // ToID is a function that converts the strongly typed ID to the generic SecretID used by the SecretStorage. ToID func(*ID) (*SecretID, error) // Serialize is a function to convert the strongly typed data into a byte array. You can use // for example the SerializeJSON function. Serialize func(*D) ([]byte, error) // Deserialize is a function to convert the byte array back to the strongly typed data. You can use // for example the DeserializeJSON function. Deserialize func([]byte, *D) error }
DefaultTypedSecretStorage is the default implementation of the TypedSecretStorage interface that uses the provided functions to convert between the id and data types to SecretID and []byte respectively.
func (*DefaultTypedSecretStorage[ID, D]) Delete ¶
func (s *DefaultTypedSecretStorage[ID, D]) Delete(ctx context.Context, id *ID) error
Delete implements TypedSecretStorage
func (*DefaultTypedSecretStorage[ID, D]) Examine ¶
func (s *DefaultTypedSecretStorage[ID, D]) Examine(ctx context.Context) error
func (*DefaultTypedSecretStorage[ID, D]) Get ¶
func (s *DefaultTypedSecretStorage[ID, D]) Get(ctx context.Context, id *ID) (*D, error)
Get implements TypedSecretStorage
func (*DefaultTypedSecretStorage[ID, D]) Initialize ¶
func (s *DefaultTypedSecretStorage[ID, D]) Initialize(ctx context.Context) error
Initialize implements TypedSecretStorage. It is a noop.
type SecretID ¶
SecretID is a generic identifier of the secret that we store data of. While it very much resembles the Kubernetes client's ObjectKey, we keep it as a separate struct to be more explicit and forward-compatible should any changes to this struct arise in the future.
func ObjectToID ¶
ObjectToID converts given Kubernetes object to SecretID based on the name and namespace.
type SecretStorage ¶
type SecretStorage interface { // Initialize initializes the connection to the underlying data store, etc. Initialize(ctx context.Context) error // Examine verifies that the underlying data store is in a good state and can be used. Examine(ctx context.Context) error // Store stores the provided data under given id Store(ctx context.Context, id SecretID, data []byte) error // Get retrieves the data under the given id. A NotFoundError is returned if the data is not found. Get(ctx context.Context, id SecretID) ([]byte, error) // Delete deletes the data of given id. A NotFoundError is returned if there is no such data. Delete(ctx context.Context, id SecretID) error }
SecretStorage is a generic storage mechanism for storing secret data keyed by the SecretID.
type TestSecretStorage ¶
type TestSecretStorage struct { InitializeImpl func(context.Context) error StoreImpl func(ctx context.Context, key SecretID, data []byte) error GetImpl func(ctx context.Context, key SecretID) ([]byte, error) DeleteImpl func(ctx context.Context, key SecretID) error }
func (TestSecretStorage) Delete ¶
func (t TestSecretStorage) Delete(ctx context.Context, key SecretID) error
func (TestSecretStorage) Initialize ¶
func (t TestSecretStorage) Initialize(ctx context.Context) error
type TypedSecretStorage ¶
type TypedSecretStorage[ID any, D any] interface { // Initialize initializes the connection to the underlying data store, etc. Initialize(ctx context.Context) error // Examine verifies that the underlying data store is in a good state and can be used. Examine(ctx context.Context) error // Store stores the provided data under given id Store(ctx context.Context, id *ID, data *D) error // Get retrieves the data under the given id. A NotFoundError is returned if the data is not found. Get(ctx context.Context, id *ID) (*D, error) // Delete deletes the data of given id. A NotFoundError is returned if there is no such data. Delete(ctx context.Context, id *ID) error }
TypedSecretStorage is a generic "companion" to the "raw" SecretStorage interface which uses strongly typed arguments instead of the generic SecretID and []byte.