engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RepositoriesByUserAccess = "access.owner_id"
	AnonymousUserID          = int64(-1000) // uses for share access for anonymous and not registered users
	RegisteredUserID         = int64(-999)  // uses for share access for registered users only
)

RepositoriesByUserAccess allow filtered repositories result list by assigned user access it's relevant only for role 'user' only

Variables

View Source
var ErrNotFound = errors.New("record not found")

ErrNotFound return empty result error with request

Functions

func GetAdminDefaultPassword

func GetAdminDefaultPassword(ctx context.Context) string

GetAdminDefaultPassword allows get default password for user admin from context

func SetAdminDefaultPassword

func SetAdminDefaultPassword(ctx context.Context, passwd *string) context.Context

SetAdminDefaultPassword allows defining default password for user admin when database with users created first

Types

type Interface

type Interface interface {

	// CreateUser create a new user login record in application storage
	CreateUser(ctx context.Context, user *store.User) (err error)

	// GetUser get data by user ID, where id can be any type
	GetUser(ctx context.Context, id interface{}) (user store.User, err error)

	// FindUsers fetch list of user by filter values.
	// @withPassword defines include or not hash value of password to result
	FindUsers(ctx context.Context, filter QueryFilter, withPassword bool) (users ListResponse, err error)

	// UpdateUser update user records data in application storage
	UpdateUser(ctx context.Context, user store.User) (err error)

	// DeleteUser delete user record by ID
	DeleteUser(ctx context.Context, id int64) (err error)

	// CreateGroup create a new users group record in application storage
	CreateGroup(ctx context.Context, group *store.Group) (err error)

	// GetGroup get data of users group by ID
	GetGroup(ctx context.Context, id int64) (group store.Group, err error)

	// FindGroups fetch list of existed users group
	FindGroups(ctx context.Context, filter QueryFilter) (groups ListResponse, err error)

	// UpdateGroup update data of users group
	UpdateGroup(ctx context.Context, group store.Group) (err error)

	// DeleteGroup delete users group record by ID
	DeleteGroup(ctx context.Context, id int64) (err error)

	// CreateAccess create a new access record for a specific user and repository
	CreateAccess(ctx context.Context, access *store.Access) (err error)

	// GetAccess get data of access entry by ID
	GetAccess(ctx context.Context, id int64) (access store.Access, err error)

	// FindAccesses get list of users access
	FindAccesses(ctx context.Context, filter QueryFilter) (accesses ListResponse, err error)

	// UpdateAccess will update a user access record
	UpdateAccess(ctx context.Context, access store.Access) (err error)

	// DeleteAccess delete access record by ID
	DeleteAccess(ctx context.Context, key string, id interface{}) (err error)

	// AccessGarbageCollector check outdated repositories in repositories table and delete ones from access list
	AccessGarbageCollector(ctx context.Context) error

	// CreateRepository create a new repository record
	CreateRepository(ctx context.Context, entry *store.RegistryEntry) (err error)

	// GetRepository get repository data by ID
	GetRepository(ctx context.Context, entryID int64) (entry store.RegistryEntry, err error)

	// FindRepositories get list of repositories
	FindRepositories(ctx context.Context, filter QueryFilter) (entries ListResponse, err error)

	// UpdateRepository update repository entry data
	UpdateRepository(ctx context.Context, conditionClause, data map[string]interface{}) (err error)

	// DeleteRepository delete repository entry by ID
	DeleteRepository(ctx context.Context, repositoryName, digest string) (err error)

	// RepositoryGarbageCollector deletes outdated repositories entries
	RepositoryGarbageCollector(ctx context.Context, syncDate int64) (err error)

	// Close connection to storage instance
	Close(ctx context.Context) error
}

Interface defines methods provided by low-level storage engine

type InterfaceMock

