repo

package
v0.0.0-...-6aec01b Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package repo provides facade to data stored in external sources.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoValuesToUpdate = errors.New("no values to update")

Functions

This section is empty.

Types

type Repositories

type Repositories struct {
	Secrets Secrets
	Users   Users
}

Repositories is a collection of data repositories.

func New

func New(pg *postgres.Postgres) *Repositories

New creates and initializes collection of data repositories.

type Secrets

type Secrets interface {
	Create(
		ctx context.Context,
		owner uuid.UUID,
		name string,
		kind goph.DataKind,
		metadata, data []byte,
	) (uuid.UUID, error)

	List(ctx context.Context, owner uuid.UUID) ([]entity.Secret, error)
	Get(ctx context.Context, owner, id uuid.UUID) (*entity.Secret, error)

	Update(
		ctx context.Context,
		owner, id uuid.UUID,
		changed []string,
		name string,
		metadata []byte,
		data []byte,
	) error

	Delete(ctx context.Context, owner, id uuid.UUID) error
}

type SecretsRepo

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

SecretsRepo is facade to secrets stored in Postgres.

func NewSecretsRepo

func NewSecretsRepo(pg *postgres.Postgres) *SecretsRepo

NewSecretsRepo creates and initializes SecretsRepo object.

func (*SecretsRepo) Create

func (r *SecretsRepo) Create(
	ctx context.Context,
	owner uuid.UUID,
	name string,
	kind goph.DataKind,
	metadata, data []byte,
) (id uuid.UUID, err error)

Create stores new secret in database.

func (*SecretsRepo) Delete

func (r *SecretsRepo) Delete(
	ctx context.Context,
	owner, id uuid.UUID,
) (err error)

Delete removes secret from database.

func (*SecretsRepo) Get

func (r *SecretsRepo) Get(
	ctx context.Context,
	owner, id uuid.UUID,
) (*entity.Secret, error)

Get returns full secret info and data.

func (*SecretsRepo) List

func (r *SecretsRepo) List(
	ctx context.Context,
	owner uuid.UUID,
) ([]entity.Secret, error)

List returns all secrets of the provided user. Data is not filled in this case to reduce load on service.

func (*SecretsRepo) Update

func (r *SecretsRepo) Update(
	ctx context.Context,
	owner, id uuid.UUID,
	changed []string,
	name string,
	metadata, data []byte,
) error

Update changes secret info and data.

type SecretsRepoMock

type SecretsRepoMock struct {
	mock.Mock
}

func (*SecretsRepoMock) Create

func (m *SecretsRepoMock) Create(
	ctx context.Context,
	owner uuid.UUID,
	name string,
	kind goph.DataKind,
	metadata, data []byte,
) (uuid.UUID, error)

func (*SecretsRepoMock) Delete

func (m *SecretsRepoMock) Delete(
	ctx context.Context,
	owner, id uuid.UUID,
) error

func (*SecretsRepoMock) Get

func (m *SecretsRepoMock) Get(
	ctx context.Context,
	owner, id uuid.UUID,
) (*entity.Secret, error)

func (*SecretsRepoMock) List

func (m *SecretsRepoMock) List(
	ctx context.Context,
	owner uuid.UUID,
) ([]entity.Secret, error)

func (*SecretsRepoMock) Update

func (m *SecretsRepoMock) Update(
	ctx context.Context,
	owner, id uuid.UUID,
	changed []string,
	name string,
	metadata []byte,
	data []byte,
) error

type Users

type Users interface {
	Register(ctx context.Context, username, securityKey string) (uuid.UUID, error)
	Verify(ctx context.Context, username, securityKey string) (entity.User, error)
}

type UsersRepo

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

UsersRepo is facade to users stored in Postgres.

func NewUsersRepo

func NewUsersRepo(
	pg *postgres.Postgres,
) *UsersRepo

NewUsersRepo creates and initializes UsersRepo object.

func (*UsersRepo) Register

func (r *UsersRepo) Register(
	ctx context.Context,
	username, securityKey string,
) (uuid.UUID, error)

Register creates a new user.

func (*UsersRepo) Verify

func (r *UsersRepo) Verify(
	ctx context.Context,
	username, securityKey string,
) (entity.User, error)

Verify checks provided username and security key against data stored in database. Returns entity.User, if verification was successful.

type UsersRepoMock

type UsersRepoMock struct {
	mock.Mock
}

func (*UsersRepoMock) Register

func (m *UsersRepoMock) Register(
	ctx context.Context,
	username, securityKey string,
) (uuid.UUID, error)

func (*UsersRepoMock) Verify

func (m *UsersRepoMock) Verify(
	ctx context.Context,
	username, securityKey string,
) (entity.User, error)

Jump to

Keyboard shortcuts

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