postgres

package
v0.7.22 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TABLE_PERMISSIONS            = "permissions"
	TABLE_GROUPS                 = "groups"
	TABLE_NAMESPACES             = "namespaces"
	TABLE_ORGANIZATIONS          = "organizations"
	TABLE_POLICIES               = "policies"
	TABLE_PROJECTS               = "projects"
	TABLE_RELATIONS              = "relations"
	TABLE_RESOURCES              = "resources"
	TABLE_ROLES                  = "roles"
	TABLE_USERS                  = "users"
	TABLE_METASCHEMA             = "metaschema"
	TABLE_FLOWS                  = "flows"
	TABLE_SESSIONS               = "sessions"
	TABLE_INVITATIONS            = "invitations"
	TABLE_SERVICEUSER            = "serviceusers"
	TABLE_SERVICEUSERCREDENTIALS = "serviceuser_credentials"
	TABLE_AUDITLOGS              = "auditlogs"
	TABLE_DOMAINS                = "domains"
	TABLE_PREFERENCES            = "preferences"
)

Variables

View Source
var (
	ErrDuplicateKey              = errors.New("duplicate key")
	ErrCheckViolation            = errors.New("check constraint violation")
	ErrForeignKeyViolation       = errors.New("foreign key violation")
	ErrInvalidTextRepresentation = errors.New("invalid input syntax type")
	ErrInvalidID                 = errors.New("invalid id")
)
View Source
var (
	ErrInvalidSlug = fmt.Errorf("invalid slug")
)

Functions

This section is empty.

Types

type Audit

type Audit struct {
	ID     string `db:"id"`
	OrgID  string `db:"org_id"`
	Source string `db:"source"`
	Action string `db:"action"`

	Actor    types.NullJSONText `db:"actor"`
	Target   types.NullJSONText `db:"target"`
	Metadata types.NullJSONText `db:"metadata"`

	CreatedAt time.Time `db:"created_at"`
}

type AuditRepository

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

func NewAuditRepository

func NewAuditRepository(dbc *db.Client) *AuditRepository

func (AuditRepository) Create

func (a AuditRepository) Create(ctx context.Context, l *audit.Log) error

func (AuditRepository) GetByID

func (a AuditRepository) GetByID(ctx context.Context, id string) (audit.Log, error)

func (AuditRepository) List

func (a AuditRepository) List(ctx context.Context, flt audit.Filter) ([]audit.Log, error)

type Domain added in v0.7.2

type Domain struct {
	ID        string    `db:"id"`
	OrgID     string    `db:"org_id"`
	Name      string    `db:"name"`
	Token     string    `db:"token"`
	State     string    `db:"state"`
	UpdatedAt time.Time `db:"updated_at"`
	CreatedAt time.Time `db:"created_at"`
}

type DomainRepository added in v0.7.2

type DomainRepository struct {
	Now func() time.Time
	// contains filtered or unexported fields
}

func NewDomainRepository added in v0.7.2

func NewDomainRepository(logger log.Logger, dbc *db.Client) *DomainRepository

func (*DomainRepository) Create added in v0.7.2

func (s *DomainRepository) Create(ctx context.Context, toCreate domain.Domain) (domain.Domain, error)

func (*DomainRepository) Delete added in v0.7.2

func (s *DomainRepository) Delete(ctx context.Context, id string) error

func (*DomainRepository) DeleteExpiredDomainRequests added in v0.7.2

func (s *DomainRepository) DeleteExpiredDomainRequests(ctx context.Context) error

func (*DomainRepository) Get added in v0.7.2

func (*DomainRepository) List added in v0.7.2

func (*DomainRepository) Update added in v0.7.2

func (s *DomainRepository) Update(ctx context.Context, toUpdate domain.Domain) (domain.Domain, error)

type Flow

type Flow struct {
	ID        uuid.UUID `db:"id"`
	Method    string    `db:"method"`
	Email     string    `db:"email"`
	Nonce     string    `db:"nonce"`
	Metadata  []byte    `db:"metadata"`
	CreatedAt time.Time `db:"created_at"`
	ExpiresAt time.Time `db:"expires_at"`
}