type InterfaceMock struct {
	// AccessGarbageCollectorFunc mocks the AccessGarbageCollector method.
	AccessGarbageCollectorFunc func(ctx context.Context) error

	// CloseFunc mocks the Close method.
	CloseFunc func(ctx context.Context) error

	// CreateAccessFunc mocks the CreateAccess method.
	CreateAccessFunc func(ctx context.Context, access *store.Access) error

	// CreateGroupFunc mocks the CreateGroup method.
	CreateGroupFunc func(ctx context.Context, group *store.Group) error

	// CreateRepositoryFunc mocks the CreateRepository method.
	CreateRepositoryFunc func(ctx context.Context, entry *store.RegistryEntry) error

	// CreateUserFunc mocks the CreateUser method.
	CreateUserFunc func(ctx context.Context, user *store.User) error

	// DeleteAccessFunc mocks the DeleteAccess method.
	DeleteAccessFunc func(ctx context.Context, key string, id interface{}) error

	// DeleteGroupFunc mocks the DeleteGroup method.
	DeleteGroupFunc func(ctx context.Context, id int64) error

	// DeleteRepositoryFunc mocks the DeleteRepository method.
	DeleteRepositoryFunc func(ctx context.Context, repositoryName string, digest string) error

	// DeleteUserFunc mocks the DeleteUser method.
	DeleteUserFunc func(ctx context.Context, id int64) error

	// FindAccessesFunc mocks the FindAccesses method.
	FindAccessesFunc func(ctx context.Context, filter QueryFilter) (ListResponse, error)

	// FindGroupsFunc mocks the FindGroups method.
	FindGroupsFunc func(ctx context.Context, filter QueryFilter) (ListResponse, error)

	// FindRepositoriesFunc mocks the FindRepositories method.
	FindRepositoriesFunc func(ctx context.Context, filter QueryFilter) (ListResponse, error)

	// FindUsersFunc mocks the FindUsers method.
	FindUsersFunc func(ctx context.Context, filter QueryFilter, withPassword bool) (ListResponse, error)

	// GetAccessFunc mocks the GetAccess method.
	GetAccessFunc func(ctx context.Context, id int64) (store.Access, error)

	// GetGroupFunc mocks the GetGroup method.
	GetGroupFunc func(ctx context.Context, id int64) (store.Group, error)

	// GetRepositoryFunc mocks the GetRepository method.
	GetRepositoryFunc func(ctx context.Context, entryID int64) (store.RegistryEntry, error)

	// GetUserFunc mocks the GetUser method.
	GetUserFunc func(ctx context.Context, id interface{}) (store.User, error)

	// RepositoryGarbageCollectorFunc mocks the RepositoryGarbageCollector method.
	RepositoryGarbageCollectorFunc func(ctx context.Context, syncDate int64) error

	// UpdateAccessFunc mocks the UpdateAccess method.
	UpdateAccessFunc func(ctx context.Context, access store.Access) error

	// UpdateGroupFunc mocks the UpdateGroup method.
	UpdateGroupFunc func(ctx context.Context, group store.Group) error

	// UpdateRepositoryFunc mocks the UpdateRepository method.
	UpdateRepositoryFunc func(ctx context.Context, conditionClause map[string]interface{}, data map[string]interface{}) error

	// UpdateUserFunc mocks the UpdateUser method.
	UpdateUserFunc func(ctx context.Context, user store.User) error
	// contains filtered or unexported fields
}

InterfaceMock is a mock implementation of Interface.

