Documentation ¶
Index ¶
- Constants
- Variables
- func Close() error
- func Connect(conf config.DatabaseConfig) (err error)
- func CreateMember(ctx context.Context, member *Member) (err error)
- func CreateProject(ctx context.Context, project *Project) (err error)
- func CreateTenant(ctx context.Context, tenant *Tenant) (err error)
- func CreateTenantProject(ctx context.Context, project *Project) (err error)
- func CreateTopic(ctx context.Context, topic *Topic) (err error)
- func CreateUserResources(ctx context.Context, projectID ulid.ULID, orgName string, member *Member) (err error)
- func Delete(ctx context.Context, model Model) (err error)
- func DeleteMember(ctx context.Context, orgID, memberID ulid.ULID) (err error)
- func DeleteObjectKey(ctx context.Context, key []byte) (err error)
- func DeleteProject(ctx context.Context, projectID ulid.ULID) (err error)
- func DeleteTenant(ctx context.Context, orgID, tenantID ulid.ULID) (err error)
- func DeleteTopic(ctx context.Context, topicID ulid.ULID) (err error)
- func Get(ctx context.Context, model Model) (err error)
- func GetMock() *mock.RemoteTrtl
- func GetObjectKey(ctx context.Context, objectID ulid.ULID) (key []byte, err error)
- func IsConnected() bool
- func IsTesting() bool
- func List(ctx context.Context, prefix []byte, namespace string) (values [][]byte, err error)
- func NewResourceToken(id ulid.ULID) (string, error)
- func Put(ctx context.Context, model Model) (err error)
- func PutObjectKey(ctx context.Context, object Model) (err error)
- func TimeToString(t time.Time) string
- func UpdateMember(ctx context.Context, member *Member) (err error)
- func UpdateProject(ctx context.Context, project *Project) (err error)
- func UpdateTenant(ctx context.Context, tenant *Tenant) (err error)
- func UpdateTopic(ctx context.Context, topic *Topic) (err error)
- type Key
- type Member
- type Model
- type Project
- type ResourceToken
- type Tenant
- type Topic
Constants ¶
const KeysNamespace = "object_keys"
Keys Namespace maps object IDs to their fully qualified database keys.
const MembersNamespace = "members"
const ProjectNamespace = "projects"
const TenantNamespace = "tenants"
const TopicNamespace = "topics"
Variables ¶
var ( ErrNotConnected = errors.New("not connected to trtl database") ErrNotFound = errors.New("object not found for the specified key") // Missing fields 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") // Invalid fields ErrInvalidMemberName = errors.New("invalid member name") ErrUnknownMemberRole = errors.New("unknown member role") ErrInvalidProjectName = errors.New("invalid project name") ErrInvalidTenantName = errors.New("invalid tenant name") ErrInvalidTopicName = errors.New("invalid topic name") // Key errors ErrKeyNoID = errors.New("key does not contain an id") ErrKeyWrongSize = errors.New("key is not the correct size") )
var NullID = []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
var TenantNameRegex = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9\.\-_]*$`)
Tenant names must be URL safe and begin with a letter.
var TopicNameRegex = regexp.MustCompile("^[a-zA-Z][a-zA-Z0-9.-_]*$")
Topic names must be URL safe and begin with a letter.
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
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
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 ¶
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 CreateTenantProject ¶ added in v0.2.0
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
CreateTopic adds a new topic to the database.
func CreateUserResources ¶ added in v0.3.0
func CreateUserResources(ctx context.Context, projectID ulid.ULID, orgName string, 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 DeleteMember ¶ added in v0.2.0
DeleteMember deletes a member with a given orgID and member ID.
func DeleteObjectKey ¶ added in v0.5.0
Helper to delete an object's key from the database.
func DeleteProject ¶ added in v0.2.0
DeleteProject deletes a project with the given project id.
func DeleteTenant ¶
Delete a tenant from the orgID and tenantID.
func DeleteTopic ¶ added in v0.2.0
DeleteTopic deletes a topic by the given project ID and topic ID.
func GetMock ¶ added in v0.2.0
func GetMock() *mock.RemoteTrtl
func GetObjectKey ¶ added in v0.5.0
Helper to retrieve an object's key from its ID from the database.
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 NewResourceToken ¶ added in v0.5.0
NewResourceToken creates a new string token that includes a random secret and expires after 5 minutes.
func PutObjectKey ¶ added in v0.5.0
Helper to store an object's key in the database.
func TimeToString ¶ added in v0.5.0
Helper to convert a time.Time to an RFC3339Nano string for JSON serialization.
func UpdateMember ¶ added in v0.2.0
UpdateMember updates the record of a member by its id.
func UpdateProject ¶ added in v0.2.0
UpdateProject updates the record of a project from its database model.
Types ¶
type Key ¶ added in v0.5.0
type Key [32]byte
Key is composed of two concatenated IDs. The first 16 bytes are the ID of parent and the second 16 bytes are the ID of the object.
func CreateKey ¶ added in v0.5.0
CreateKey creates a new key from a parent ID and object ID so that callers can lookup the object ID from its namespace.
func (Key) Key ¶ added in v0.5.0
Keys are stored by object ID. Since object IDs are locked monotonically increasing ulids they are guaranteed to be unique.
func (Key) MarshalValue ¶ added in v0.5.0
func (*Key) UnmarshalValue ¶ added in v0.5.0
type Member ¶ added in v0.2.0
type Member struct { OrgID ulid.ULID `msgpack:"org_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
ListMembers retrieves all members in an organization.
func RetrieveMember ¶ added in v0.2.0
RetrieveMember gets a member from the database with the given orgID and member ID.
func (*Member) Key ¶ added in v0.2.0
Key is a 32 byte composite key combining the org id and member id.
func (*Member) MarshalValue ¶ added in v0.2.0
func (*Member) ToAPI ¶ added in v0.5.0
func (m *Member) ToAPI() *api.Member
Convert the model to an API response
func (*Member) UnmarshalValue ¶ added in v0.2.0
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
ListProjects retrieves all projects assigned to a tenant.
func RetrieveProject ¶ added in v0.2.0
RetrieveProject gets a project from the database with the given project id.
func (*Project) Key ¶ added in v0.2.0
Key is a 32 composite key combining the tenant id and the project id.
func (*Project) MarshalValue ¶ added in v0.2.0
func (*Project) ToAPI ¶ added in v0.5.0
func (p *Project) ToAPI() *api.Project
Convert the model to an API response.
func (*Project) UnmarshalValue ¶ added in v0.2.0
type ResourceToken ¶ added in v0.5.0
type ResourceToken struct { ID ulid.ULID `msgpack:"id"` Secret string `msgpack:"token"` ExpiresAt time.Time `msgpack:"expires_at"` }
ResourceToken protects access to a resource by encoding an ID with a cryptographically secure secret and an expiration time.
func (*ResourceToken) Create ¶ added in v0.5.0
func (t *ResourceToken) Create() (_ string, err error)
Create a new base64 encoded string from the token data. Note that callers should use the NewResourceToken method to ensure that all fields are present; this method is primarily exposed for the tests.
func (*ResourceToken) Decode ¶ added in v0.5.0
func (t *ResourceToken) Decode(token string) (err error)
Decode a base64 encoded string into the struct.
func (*ResourceToken) IsExpired ¶ added in v0.5.0
func (t *ResourceToken) IsExpired() bool
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
ListTenants retrieves all tenants assigned to an organization.
func RetrieveTenant ¶
Retrieve a tenant from the orgID and tenantID.
func (*Tenant) MarshalValue ¶
func (*Tenant) ToAPI ¶ added in v0.5.0
func (t *Tenant) ToAPI() *api.Tenant
Convert the model to an API response.
func (*Tenant) UnmarshalValue ¶
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"` State pb.TopicTombstone_Status `msgpack:"state"` ConfirmDeleteToken string `msgpack:"confirm_delete_token"` Created time.Time `msgpack:"created"` Modified time.Time `msgpack:"modified"` }
func ListTopics ¶ added in v0.2.0
ListTopics retrieves all topics assigned to a project.
func RetrieveTopic ¶ added in v0.2.0
RetrieveTopic gets a topic from the database by the given topic ID.
func (*Topic) Key ¶ added in v0.2.0
Key is a 32 composite key combining the project ID and the topic ID.
func (*Topic) MarshalValue ¶ added in v0.2.0
func (*Topic) ToAPI ¶ added in v0.5.0
func (t *Topic) ToAPI() *api.Topic
Convert the model to an API response.