type FlowRepository

type FlowRepository struct {
	Now func() time.Time
	// contains filtered or unexported fields
}

func NewFlowRepository

func NewFlowRepository(logger log.Logger, dbc *db.Client) *FlowRepository

func (*FlowRepository) Delete

func (s *FlowRepository) Delete(ctx context.Context, id uuid.UUID) error

func (*FlowRepository) DeleteExpiredFlows

func (s *FlowRepository) DeleteExpiredFlows(ctx context.Context) error

func (*FlowRepository) Get

func (*FlowRepository) Set

func (s *FlowRepository) Set(ctx context.Context, flow *authenticate.Flow) error

type Group

type Group struct {
	ID        string         `db:"id"`
	Name      string         `db:"name"`
	Title     sql.NullString `db:"title"`
	OrgID     string         `db:"org_id"`
	Metadata  []byte         `db:"metadata"`
	State     sql.NullString `db:"state"`
	CreatedAt time.Time      `db:"created_at"`
	UpdatedAt time.Time      `db:"updated_at"`
	DeletedAt sql.NullTime   `db:"deleted_at"`
}

type GroupRepository

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

func NewGroupRepository

func NewGroupRepository(dbc *db.Client) *GroupRepository

func (GroupRepository) Create

func (r GroupRepository) Create(ctx context.Context, grp group.Group) (group.Group, error)

func (GroupRepository) Delete

func (r GroupRepository) Delete(ctx context.Context, id string) error

func (GroupRepository) GetByID

func (r GroupRepository) GetByID(ctx context.Context, id string) (group.Group, error)

func (GroupRepository) GetByIDs

func (r GroupRepository) GetByIDs(ctx context.Context, groupIDs []string, flt group.Filter) ([]group.Group, error)

func (GroupRepository) List

func (r GroupRepository) List(ctx context.Context, flt group.Filter) ([]group.Group, error)

func (GroupRepository) ListGroupRelations

func (r GroupRepository) ListGroupRelations(ctx context.Context, objectId string, subject_type string, role string) ([]relation.Relation, error)

TODO(kushsharma): no longer in use, delete if needed

func (GroupRepository) SetState

func (r GroupRepository) SetState(ctx context.Context, id string, state group.State) error

func (GroupRepository) UpdateByID

func (r GroupRepository) UpdateByID(ctx context.Context, grp group.Group) (group.Group, error)

type Invitation

type Invitation struct {
	ID        uuid.UUID `db:"id"`
	UserID    string    `db:"user_id"`
	OrgID     string    `db:"org_id"`
	Metadata  []byte    `db:"metadata"`
	CreatedAt time.Time `db:"created_at"`
	ExpiresAt time.Time `db:"expires_at"`
}

type InvitationRepository

type InvitationRepository struct {
	Now func() time.Time
	// contains filtered or unexported fields
}

func NewInvitationRepository

func NewInvitationRepository(logger log.Logger, dbc *db.Client) *InvitationRepository

func (*InvitationRepository) Delete

func (s *InvitationRepository) Delete(ctx context.Context, id uuid.UUID) error

func (*InvitationRepository) GarbageCollect

func (s *InvitationRepository) GarbageCollect(ctx context.Context) error

TODO(kushsharma): schedue a cron for it

func (*InvitationRepository) Get

func (*InvitationRepository) List

func (*InvitationRepository) ListByUser

func (*InvitationRepository) Set

type MetaSchema

type MetaSchema struct {
	ID        string    `db:"id"`
	Name      string    `db:"name"`
	Schema    string    `db:"schema"`
	CreatedAt time.Time `db:"created_at"`
	UpdatedAt time.Time `db:"updated_at"`
}

type MetaSchemaRepository

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

func NewMetaSchemaRepository

func NewMetaSchemaRepository(logger log.Logger, dbc *db.Client) *MetaSchemaRepository

func (MetaSchemaRepository) Create