func TestSomethingThatUsesInterface(t *testing.T) {

	// make and configure a mocked Interface
	mockedInterface := &InterfaceMock{
		AccessGarbageCollectorFunc: func(ctx context.Context) error {
			panic("mock out the AccessGarbageCollector method")
		},
		CloseFunc: func(ctx context.Context) error {
			panic("mock out the Close method")
		},
		CreateAccessFunc: func(ctx context.Context, access *store.Access) error {
			panic("mock out the CreateAccess method")
		},
		CreateGroupFunc: func(ctx context.Context, group *store.Group) error {
			panic("mock out the CreateGroup method")
		},
		CreateRepositoryFunc: func(ctx context.Context, entry *store.RegistryEntry) error {
			panic("mock out the CreateRepository method")
		},
		CreateUserFunc: func(ctx context.Context, user *store.User) error {
			panic("mock out the CreateUser method")
		},
		DeleteAccessFunc: func(ctx context.Context, key string, id interface{}) error {
			panic("mock out the DeleteAccess method")
		},
		DeleteGroupFunc: func(ctx context.Context, id int64) error {
			panic("mock out the DeleteGroup method")
		},
		DeleteRepositoryFunc: func(ctx context.Context, repositoryName string, digest string) error {
			panic("mock out the DeleteRepository method")
		},
		DeleteUserFunc: func(ctx context.Context, id int64) error {
			panic("mock out the DeleteUser method")
		},
		FindAccessesFunc: func(ctx context.Context, filter QueryFilter) (ListResponse, error) {
			panic("mock out the FindAccesses method")
		},
		FindGroupsFunc: func(ctx context.Context, filter QueryFilter) (ListResponse, error) {
			panic("mock out the FindGroups method")
		},
		FindRepositoriesFunc: func(ctx context.Context, filter QueryFilter) (ListResponse, error) {
			panic("mock out the FindRepositories method")
		},
		FindUsersFunc: func(ctx context.Context, filter QueryFilter, withPassword bool) (ListResponse, error) {
			panic("mock out the FindUsers method")
		},
		GetAccessFunc: func(ctx context.Context, id int64) (store.Access, error) {
			panic("mock out the GetAccess method")
		},
		GetGroupFunc: func(ctx context.Context, id int64) (store.Group, error) {
			panic("mock out the GetGroup method")
		},
		GetRepositoryFunc: func(ctx context.Context, entryID int64) (store.RegistryEntry, error) {
			panic("mock out the GetRepository method")
		},
		GetUserFunc: func(ctx context.Context, id interface{}) (store.User, error) {
			panic("mock out the GetUser method")
		},
		RepositoryGarbageCollectorFunc: func(ctx context.Context, syncDate int64) error {
			panic("mock out the RepositoryGarbageCollector method")
		},
		UpdateAccessFunc: func(ctx context.Context, access store.Access) error {
			panic("mock out the UpdateAccess method")
		},
		UpdateGroupFunc: func(ctx context.Context, group store.Group) error {
			panic("mock out the UpdateGroup method")
		},
		UpdateRepositoryFunc: func(ctx context.Context, conditionClause map[string]interface{}, data map[string]interface{}) error {
			panic("mock out the UpdateRepository method")
		},
		UpdateUserFunc: func(ctx context.Context, user store.User) error {
			panic("mock out the UpdateUser method")
		},
	}

	// use mockedInterface in code that requires Interface
	// and then make assertions.

}

func (*InterfaceMock) AccessGarbageCollector

func (mock *InterfaceMock) AccessGarbageCollector(ctx context.Context) error

AccessGarbageCollector calls AccessGarbageCollectorFunc.

func (*InterfaceMock) AccessGarbageCollectorCalls

func (mock *InterfaceMock) AccessGarbageCollectorCalls() []struct {
	Ctx context.Context
}

AccessGarbageCollectorCalls gets all the calls that were made to AccessGarbageCollector. Check the length with:

len(mockedInterface.AccessGarbageCollectorCalls())

func (*InterfaceMock) Close

func (mock *InterfaceMock) Close(ctx context.Context) error

Close calls CloseFunc.

func (*InterfaceMock) CloseCalls

func (mock *InterfaceMock) CloseCalls() []struct {
	Ctx context.Context
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedInterface.CloseCalls())

func (*InterfaceMock) CreateAccess

func (mock *InterfaceMock) CreateAccess(ctx context.Context, access *store.Access) error

CreateAccess calls CreateAccessFunc.

func (*InterfaceMock) CreateAccessCalls

