database

package
v0.0.0-...-db8f46d Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTokenExpiration = time.Hour * 24

Variables

View Source
var ErrConflict = &dbError{message: "conflict"}

Functions

func PointerToUint64

func PointerToUint64(x uint64) *uint64

Types

type AdminMessage

type AdminMessage struct {
	OrganizationID uuid.UUID
	LoggedAt       time.Time
	Severity       AdminMessageSeverity
	Verbosity      int
	Nonce          []byte
	Data           []byte
}

type AdminMessageData

type AdminMessageData struct {
	Summary   string
	Message   string
	ExtraData map[string]interface{}
}

type AdminMessageSeverity

type AdminMessageSeverity string
const (
	AdminMessageSeverityError AdminMessageSeverity = "error"
	AdminMessageSeverityInfo  AdminMessageSeverity = "info"
)

type Device

type Device struct {
	ID             uuid.UUID
	OrganizationID uuid.UUID
	Name           string
	LastHeartbeat  sql.NullTime
}

type GetAdminMessagesOpts

type GetAdminMessagesOpts struct {
	OrganizationID uuid.UUID
	Limit          *uint64
	FromTimestamp  *time.Time
}

type GetDevicesOpts

type GetDevicesOpts struct {
	OrganizationID uuid.UUID
	Limit          *uint64
	Offset         *uint64
	NameSearch     *string
}

type GetNetworkingServicesOpts

type GetNetworkingServicesOpts struct {
	OrganizationID uuid.UUID
	Limit          *uint64
	Offset         *uint64
}

type GetStudentsOpts

type GetStudentsOpts struct {
	OrganizationID uuid.UUID
	Limit          *uint64
	Offset         *uint64
}

type NetworkingService

type NetworkingService struct {
	ID             uuid.UUID
	OrganizationID uuid.UUID
	Name           string
}

type OAuth2State

type OAuth2State struct {
	State       uuid.UUID
	Issuer      string
	RedirectURL string
	CreatedAt   time.Time
	ExpiresAt   time.Time
}

type OIDCFederation

type OIDCFederation struct {
	OIDCIssuer   string
	OIDCSubject  string
	OIDCAudience string
	UserID       uuid.UUID
}

type Organization

type Organization struct {
	ID                 uuid.UUID
	Name               string
	ZermeloInstitution string
}

type PaginatedDevices

type PaginatedDevices struct {
	Pagination
	Devices []Device
}

type PaginatedNetworkingServices

type PaginatedNetworkingServices struct {
	Pagination
	NetworkingServices []NetworkingService
}

type PaginatedStudents

type PaginatedStudents struct {
	Pagination
	Students []Student
}

type Pagination

type Pagination struct {
	Offset, Limit, Total uint64
}

type Student

type Student struct {
	ID                uuid.UUID
	OrganizationID    uuid.UUID
	ZermeloUser       sql.NullString
	HasCardAssociated bool
}

type User

type User struct {
	ID             uuid.UUID
	Name           string
	Email          string
	OrganizationID uuid.UUID
}

type Wrapper

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

Wrapper wraps the PostgreSQL database.

func New

func New(url string, log logr.Logger, opts ...WrapperOpt) (*Wrapper, error)

New opens the database and creates a new database wrapper.

func (*Wrapper) AreDevicesInOrganization

func (w *Wrapper) AreDevicesInOrganization(ctx context.Context,
	organizationID uuid.UUID,
	ids ...uuid.UUID,
) (bool, error)

func (*Wrapper) AreStudentsInOrganization

func (w *Wrapper) AreStudentsInOrganization(ctx context.Context,
	organizationID uuid.UUID,
	ids ...uuid.UUID,
) (bool, error)

func (*Wrapper) Close

func (w *Wrapper) Close() error

func (*Wrapper) CreateAdminMessage

func (w *Wrapper) CreateAdminMessage(ctx context.Context, msg AdminMessage) error