func (MetaSchemaRepository) Delete

func (m MetaSchemaRepository) Delete(ctx context.Context, id string) (string, error)

func (MetaSchemaRepository) Get

func (MetaSchemaRepository) List

func (MetaSchemaRepository) MigrateDefaults

func (m MetaSchemaRepository) MigrateDefaults(ctx context.Context) error

add default schemas to db once during database migration

func (MetaSchemaRepository) Update

type Namespace

type Namespace struct {
	ID        string       `db:"id"`
	Name      string       `db:"name"`
	Metadata  []byte       `db:"metadata"`
	CreatedAt time.Time    `db:"created_at"`
	UpdatedAt time.Time    `db:"updated_at"`
	DeletedAt sql.NullTime `db:"deleted_at"`
}

type NamespaceRepository

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

func NewNamespaceRepository

func NewNamespaceRepository(dbc *db.Client) *NamespaceRepository

func (NamespaceRepository) Get

func (NamespaceRepository) List

func (NamespaceRepository) Update

func (NamespaceRepository) Upsert

Upsert inserts a new namespace if it doesn't exist. If it does, update the details and return no error

type Organization

type Organization struct {
	ID        string         `db:"id"`
	Name      string         `db:"name"`
	Title     sql.NullString `db:"title"`
	Avatar    sql.NullString `db:"avatar"`
	Metadata  []byte         `db:"metadata"`
	State     sql.NullString `db:"state"`
	CreatedAt time.Time      `db:"created_at"`
	UpdatedAt time.Time      `db:"updated_at"`
	DeletedAt sql.NullTime   `db:"deleted_at"`
}

type OrganizationRepository

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

func NewOrganizationRepository

func NewOrganizationRepository(dbc *db.Client) *OrganizationRepository

func (OrganizationRepository) Create

func (OrganizationRepository) Delete

func (OrganizationRepository) GetByID

func (OrganizationRepository) GetByIDs

func (OrganizationRepository) GetByName

func (OrganizationRepository) List

func (OrganizationRepository) SetState

func (OrganizationRepository) UpdateByID

func (OrganizationRepository) UpdateByName

type Permission

type Permission struct {
	ID          string    `db:"id"`
	Name        string    `db:"name"`
	Slug        string    `db:"slug"`
	Namespace   Namespace `db:"namespace"`
	NamespaceID string    `db:"namespace_name"`
	Metadata    []byte    `db:"metadata"`
	CreatedAt   time.Time `db:"created_at"`
	UpdatedAt   time.Time `db:"updated_at"`
}

type PermissionRepository

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

func NewPermissionRepository

func NewPermissionRepository(dbc *db.Client) *PermissionRepository

func (PermissionRepository) Delete

func (r PermissionRepository) Delete(ctx context.Context, id string) error

func (PermissionRepository) Get

func (PermissionRepository) GetBySlug

func (PermissionRepository) List

func (PermissionRepository) Update

func (PermissionRepository) Upsert

type Policy

type Policy struct {
	ID            string `db:"id"`
	Role          Role
	RoleID        string    `db:"role_id"`
	ResourceID    string    `db:"resource_id"`
	ResourceType  string    `db:"resource_type"`
	PrincipalID   string    `db:"principal_id"`
	PrincipalType string    `db:"principal_type"`
	Metadata      []byte    `db:"metadata"`
	CreatedAt     time.Time `db:"created_at"`
	UpdatedAt     time.Time `db:"updated_at"`
}

type PolicyCols

type PolicyCols struct {
	ID            string    `db:"id"`
	RoleID        string    `db:"role_id"`
	ResourceType  string    `db:"resource_type"`
	ResourceID    string    `db:"resource_id"`
	PrincipalID   string    `db:"principal_id"`
	PrincipalType string    `db:"principal_type"`
	Metadata      []byte    `db:"metadata"`
	CreatedAt     time.Time `db:"created_at"`
	UpdatedAt     time.Time `db:"updated_at"`
}

type PolicyRepository

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

func NewPolicyRepository