func (mock *InterfaceMock) CreateAccessCalls() []struct {
	Ctx    context.Context
	Access *store.Access
}

CreateAccessCalls gets all the calls that were made to CreateAccess. Check the length with:

len(mockedInterface.CreateAccessCalls())

func (*InterfaceMock) CreateGroup

func (mock *InterfaceMock) CreateGroup(ctx context.Context, group *store.Group) error

CreateGroup calls CreateGroupFunc.

func (*InterfaceMock) CreateGroupCalls

func (mock *InterfaceMock) CreateGroupCalls() []struct {
	Ctx   context.Context
	Group *store.Group
}

CreateGroupCalls gets all the calls that were made to CreateGroup. Check the length with:

len(mockedInterface.CreateGroupCalls())

func (*InterfaceMock) CreateRepository

func (mock *InterfaceMock) CreateRepository(ctx context.Context, entry *store.RegistryEntry) error

CreateRepository calls CreateRepositoryFunc.

func (*InterfaceMock) CreateRepositoryCalls

func (mock *InterfaceMock) CreateRepositoryCalls() []struct {
	Ctx   context.Context
	Entry *store.RegistryEntry
}

CreateRepositoryCalls gets all the calls that were made to CreateRepository. Check the length with:

len(mockedInterface.CreateRepositoryCalls())

func (*InterfaceMock) CreateUser

func (mock *InterfaceMock) CreateUser(ctx context.Context, user *store.User) error

CreateUser calls CreateUserFunc.

func (*InterfaceMock) CreateUserCalls

func (mock *InterfaceMock) CreateUserCalls() []struct {
	Ctx  context.Context
	User *store.User
}

CreateUserCalls gets all the calls that were made to CreateUser. Check the length with:

len(mockedInterface.CreateUserCalls())

func (*InterfaceMock) DeleteAccess

func (mock *InterfaceMock) DeleteAccess(ctx context.Context, key string, id interface{}) error

DeleteAccess calls DeleteAccessFunc.

func (*InterfaceMock) DeleteAccessCalls

func (mock *InterfaceMock) DeleteAccessCalls() []struct {
	Ctx context.Context
	Key string
	ID  interface{}
}

DeleteAccessCalls gets all the calls that were made to DeleteAccess. Check the length with:

len(mockedInterface.DeleteAccessCalls())

func (*InterfaceMock) DeleteGroup

func (mock *InterfaceMock) DeleteGroup(ctx context.Context, id int64) error

DeleteGroup calls DeleteGroupFunc.

func (*InterfaceMock) DeleteGroupCalls

func (mock *InterfaceMock) DeleteGroupCalls() []struct {
	Ctx context.Context
	ID  int64
}

DeleteGroupCalls gets all the calls that were made to DeleteGroup. Check the length with:

len(mockedInterface.DeleteGroupCalls())

func (*InterfaceMock) DeleteRepository

func (mock *InterfaceMock) DeleteRepository(ctx context.Context, repositoryName string, digest string) error

DeleteRepository calls DeleteRepositoryFunc.

func (*InterfaceMock) DeleteRepositoryCalls

func (mock *InterfaceMock) DeleteRepositoryCalls() []struct {
	Ctx            context.Context
	RepositoryName string
	Digest         string
}

DeleteRepositoryCalls gets all the calls that were made to DeleteRepository. Check the length with:

len(mockedInterface.DeleteRepositoryCalls())

func (*InterfaceMock) DeleteUser

func (mock *InterfaceMock) DeleteUser(ctx context.Context, id int64) error

DeleteUser calls DeleteUserFunc.

func (*InterfaceMock) DeleteUserCalls

func (mock *InterfaceMock) DeleteUserCalls() []struct {
	Ctx context.Context
	ID  int64
}

DeleteUserCalls gets all the calls that were made to DeleteUser. Check the length with:

len(mockedInterface.DeleteUserCalls())

func (*InterfaceMock) FindAccesses