func (*Wrapper) CreateDevice

func (w *Wrapper) CreateDevice(ctx context.Context,
	organizationID uuid.UUID,
	name string,
) (Device, uuid.UUID, error)

func (*Wrapper) CreateDeviceRegistrationToken

func (w *Wrapper) CreateDeviceRegistrationToken(ctx context.Context, organizationID uuid.UUID) (uuid.UUID, error)

func (*Wrapper) CreateDeviceToken

func (w *Wrapper) CreateDeviceToken(ctx context.Context, deviceID uuid.UUID) (uuid.UUID, error)

func (*Wrapper) CreateNetworkingService

func (w *Wrapper) CreateNetworkingService(
	ctx context.Context,
	organizationID uuid.UUID,
	name string,
) (NetworkingService, error)

func (*Wrapper) CreateNewUser

func (w *Wrapper) CreateNewUser(ctx context.Context, name, email string, federation OIDCFederation) (User, error)

func (*Wrapper) CreateOAuth2State

func (w *Wrapper) CreateOAuth2State(ctx context.Context, issuer, redirectURL string) (OAuth2State, error)

func (*Wrapper) CreateOIDCFederation

func (w *Wrapper) CreateOIDCFederation(ctx context.Context, federation OIDCFederation) (OIDCFederation, error)

func (*Wrapper) CreateOrganization

func (w *Wrapper) CreateOrganization(ctx context.Context,
	name string,
	zermeloInstitution string,
) (Organization, error)

func (*Wrapper) CreateStudent

func (w *Wrapper) CreateStudent(ctx context.Context, s Student) (Student, error)

func (*Wrapper) CreateUser

func (w *Wrapper) CreateUser(ctx context.Context, name, email string, organizationID uuid.UUID) (User, error)

func (*Wrapper) CreateUserToken

func (w *Wrapper) CreateUserToken(ctx context.Context, userID uuid.UUID) (uuid.UUID, error)

func (*Wrapper) DeleteDevice

func (w *Wrapper) DeleteDevice(ctx context.Context, id uuid.UUID) error

func (*Wrapper) DeleteDevices

func (w *Wrapper) DeleteDevices(ctx context.Context, ids []uuid.UUID) error

func (*Wrapper) DeleteNetworkingService

func (w *Wrapper) DeleteNetworkingService(ctx context.Context, id uuid.UUID) error

func (*Wrapper) DeleteOldDeviceTokens

func (w *Wrapper) DeleteOldDeviceTokens(ctx context.Context) error

func (*Wrapper) DeleteOldOAuth2States

func (w *Wrapper) DeleteOldOAuth2States(ctx context.Context) error

func (*Wrapper) DeleteOldUserTokens

func (w *Wrapper) DeleteOldUserTokens(ctx context.Context) error

func (*Wrapper) DeleteOrganization

func (w *Wrapper) DeleteOrganization(ctx context.Context, id uuid.UUID) error

func (*Wrapper) DeleteStudent

func (w *Wrapper) DeleteStudent(ctx context.Context, id uuid.UUID) error

func (*Wrapper) DeleteStudentCards

func (w *Wrapper) DeleteStudentCards(ctx context.Context, studentID uuid.UUID) error

func (*Wrapper) DeleteStudents

func (w *Wrapper) DeleteStudents(ctx context.Context, ids []uuid.UUID) error

func (*Wrapper) GetAdminMessage

func (w *Wrapper) GetAdminMessage(ctx context.Context, tm time.Time, organizationID uuid.UUID) (AdminMessage, error)

func (*Wrapper) GetAdminMessages

func (w *Wrapper) GetAdminMessages(ctx context.Context, opts GetAdminMessagesOpts) ([]AdminMessage, error)

func (*Wrapper) GetAllNetworkingServices

func (w *Wrapper) GetAllNetworkingServices(ctx context.Context, organizationID uuid.UUID) ([]NetworkingService, error)