func NewPolicyRepository(dbc *db.Client) *PolicyRepository

func (PolicyRepository) Delete

func (r PolicyRepository) Delete(ctx context.Context, id string) error

func (PolicyRepository) Get

func (PolicyRepository) List

func (PolicyRepository) Update

func (r PolicyRepository) Update(ctx context.Context, toUpdate policy.Policy) (string, error)

func (PolicyRepository) Upsert

type Preference added in v0.7.3

type Preference struct {
	ID           uuid.UUID `db:"id"`
	Name         string    `db:"name"`
	Value        string    `db:"value"`
	ResourceType string    `db:"resource_type"`
	ResourceID   string    `db:"resource_id"`
	CreatedAt    time.Time `db:"created_at"`
	UpdatedAt    time.Time `db:"updated_at"`
}

type PreferenceRepository added in v0.7.3

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

func NewPreferenceRepository added in v0.7.3

func NewPreferenceRepository(dbc *db.Client) *PreferenceRepository

func (*PreferenceRepository) Get added in v0.7.3

func (*PreferenceRepository) List added in v0.7.3

func (*PreferenceRepository) Set added in v0.7.3

type Project

type Project struct {
	ID        string         `db:"id"`
	Name      string         `db:"name"`
	Title     sql.NullString `db:"title"`
	OrgID     string         `db:"org_id"`
	Metadata  []byte         `db:"metadata"`
	State     sql.NullString `db:"state"`
	CreatedAt time.Time      `db:"created_at"`
	UpdatedAt time.Time      `db:"updated_at"`
	DeletedAt sql.NullTime   `db:"deleted_at"`
}

type ProjectRepository

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

func NewProjectRepository

func NewProjectRepository(dbc *db.Client) *ProjectRepository

func (ProjectRepository) Create

func (ProjectRepository) Delete

func (r ProjectRepository) Delete(ctx context.Context, id string) error

func (ProjectRepository) GetByID

func (ProjectRepository) GetByIDs

func (r ProjectRepository) GetByIDs(ctx context.Context, ids []string, flt project.Filter) ([]project.Project, error)

func (ProjectRepository) GetByName

func (r ProjectRepository) GetByName(ctx context.Context, name string) (project.Project, error)

func (ProjectRepository) List

func (ProjectRepository) SetState

func (r ProjectRepository) SetState(ctx context.Context, id string, state project.State) error

func (ProjectRepository) UpdateByID

func (ProjectRepository) UpdateByName

func (r ProjectRepository) UpdateByName(ctx context.Context, prj project.Project) (project.Project, error)

type Relation

type Relation struct {
	ID                   string         `db:"id"`
	SubjectNamespaceID   string         `db:"subject_namespace_name"`
	SubjectNamespace     Namespace      `db:"subject_namespace"`
	SubjectID            string         `db:"subject_id"`
	SubjectSubRelationID sql.NullString `db:"subject_subrelation_name"`
	ObjectNamespaceID    string         `db:"object_namespace_name"`
	ObjectNamespace      Namespace      `db:"object_namespace"`
	ObjectID             string         `db:"object_id"`
	RelationName         string         `db:"relation_name"`
	CreatedAt            time.Time      `db:"created_at"`
	UpdatedAt            time.Time      `db:"updated_at"`
	DeletedAt            sql.NullTime   `db:"deleted_at"`
}

type RelationRepository

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

func NewRelationRepository

func NewRelationRepository(dbc *db.Client) *RelationRepository

func (RelationRepository) DeleteByID

func (r RelationRepository) DeleteByID(ctx context.Context, id string) error

func (RelationRepository) Get

func (RelationRepository) GetByFields

func (RelationRepository) List

func (RelationRepository) ListByFields

func (r RelationRepository) ListByFields(ctx context.Context, rel relation.Relation) ([]relation.Relation, error)

func (RelationRepository) Upsert

func (r RelationRepository) Upsert(ctx context.Context, relationToCreate relation.Relation) (relation.Relation, error)

type Resource

