db

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const MembersNamespace = "members"
View Source
const ProjectNamespace = "projects"
View Source
const TenantNamespace = "tenants"
View Source
const TopicNamespace = "topics"

Variables

View Source
var (
	ErrNotConnected       = errors.New("not connected to trtl database")
	ErrNotFound           = errors.New("object not found for the specified key")
	ErrUnavailable        = errors.New("trtl database service is unavailable")
	ErrMissingID          = errors.New("object requires id for serialization")
	ErrMissingOrgID       = errors.New("object requires organization id for serialization")
	ErrMissingTenantID    = errors.New("object requires tenant id for serialization")
	ErrMissingProjectID   = errors.New("object requires project id for serialization")
	ErrMissingMemberName  = errors.New("member name is required")
	ErrMissingMemberRole  = errors.New("member role is required")
	ErrMissingProjectName = errors.New("project name is required")
	ErrMissingTenantName  = errors.New("tenant name is required")
	ErrMissingEnvType     = errors.New("tenant environment type is required")
	ErrMissingTopicName   = errors.New("topic name is required")
)

Functions

func Close

func Close() error

Close the connection to the database, once closed the package must be reconnected otherwise database operations will not succeed. If the database is already closed then no error will occur.

func Connect

func Connect(conf config.DatabaseConfig) (err error)

Connect to the trtl database, this function must be called at least once before any database interaction can occur. Multiple calls to Connect will not error (e.g. if the database is already connected then nothing will happen).

func CreateMember added in v0.2.0

func CreateMember(ctx context.Context, member *Member) (err error)

CreateMember adds a new Member to an organization in the database. Note: If a memberID is not passed in by the User, a new member id will be generated.

func CreateProject added in v0.2.0

func CreateProject(ctx context.Context, project *Project) (err error)

CreateProject adds a new project to an organization in the database. Note: If a project id is not passed in by the User, a new project id will be generated.

func CreateTenant

func CreateTenant(ctx context.Context, tenant *Tenant) (err error)

CreateTenant adds a new project to the database. Note: If a tenant id is not passed in by the User, a new tenant id will be generated.

func CreateTenantMember added in v0.2.0

func CreateTenantMember(ctx context.Context, member *Member) (err error)

CreateTenantMember adds a new Member to a tenant in the database. Note: If a memberID is not passed in by the User, a new member id will be generated.

func CreateTenantProject added in v0.2.0

func CreateTenantProject(ctx context.Context, project *Project) (err error)

CreateTenantProject adds a new project to a tenant in the database. Note: If a project id is not passed in by the User, a new project id will be generated.

func CreateTopic added in v0.2.0

func CreateTopic(ctx context.Context, topic *Topic) (err error)

CreateTopic adds a new topic to the database.

func CreateUserResources added in v0.3.0

func CreateUserResources(ctx context.Context, projectID ulid.ULID, member *Member) (err error)

CreateUserResources creates all the necessary database objects for a new user given a partially constructed member model. This method should be called after a new user has been successfully registered with Quarterdeck in order to allow the user to access default resources such as the tenant and project when they login.

func Delete

func Delete(ctx context.Context, model Model) (err error)

func DeleteMember added in v0.2.0

func DeleteMember(ctx context.Context, id ulid.ULID) (err error)

DeleteMember deletes a member with a given id.

func DeleteProject added in v0.2.0

func DeleteProject(ctx context.Context, id ulid.ULID) (err error)

DeleteProject deletes a project with a given id.

func DeleteTenant

func DeleteTenant(ctx context.Context, id ulid.ULID) (err error)

func DeleteTopic added in v0.2.0

func DeleteTopic(ctx context.Context, id ulid.ULID) (err error)

DeleteTopic deletes a topic by a given ID.

func Get

func Get(ctx context.Context, model Model) (err error)

Get retrieves a model value based on its key and namespace.

func GetMock added in v0.2.0

func GetMock() *mock.RemoteTrtl

func IsConnected

func IsConnected() bool

IsConnected returns true if the database has been connected to without error and the db module is ready to interact with the trtl database.

func IsTesting added in v0.2.0

func IsTesting() bool

func List

func List(ctx context.Context, prefix []byte, namespace string) (values [][]byte, err error)

func Put

func Put(ctx context.Context, model Model) (err error)

func UpdateMember added in v0.2.0

func UpdateMember(ctx context.Context, member *Member) (err error)

UpdateMember updates the record of a member by its id.

func UpdateProject added in v0.2.0

func UpdateProject(ctx context.Context, project *Project) (err error)

UpdateProject updates the record of a project by its id.

func UpdateTenant

func UpdateTenant(ctx context.Context, tenant *Tenant) (err error)

func UpdateTopic added in v0.2.0

func UpdateTopic(ctx context.Context, topic *Topic) (err error)

UpdateTopic updates the record of a topic by a given ID.

func ValidationError added in v0.3.0

func ValidationError(model string) error

Types

type Member added in v0.2.0

type Member struct {
	OrgID    ulid.ULID `msgpack:"org_id"`
	TenantID ulid.ULID `msgpack:"tenant_id"`
	ID       ulid.ULID `msgpack:"id"`
	Name     string    `msgpack:"name"`
	Role     string    `msgpack:"role"`
	Created  time.Time `msgpack:"created"`
	Modified time.Time `msgpack:"modified"`
}

func ListMembers added in v0.2.0