func (mock *InterfaceMock) FindAccesses(ctx context.Context, filter QueryFilter) (ListResponse, error)

FindAccesses calls FindAccessesFunc.

func (*InterfaceMock) FindAccessesCalls

func (mock *InterfaceMock) FindAccessesCalls() []struct {
	Ctx    context.Context
	Filter QueryFilter
}

FindAccessesCalls gets all the calls that were made to FindAccesses. Check the length with:

len(mockedInterface.FindAccessesCalls())

func (*InterfaceMock) FindGroups

func (mock *InterfaceMock) FindGroups(ctx context.Context, filter QueryFilter) (ListResponse, error)

FindGroups calls FindGroupsFunc.

func (*InterfaceMock) FindGroupsCalls

func (mock *InterfaceMock) FindGroupsCalls() []struct {
	Ctx    context.Context
	Filter QueryFilter
}

FindGroupsCalls gets all the calls that were made to FindGroups. Check the length with:

len(mockedInterface.FindGroupsCalls())

func (*InterfaceMock) FindRepositories

func (mock *InterfaceMock) FindRepositories(ctx context.Context, filter QueryFilter) (ListResponse, error)

FindRepositories calls FindRepositoriesFunc.

func (*InterfaceMock) FindRepositoriesCalls

func (mock *InterfaceMock) FindRepositoriesCalls() []struct {
	Ctx    context.Context
	Filter QueryFilter
}

FindRepositoriesCalls gets all the calls that were made to FindRepositories. Check the length with:

len(mockedInterface.FindRepositoriesCalls())

func (*InterfaceMock) FindUsers

func (mock *InterfaceMock) FindUsers(ctx context.Context, filter QueryFilter, withPassword bool) (ListResponse, error)

FindUsers calls FindUsersFunc.

func (*InterfaceMock) FindUsersCalls

func (mock *InterfaceMock) FindUsersCalls() []struct {
	Ctx          context.Context
	Filter       QueryFilter
	WithPassword bool
}

FindUsersCalls gets all the calls that were made to FindUsers. Check the length with:

len(mockedInterface.FindUsersCalls())

func (*InterfaceMock) GetAccess

func (mock *InterfaceMock) GetAccess(ctx context.Context, id int64) (store.Access, error)

GetAccess calls GetAccessFunc.

func (*InterfaceMock) GetAccessCalls

func (mock *InterfaceMock) GetAccessCalls() []struct {
	Ctx context.Context
	ID  int64
}

GetAccessCalls gets all the calls that were made to GetAccess. Check the length with:

len(mockedInterface.GetAccessCalls())

func (*InterfaceMock) GetGroup

func (mock *InterfaceMock) GetGroup(ctx context.Context, id int64) (store.Group, error)

GetGroup calls GetGroupFunc.

func (*InterfaceMock) GetGroupCalls

func (mock *InterfaceMock) GetGroupCalls() []struct {
	Ctx context.Context
	ID  int64
}

GetGroupCalls gets all the calls that were made to GetGroup. Check the length with:

len(mockedInterface.GetGroupCalls())

func (*InterfaceMock) GetRepository

func (mock *InterfaceMock) GetRepository(ctx context.Context, entryID int64) (store.RegistryEntry, error)

GetRepository calls GetRepositoryFunc.

func (*InterfaceMock) GetRepositoryCalls

func (mock *InterfaceMock) GetRepositoryCalls() []struct {
	Ctx     context.Context
	EntryID int64
}

GetRepositoryCalls gets all the calls that were made to GetRepository. Check the length with:

len(mockedInterface.GetRepositoryCalls())

func (*InterfaceMock) GetUser

func (mock *InterfaceMock) GetUser(ctx context.Context, id interface{}) (store.User, error)

GetUser calls GetUserFunc.

func (*InterfaceMock) GetUserCalls

func (mock *InterfaceMock) GetUserCalls() []struct {
	Ctx context.Context
	ID  interface{}
}