type Resource struct {
	ID            string         `db:"id"`
	URN           string         `db:"urn"`
	Name          string         `db:"name"`
	Title         string         `db:"title"`
	ProjectID     string         `db:"project_id"`
	Project       Project        `db:"project"`
	Metadata      []byte         `db:"metadata"`
	NamespaceID   string         `db:"namespace_name"`
	Namespace     Namespace      `db:"namespace"`
	PrincipalID   sql.NullString `db:"principal_id"`
	PrincipalType sql.NullString `db:"principal_type"`
	CreatedAt     time.Time      `db:"created_at"`
	UpdatedAt     time.Time      `db:"updated_at"`
	DeletedAt     sql.NullTime   `db:"deleted_at"`
}

type ResourceCols

type ResourceCols struct {
	ID            string         `db:"id"`
	URN           string         `db:"urn"`
	Title         string         `db:"title"`
	Name          string         `db:"name"`
	ProjectID     string         `db:"project_id"`
	NamespaceID   string         `db:"namespace_name"`
	PrincipalID   sql.NullString `db:"principal_id"`
	PrincipalType sql.NullString `db:"principal_type"`
	Metadata      []byte         `db:"metadata"`
	CreatedAt     time.Time      `db:"created_at"`
	UpdatedAt     time.Time      `db:"updated_at"`
}

type ResourceRepository

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

func NewResourceRepository

func NewResourceRepository(dbc *db.Client) *ResourceRepository

func (ResourceRepository) Create

func (ResourceRepository) Delete

func (r ResourceRepository) Delete(ctx context.Context, id string) error

func (ResourceRepository) GetByID

func (ResourceRepository) GetByURN

func (ResourceRepository) List

func (ResourceRepository) Update

type Role

type Role struct {
	ID          string         `db:"id"`
	OrgID       string         `db:"org_id"`
	Name        string         `db:"name"`
	Title       sql.NullString `db:"title"`
	Permissions []byte         `db:"permissions"`
	State       string         `db:"state"`
	Scopes      pq.StringArray `db:"scopes"`
	Metadata    []byte         `db:"metadata"`
	CreatedAt   time.Time      `db:"created_at"`
	UpdatedAt   time.Time      `db:"updated_at"`
	DeletedAt   sql.NullTime   `db:"deleted_at"`
}

type RoleRepository

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

func NewRoleRepository

func NewRoleRepository(dbc *db.Client) *RoleRepository

func (RoleRepository) Delete

func (r RoleRepository) Delete(ctx context.Context, id string) error

func (RoleRepository) Get

func (r RoleRepository) Get(ctx context.Context, id string) (role.Role, error)

func (RoleRepository) GetByName

func (r RoleRepository) GetByName(ctx context.Context, orgID, name string) (role.Role, error)

func (RoleRepository) List

func (r RoleRepository) List(ctx context.Context, flt role.Filter) ([]role.Role, error)

func (RoleRepository) Update

func (r RoleRepository) Update(ctx context.Context, rl role.Role) (role.Role, error)

func (RoleRepository) Upsert

func (r RoleRepository) Upsert(ctx context.Context, rl role.Role) (role.Role, error)

type ServiceUser

type ServiceUser struct {
	ID        string         `db:"id"`
	OrgID     string         `db:"org_id"`
	Title     sql.NullString `db:"title"`
	State     sql.NullString `db:"state"`
	Metadata  []byte         `db:"metadata"`
	CreatedAt time.Time      `db:"created_at"`
	UpdatedAt time.Time      `db:"updated_at"`
	DeletedAt sql.NullTime   `db:"deleted_at"`
}

type ServiceUserCredential

type ServiceUserCredential struct {
	ID            string         `db:"id"`
	ServiceUserID string         `db:"serviceuser_id"`
	SecretHash    sql.NullString `db:"secret_hash"`
	PublicKey     []byte         `db:"public_key"`
	Title         sql.NullString `db:"title"`
	Metadata      []byte         `db:"metadata"`
	CreatedAt     time.Time      `db:"created_at"`
	UpdatedAt     time.Time      `db:"updated_at"`
	DeletedAt     sql.NullTime   `db:"deleted_at"`
}