func ListMembers(ctx context.Context, tenantID ulid.ULID) (members []*Member, err error)

ListMembers retrieves all members assigned to a tenant.

func RetrieveMember added in v0.2.0

func RetrieveMember(ctx context.Context, id ulid.ULID) (member *Member, err error)

RetrieveMember gets a member from the database with a given id.

func (*Member) Key added in v0.2.0

func (m *Member) Key() (key []byte, err error)

Key is a 32 byte composite key combining the tennat id and member id.

func (*Member) MarshalValue added in v0.2.0

func (m *Member) MarshalValue() ([]byte, error)

func (*Member) Namespace added in v0.2.0

func (m *Member) Namespace() string

func (*Member) UnmarshalValue added in v0.2.0

func (m *Member) UnmarshalValue(data []byte) error

func (*Member) Validate added in v0.2.0

func (m *Member) Validate(requireTenant bool) error

Validate checks that the member data is valid. The tenant id is only required if requireTenant is set to allow this method to be used by both CreateMember and CreateTenantMember.

type Model

type Model interface {
	// Handle database storage semantics
	Key() ([]byte, error)
	Namespace() string

	// Handle serialization and deserialization of a single Model
	MarshalValue() ([]byte, error)
	UnmarshalValue([]byte) error
}

Models are structs that have key-value properties that can used for Get, Put, and Delete operations to the database. The Model interface allows us to unify common interaction patterns (for example checking connections) and returning specific errors as well as ensuring that serialization and deserialization occur correctly.

type Project added in v0.2.0

type Project struct {
	OrgID    ulid.ULID `msgpack:"org_id"`
	TenantID ulid.ULID `msgpack:"tenant_id"`
	ID       ulid.ULID `msgpack:"id"`
	Name     string    `msgpack:"name"`
	Created  time.Time `msgpack:"created"`
	Modified time.Time `msgpack:"modified"`
}

func ListProjects added in v0.2.0

func ListProjects(ctx context.Context, tenantID ulid.ULID) (projects []*Project, err error)

ListProjects retrieves all projects assigned to a tenant.

func RetrieveProject added in v0.2.0

func RetrieveProject(ctx context.Context, id ulid.ULID) (project *Project, err error)

RetrieveProject gets a project from the database with a given id.

func (*Project) Key added in v0.2.0

func (p *Project) Key() (key []byte, err error)

Key is a 32 composite key combining the tenant id and the project id.

func (*Project) MarshalValue added in v0.2.0

func (p *Project) MarshalValue() ([]byte, error)

func (*Project) Namespace added in v0.2.0

func (p *Project) Namespace() string

func (*Project) UnmarshalValue added in v0.2.0

func (p *Project) UnmarshalValue(data []byte) error

func (*Project) Validate added in v0.2.0

func (p *Project) Validate() error

type Tenant

type Tenant struct {
	OrgID           ulid.ULID `msgpack:"org_id"`
	ID              ulid.ULID `msgpack:"id"`
	Name            string    `msgpack:"name"`
	EnvironmentType string    `msgpack:"environment_type"`
	Created         time.Time `msgpack:"created"`
	Modified        time.Time `msgpack:"modified"`
}

func ListTenants added in v0.2.0

func ListTenants(ctx context.Context, orgID ulid.ULID) (tenants []*Tenant, err error)

ListTenants retrieves all tenants assigned to an organization.

func RetrieveTenant

func RetrieveTenant(ctx context.Context, id ulid.ULID) (tenant *Tenant, err error)

func (*Tenant) Key

func (t *Tenant) Key() (key []byte, err error)

Key is a 32 byte composite key combining the org id and tenant id.

func (*Tenant) MarshalValue

func (t *Tenant) MarshalValue() ([]byte, error)

func (*Tenant) Namespace

func (t *Tenant) Namespace() string

func (*Tenant) UnmarshalValue

func (t *Tenant) UnmarshalValue(data []byte) error

func (*Tenant) Validate added in v0.3.0

func (t *Tenant) Validate() error

type Topic added in v0.2.0

type Topic struct {
	OrgID     ulid.ULID `msgpack:"org_id"`
	ProjectID ulid.ULID `msgpack:"project_id"`
	ID        ulid.ULID `msgpack:"id"`
	Name      string    `msgpack:"name"`
	Created   time.Time `msgpack:"created"`
	Modified  time.Time `msgpack:"modified"`
}

func ListTopics added in v0.2.0

func ListTopics(ctx context.Context, projectID ulid.ULID) (topics []*Topic, err error)

ListTopics retrieves all topics assigned to a project.

func RetrieveTopic added in v0.2.0

func RetrieveTopic(ctx context.Context, id ulid.ULID) (topic *Topic, err error)

RetrieveTopic gets a topic from the database by a given ID.

func (*Topic) Key added in v0.2.0

func (t *Topic) Key() (key []byte, err error)

Key is a 32 composite key combining the project ID and the topic ID.

func (*Topic) MarshalValue added in v0.2.0

func (t *Topic) MarshalValue() ([]byte, error)

func (*Topic) Namespace added in v0.2.0

func (t *Topic) Namespace() string

func (*Topic) UnmarshalValue added in v0.2.0

func (t *Topic) UnmarshalValue(data []byte) error

func (*Topic) Validate added in v0.2.0

func (t *Topic) Validate() error

Jump to

Keyboard shortcuts

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