GetUserCalls gets all the calls that were made to GetUser. Check the length with:

len(mockedInterface.GetUserCalls())

func (*InterfaceMock) RepositoryGarbageCollector

func (mock *InterfaceMock) RepositoryGarbageCollector(ctx context.Context, syncDate int64) error

RepositoryGarbageCollector calls RepositoryGarbageCollectorFunc.

func (*InterfaceMock) RepositoryGarbageCollectorCalls

func (mock *InterfaceMock) RepositoryGarbageCollectorCalls() []struct {
	Ctx      context.Context
	SyncDate int64
}

RepositoryGarbageCollectorCalls gets all the calls that were made to RepositoryGarbageCollector. Check the length with:

len(mockedInterface.RepositoryGarbageCollectorCalls())

func (*InterfaceMock) UpdateAccess

func (mock *InterfaceMock) UpdateAccess(ctx context.Context, access store.Access) error

UpdateAccess calls UpdateAccessFunc.

func (*InterfaceMock) UpdateAccessCalls

func (mock *InterfaceMock) UpdateAccessCalls() []struct {
	Ctx    context.Context
	Access store.Access
}

UpdateAccessCalls gets all the calls that were made to UpdateAccess. Check the length with:

len(mockedInterface.UpdateAccessCalls())

func (*InterfaceMock) UpdateGroup

func (mock *InterfaceMock) UpdateGroup(ctx context.Context, group store.Group) error

UpdateGroup calls UpdateGroupFunc.

func (*InterfaceMock) UpdateGroupCalls

func (mock *InterfaceMock) UpdateGroupCalls() []struct {
	Ctx   context.Context
	Group store.Group
}

UpdateGroupCalls gets all the calls that were made to UpdateGroup. Check the length with:

len(mockedInterface.UpdateGroupCalls())

func (*InterfaceMock) UpdateRepository

func (mock *InterfaceMock) UpdateRepository(ctx context.Context, conditionClause map[string]interface{}, data map[string]interface{}) error

UpdateRepository calls UpdateRepositoryFunc.

func (*InterfaceMock) UpdateRepositoryCalls

func (mock *InterfaceMock) UpdateRepositoryCalls() []struct {
	Ctx             context.Context
	ConditionClause map[string]interface{}
	Data            map[string]interface{}
}

UpdateRepositoryCalls gets all the calls that were made to UpdateRepository. Check the length with:

len(mockedInterface.UpdateRepositoryCalls())

func (*InterfaceMock) UpdateUser

func (mock *InterfaceMock) UpdateUser(ctx context.Context, user store.User) error

UpdateUser calls UpdateUserFunc.

func (*InterfaceMock) UpdateUserCalls

func (mock *InterfaceMock) UpdateUserCalls() []struct {
	Ctx  context.Context
	User store.User
}

UpdateUserCalls gets all the calls that were made to UpdateUser. Check the length with:

len(mockedInterface.UpdateUserCalls())

type ListResponse

type ListResponse struct {
	Total int64         `json:"total"`
	Data  []interface{} `json:"data"`
}

ListResponse is a container for return list of result data

type QueryFilter

type QueryFilter struct {
	Range [2]int64 // array indexes are: 0 - Skip value, 1 - Limit value
	IDs   []int64  `json:"id"`

	// 'q' - key in filter use for full text search by fields which defined with parameters in filtersBuilder
	// other filters keys/values applies as exactly condition in query (at where clause)
	Filters map[string]interface{}

	Sort []string // ASC or DESC

	// GroupByFiled set field name to make a unique search by repositories table which contain duplicate repository names linked to different tags
	// GroupByField value for grouping should define in an engine implementation
	GroupByField bool
}

QueryFilter using for query to data from storage

func FilterFromURLExtractor

func FilterFromURLExtractor(requestedURL *url.URL) (filters QueryFilter, err error)

FilterFromURLExtractor extracts param from URL and pass it to query which manipulation data in storage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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