type ServiceUserCredentialRepository

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

func NewServiceUserCredentialRepository

func NewServiceUserCredentialRepository(dbc *db.Client) *ServiceUserCredentialRepository

func (ServiceUserCredentialRepository) Create

func (ServiceUserCredentialRepository) Delete

func (ServiceUserCredentialRepository) Get

func (ServiceUserCredentialRepository) List

type ServiceUserRepository

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

func NewServiceUserRepository

func NewServiceUserRepository(dbc *db.Client) *ServiceUserRepository

func (ServiceUserRepository) Create

func (ServiceUserRepository) Delete

func (s ServiceUserRepository) Delete(ctx context.Context, id string) error

func (ServiceUserRepository) GetByID

func (ServiceUserRepository) GetByIDs

GetByIDs returns a list of service users by their IDs.

func (ServiceUserRepository) List

type Session

type Session struct {
	ID              uuid.UUID `db:"id"`
	UserID          uuid.UUID `db:"user_id"`
	AuthenticatedAt time.Time `db:"authenticated_at"`
	ExpiresAt       time.Time `db:"expires_at"`
	Metadata        []byte    `db:"metadata"`
	CreatedAt       time.Time `db:"created_at"`
}

type SessionRepository

type SessionRepository struct {
	Now func() time.Time
	// contains filtered or unexported fields
}

func NewSessionRepository

func NewSessionRepository(logger log.Logger, dbc *db.Client) *SessionRepository

func (*SessionRepository) Delete

func (s *SessionRepository) Delete(ctx context.Context, id uuid.UUID) error

func (*SessionRepository) DeleteExpiredSessions

func (s *SessionRepository) DeleteExpiredSessions(ctx context.Context) error

func (*SessionRepository) Get

func (*SessionRepository) Set

func (*SessionRepository) UpdateValidity

func (s *SessionRepository) UpdateValidity(ctx context.Context, id uuid.UUID, validity time.Duration) error

type User

type User struct {
	ID        string         `db:"id"`
	Name      string         `db:"name"`
	Email     string         `db:"email"`
	Title     sql.NullString `db:"title"`
	Avatar    sql.NullString `db:"avatar"`
	Metadata  []byte         `db:"metadata"`
	State     sql.NullString `db:"state"`
	CreatedAt time.Time      `db:"created_at"`
	UpdatedAt time.Time      `db:"updated_at"`
	DeletedAt sql.NullTime   `db:"deleted_at"`
}

type UserRepository

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

func NewUserRepository

func NewUserRepository(dbc *db.Client) *UserRepository

func (UserRepository) Create

func (r UserRepository) Create(ctx context.Context, usr user.User) (user.User, error)

func (UserRepository) Delete

func (r UserRepository) Delete(ctx context.Context, id string) error

func (UserRepository) GetByEmail

func (r UserRepository) GetByEmail(ctx context.Context, email string) (user.User, error)

func (UserRepository) GetByID

func (r UserRepository) GetByID(ctx context.Context, id string) (user.User, error)

func (UserRepository) GetByIDs

func (r UserRepository) GetByIDs(ctx context.Context, userIDs []string) ([]user.User, error)

func (UserRepository) GetByName

func (r UserRepository) GetByName(ctx context.Context, name string) (user.User, error)

func (UserRepository) List

func (r UserRepository) List(ctx context.Context, flt user.Filter) ([]user.User, error)

func (UserRepository) SetState

func (r UserRepository) SetState(ctx context.Context, id string, state user.State) error

func (UserRepository) UpdateByEmail

func (r UserRepository) UpdateByEmail(ctx context.Context, usr user.User) (user.User, error)

func (UserRepository) UpdateByID

func (r UserRepository) UpdateByID(ctx context.Context, usr user.User) (user.User, error)

func (UserRepository) UpdateByName

func (r UserRepository) UpdateByName(ctx context.Context, usr user.User) (user.User, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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