func (*Wrapper) GetDevice

func (w *Wrapper) GetDevice(ctx context.Context, id uuid.UUID) (Device, error)

func (*Wrapper) GetDeviceByToken

func (w *Wrapper) GetDeviceByToken(ctx context.Context, token uuid.UUID) (Device, error)

func (*Wrapper) GetDevices

func (w *Wrapper) GetDevices(ctx context.Context, opts GetDevicesOpts) (PaginatedDevices, error)

func (*Wrapper) GetNetworkingService

func (w *Wrapper) GetNetworkingService(ctx context.Context, id uuid.UUID) (NetworkingService, error)

func (*Wrapper) GetNetworkingServices

func (w *Wrapper) GetNetworkingServices(ctx context.Context, opts GetNetworkingServicesOpts) (PaginatedNetworkingServices, error)

func (*Wrapper) GetOAuth2State

func (w *Wrapper) GetOAuth2State(ctx context.Context, state uuid.UUID) (OAuth2State, error)

func (*Wrapper) GetOrganization

func (w *Wrapper) GetOrganization(ctx context.Context, id uuid.UUID) (Organization, error)

func (*Wrapper) GetOrganizationByDeviceRegistrationToken

func (w *Wrapper) GetOrganizationByDeviceRegistrationToken(ctx context.Context, token uuid.UUID) (Organization, error)

func (*Wrapper) GetStudent

func (w *Wrapper) GetStudent(ctx context.Context, id uuid.UUID) (Student, error)

func (*Wrapper) GetStudentByCard

func (w *Wrapper) GetStudentByCard(ctx context.Context, uid []byte, organizationID uuid.UUID) (Student, error)

func (*Wrapper) GetStudents

func (w *Wrapper) GetStudents(ctx context.Context, opts GetStudentsOpts) (PaginatedStudents, error)

func (*Wrapper) GetUserByEmail

func (w *Wrapper) GetUserByEmail(ctx context.Context, email string) (User, error)

func (*Wrapper) GetUserByID

func (w *Wrapper) GetUserByID(ctx context.Context, id uuid.UUID) (User, error)

func (*Wrapper) GetUserByOIDCFederation

func (w *Wrapper) GetUserByOIDCFederation(ctx context.Context, federation OIDCFederation) (User, error)

func (*Wrapper) GetUserByToken

func (w *Wrapper) GetUserByToken(ctx context.Context, token uuid.UUID) (User, error)

func (*Wrapper) ReplaceDevice

func (w *Wrapper) ReplaceDevice(ctx context.Context, dev Device) error

func (*Wrapper) ReplaceDeviceHeartbeat

func (w *Wrapper) ReplaceDeviceHeartbeat(ctx context.Context, id uuid.UUID) error

func (*Wrapper) ReplaceNetworkingService

func (w *Wrapper) ReplaceNetworkingService(ctx context.Context, s NetworkingService) error

func (*Wrapper) ReplaceOrganization

func (w *Wrapper) ReplaceOrganization(ctx context.Context, org Organization) error

func (*Wrapper) ReplaceStudent

func (w *Wrapper) ReplaceStudent(ctx context.Context, s Student) error

func (*Wrapper) ReplaceStudentCard

func (w *Wrapper) ReplaceStudentCard(ctx context.Context, organizationID, studentID uuid.UUID, cardUID []byte) error

func (*Wrapper) ReplaceUser

func (w *Wrapper) ReplaceUser(ctx context.Context, user User) error

func (*Wrapper) WalkDevices

func (w *Wrapper) WalkDevices(ctx context.Context, organizationID uuid.UUID, f func(dev Device) bool) error

type WrapperOpt

type WrapperOpt func(w wrapperOpts) wrapperOpts

func WithJanitor

func WithJanitor(on bool) WrapperOpt

func WithMigrationsURL

func WithMigrationsURL(url string) WrapperOpt

Jump to

Keyboard shortcuts

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