store

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: AGPL-3.0, BSD-2-Clause, ISC Imports: 16 Imported by: 0

Documentation

Overview

Let consumer of this package, e.g. the API, define some types that contain both the description and the contents of the entities, if required - not much point doing it here because the openAPI generator will create its own types anyway.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckManifest

func CheckManifest(m Manifest) (error, []string)

CheckManifest checks for internal consistency, throwing an error if there are any unresolved references by name

func HumaniseDuration

func HumaniseDuration(t time.Duration) string

HumaniseDuration returns a concise human readable string representing the duration

Types

type Activity

type Activity struct {
	BookingID   string            `json:"booking_id" yaml:"booking_id"`
	Description Description       `json:"description" yaml:"description"`
	ConfigURL   string            `json:"config_url,omitempty"  yaml:"config_url,omitempty"`
	Streams     map[string]Stream `json:"streams" yaml:"streams"`
	UIs         []UIDescribed     `json:"ui" yaml:"ui"`
	NotBefore   time.Time         `json:"nbf" yaml:"nbf"`
	ExpiresAt   time.Time         `json:"exp" yaml:"exp"`
}

Activity represents connection details for a live booking

type Booking

type Booking struct {
	// Cancelled indicates if booking cancelled
	Cancelled bool `json:"cancelled" yaml:"cancelled"`
	// CancelledAt represents when the booking was cancelled
	CancelledAt time.Time `json:"cancelled_at" yaml:"cancelled_at"`
	// CancelledBy indicates who cancelled e.g. auto-grace-period, admin or user
	CancelledBy string `json:"cancelled_by" yaml:"cancelled_by"`
	// Group
	Group string `json:"group" yaml:"group"`
	// booking unique reference
	Name string `json:"name" yaml:"name"`
	// reference to policy it was booked under
	Policy string `json:"policy" yaml:"policy"`
	// slot name
	Slot    string `json:"slot" yaml:"slot"`
	Started bool   `json:"started" yaml:"started"`
	//StartedAt is for reporting purposes, do not use to calculate usage
	StartedAt string `json:"started_at" yaml:"started_at"`
	//when the resource was unavailable
	Unfulfilled bool `json:"unfulfilled" yaml:"unfulfilled"`
	// User represents user's name
	User string `json:"user" yaml:"user"`

	// UsageCharged represents how much usage was charged
	// This is updated on cancellation and is for convenience of admin looking at exports/reports
	// Replace(Old)Bookings should calculate the usage to be charged based on the policy
	// That avoids those editing bookings to upload from performing this calculation manually
	UsageCharged time.Duration `json:"usage_charged" yaml:"usage_charged"`

	When interval.Interval `json:"when" yaml:"when"`
}

Booking represents a promise to access an equipment that provided by the pool referenced in the resource of the slot

type Description

type Description struct {
	Name    string `json:"name" yaml:"name"`
	Type    string `json:"type" yaml:"type"`
	Short   string `json:"short" yaml:"short"`
	Long    string `json:"long,omitempty" yaml:"long,omitempty"`
	Further string `json:"further,omitempty" yaml:"further,omitempty"`
	Thumb   string `json:"thumb,omitempty" yaml:"thumb,omitempty"`
	Image   string `json:"image,omitempty" yaml:"image,omitempty"`
}

Description represents information to display to a user about an entity

type DisplayGuide

type DisplayGuide struct {
	BookAhead time.Duration `json:"book_ahead" yaml:"book_ahead"`
	Duration  time.Duration `json:"duration" yaml:"duration"`
	Label     string        `json:"label" yaml:"label"`
	MaxSlots  int           `json:"max_slots" yaml:"max_slots"`
}

DisplayGuide represents guidance to the booking app on what length slots to offer, how many, and how far in the future. This is to allow course staff to influence the offerings to students in a way that might better suit their teaching views. remember to update UnmarshalJSON if adding fields

func (*DisplayGuide) UnmarshalJSON

func (d *DisplayGuide) UnmarshalJSON(data []byte) (err error)

type Group added in v0.3.0

type Group struct {
	Description string   `json:"description" yaml:"description"`
	Policies    []string `json:"policies" yaml:"policies"`
}

Group represents a list of policies for ease of sharing multiple policies with users and being able to change the policies that are supplied to a user without having to update all the links the user has (important if user is a course organiser on a large course!)

type GroupDescribed added in v0.3.0

type GroupDescribed struct {
	Description Description `json:"description"  yaml:"description"`
	// keep track of the description reference, needed for manifest export
	DescriptionReference string   `json:"-" yaml:"-"`
	Policies             []string `json:"policies" yaml:"policies"`
}

GroupDescribed includes the description to save some overhead, since it will always be requested by the user with the description included.

type Manifest

type Manifest struct {
	Descriptions  map[string]Description  `json:"descriptions" yaml:"descriptions"`
	DisplayGuides map[string]DisplayGuide `json:"display_guides" yaml:"display_guides"`
	Groups        map[string]Group        `json:"groups" yaml:"groups"`
	Policies      map[string]Policy       `json:"policies" yaml:"policies"`
	Resources     map[string]Resource     `json:"resources" yaml:"resources"`
	Slots         map[string]Slot         `json:"slots" yaml:"slots"`
	Streams       map[string]Stream       `json:"streams" yaml:"streams"`
	UIs           map[string]UI           `json:"uis" yaml:"uis"`
	UISets        map[string]UISet        `json:"ui_sets" yaml:"ui_sets"`
	Windows       map[string]Window       `json:"windows" yaml:"windows"`
}

Manifest represents all the available equipment and how to access it Slots are the primary entities, so reference checking starts with them

type Policy

type Policy struct {
	// AllowStartInPastWithin gives some latitude to accept a booking starting now that gets delayed on the way to the server. A bookng at minimum acceptable duration will be reduced to as much as this duration, so that there is no need to include logic about how to handle a shift in the end time. Typically values might be 10s or 1m.
	AllowStartInPastWithin time.Duration `json:"allow_start_in_past_within"  yaml:"allow_start_in_past_within"`
	//booking must finish within the book_ahead duration, if enforced
	BookAhead     time.Duration `json:"book_ahead"  yaml:"book_ahead"`
	Description   string        `json:"description"  yaml:"description"`
	DisplayGuides []string      `json:"display_guides"  yaml:"display_guides"`
	// In the manifest, we will refer to display guides by reference
	// For users, we want to send policy descriptions that are complete
	// so store a local copy of the displayguides to ease the process of fulfilling GET policy_name requests
	// but don't include this local copy of information in any manifests
	DisplayGuidesMap map[string]DisplayGuide `json:"-"  yaml:"-"` //local copy so that exported policies are complete but exclude from json/yaml so not duplicated in manifests
	// EnforceAllowStartInPast lets a request starting before now (e.g. due to delayed communication of request) be accepted if other policies are still met.
	EnforceAllowStartInPast bool `json:"enforce_allow_start_in_past"  yaml:"enforce_allow_start_in_past"`
	EnforceBookAhead        bool `json:"enforce_book_ahead"  yaml:"enforce_book_ahead"`
	EnforceGracePeriod      bool `json:"enforce_grace_period"  yaml:"enforce_grace_period"`
	EnforceMaxBookings      bool `json:"enforce_max_bookings"  yaml:"enforce_max_bookings"`
	EnforceMaxDuration      bool `json:"enforce_max_duration"  yaml:"enforce_max_duration"`
	EnforceMinDuration      bool `json:"enforce_min_duration"  yaml:"enforce_min_duration"`
	EnforceMaxUsage         bool `json:"enforce_max_usage"  yaml:"enforce_max_usage"`
	EnforceNextAvailable    bool `json:"enforce_next_available"  yaml:"enforce_next_available"`
	EnforceStartsWithin     bool `json:"enforce_starts_within"  yaml:"enforce_starts_within"`
	//EnforceUnlimitedUsers if true, bookings are not checked, and the token is granted if otherwise within policy. This supports hardware-less simulations to be
	// included without needing to specify multiple slots. We don't set a finite limit here to avoid having to track multiple overlapping bookings when usually simulations
	// run entirely in client-side code - if a simulation has a resource limit e.g. due to using some central heavyweight server to crunch data, then slots should be specified
	// same as for hardware, and this option left as false.
	EnforceUnlimitedUsers bool `json:"enforce_unlimited_users"  yaml:"enforce_unlimited_users"`
	// GracePeriod is how long after When.Start that the booking will be kept
	GracePeriod time.Duration `json:"grace_period" yaml:"grace_period"`
	// GracePenalty represents the time lost to finding a new user after auto-cancellation
	GracePenalty time.Duration `json:"grace_penalty" yaml:"grace_penalty"`
	MaxBookings  int64         `json:"max_bookings"  yaml:"max_bookings"`
	MaxDuration  time.Duration `json:"max_duration"  yaml:"max_duration"`
	MinDuration  time.Duration `json:"min_duration"  yaml:"min_duration"`
	MaxUsage     time.Duration `json:"max_usage"  yaml:"max_usage"`
	// NextAvailable allows for a small gap in bookings to give some flex in case the availability windows are presented with reduced resolution at some point in the system
	// i.e. set to 2min to allow a request that is rounded up to start at the next minute after the last booking ends, instead of expecting ms precision from everyone
	// Leaving this to default to zero requires the booking UI to return the exact figure given in the availability list, which probably works for now but might not later when other developers
	// working on other features maybe don't realise how strict the calculation is without this allowance, or we change the precision somewhere in the system for human-readability and lose the
	// exact value that the system would expect due to loss of precision - resulting in a rejected booking that is otherwise within the spirit of the policy.
	// Also, some use cases might actually let this be say 15min or 30min - we can't predict the use cases, but can expect them to vary within the same booking system,
	// so don't make this a system-wide parameter.
	NextAvailable time.Duration   `json:"next_available"  yaml:"next_available"`
	Slots         []string        `json:"slots" yaml:"slots"`
	SlotMap       map[string]bool `json:"-" yaml:"-"` // internal usage, do not populate from file
	// booking must start within this duration from now, if enforced
	StartsWithin time.Duration `json:"starts_within"  yaml:"starts_within"`
}

Policy represents what a user can book, and any limits on bookings/usage Unmarshaling of time.Duration works in yaml.v3, https://play.golang.org/p/-6y0zq96gVz" remember to update UnmarshalJSON if adding fields

func (*Policy) UnmarshalJSON

func (p *Policy) UnmarshalJSON(data []byte) (err error)

Unmarshallers for structs with durations so that we can handle JSON in our store format during testing which makes it easier to read diffs due to the lack of pointers unlike the swagger models method from https://penkovski.com/post/go-unmarshal-custom-types/

type PolicyStatus

type PolicyStatus struct {
	CurrentBookings int64         `json:"current_bookings"  yaml:"current_bookings"`
	OldBookings     int64         `json:"old_bookings"  yaml:"old_bookings"`
	Usage           time.Duration `json:"usage"  yaml:"usage"`
}

type Resource

type Resource struct {

	// ConfigURL represents a hardware configuration file URL
	// that may be useful to a UI
	ConfigURL string `json:"config_url,omitempty"  yaml:"config_url,omitempty"`

	// Description is a reference to a named description of the resource
	// that will probably only be shown on admin dashboards (not to students)
	Description string `json:"description"  yaml:"description"`

	// Diary is held in memory, not in the manifest, so don't unmarshall it.
	Diary *diary.Diary `json:"-"  yaml:"-"`

	// Streams is a list of stream types used by this resource, e.g. data, video, logging
	// We autogenerate the full stream details needed by the UI  when making a live activity,
	// using a rule to generate the topic and filling in the other details from the stream prototype
	// Streams are required because sims would still use logging, and if not
	// just add a dummy stream called null so that we have a check on streams
	// being included for the main use case.
	Streams []string `json:"streams"  yaml:"streams"`

	Tests []string `json:"tests"  yaml:"tests"`

	//TopicStub is the name that should be used to make the topic <TopicStub>-<for>
	TopicStub string `json:"topic_stub" yaml:"topic_stub"`
}

Resource represents a physical entity that can be booked

type Slot

type Slot struct {
	Description string `json:"description"  yaml:"description"`
	Policy      string `json:"policy"  yaml:"policy"`
	Resource    string `json:"resource"  yaml:"resource"`
	UISet       string `json:"ui_set"  yaml:"ui_set"`
	Window      string `json:"window"  yaml:"window"`
}

use separate description from resource, because UISet All of the strings, except Name, are references to other entries but we can do our own consistency checking rather than having to replace the yaml unmarshal process if we used pointers and big structs as before

type Store

type Store struct {
	*sync.RWMutex `json:"-"`

	// Checker does grace checking on bookings
	Checker *check.Checker

	// Bookings represents all the live bookings, indexed by booking id
	Bookings map[string]*Booking

	// Descriptions represents all the descriptions of various entities, indexed by description name
	Descriptions map[string]Description

	DisableCancelAfterUse bool

	DisplayGuides map[string]DisplayGuide

	// Filters are how the windows are checked, mapped by window name (populated after loading window info from manifest)
	Filters map[string]*filter.Filter

	// Groups represent groups of policies - we bake in the description to reduce overhead on this common operation
	Groups map[string]GroupDescribed

	// GraceRebound represents how long to wait before checking any bookings that were
	// supposed to be checked but the store was locked (see GraceCheck)
	GraceRebound time.Duration

	Locked bool

	// Message represents our message of the day, to send to users (e.g. to explain system is locked)
	Message string

	//useful for admin dashboard - don't need to also parse logs if keep old bookings
	// Old Bookings represents the
	OldBookings map[string]*Booking

	// TimePolicies represents all the TimePolicy(ies) in use
	Policies map[string]Policy

	// Resources represent all the actual physical experiments, indexed by name
	Resources map[string]Resource

	// Slots represent the combinations of virtual equipments and booking policies that apply to them
	Slots map[string]Slot

	Streams map[string]Stream

	// UIs represents all the user interfaces that are available
	UIs map[string]UIDescribed

	// UISets represents the lists of user interfaces for particular slots
	UISets map[string]UISet

	// Users maps all users.
	Users map[string]*User

	// Window represents allowed and denied time periods for slots
	Windows map[string]Window
	// contains filtered or unexported fields
}

Store represents entities required to make bookings, including resources, slots, descriptions, users, policies, and bookings any maps to values are data that are not mutated except when the manifest is replaced so do not need to be maps to pointers

func New

func New() *Store

New returns an empty store

func (*Store) AddGroupForUser added in v0.3.0

func (s *Store) AddGroupForUser(user, group string) error

AddGroupForUser adds a group for a user so they can book with it in future without having to have the access code to hand TODO needs a corresponding DeleteGroupFor

func (*Store) CancelBooking

func (s *Store) CancelBooking(booking Booking, cancelledBy string) error

CancelBooking cancels a booking or returns an error if not found Takes a lock - for external usage

func (*Store) DeleteGroupFor added in v0.3.0

func (s *Store) DeleteGroupFor(user, group string) error

DeleteGroupFor removes the group from the user's list of allowed groups, and deletes any current bookings they have policies that are only accessible to the user via that group

func (*Store) ExportBookings

func (s *Store) ExportBookings() map[string]Booking

ExportBookings returns a map of all current/future bookings

func (*Store) ExportManifest

func (s *Store) ExportManifest() Manifest

ExportManifest returns the manifest from the store

func (*Store) ExportOldBookings

func (s *Store) ExportOldBookings() map[string]Booking

ExportOldBookings returns a map by name of old bookings

func (*Store) ExportUsers

func (s *Store) ExportUsers() map[string]UserExternal

ExportUsers returns a map of users, listing the names of bookings, old bookings, policies and their usage to date by policy name

func (*Store) GenerateUniqueUser

func (s *Store) GenerateUniqueUser() string

func (*Store) GetActivity

func (s *Store) GetActivity(booking Booking) (Activity, error)

GetActivity returns an activity associated with a booking, or an error if the booking is invalid in some way

func (*Store) GetAvailability

func (s *Store) GetAvailability(slot string) ([]interval.Interval, error)

GetAvailability returns a list of intervals for which a given slot is available under a given policy, or an error if the slot or policy is not found. The policy contains aspects such as look-ahead which may limit the window of availability.

func (*Store) GetBooking

func (s *Store) GetBooking(booking string) (Booking, error)

GetBooking returns a booking given a bookingname

func (*Store) GetBookingsFor

func (s *Store) GetBookingsFor(user string) ([]Booking, error)

GetBookingsFor returns a slice of all the current bookings for the given user don't use mutex because called from functions that do

func (*Store) GetDescription

func (s *Store) GetDescription(name string) (Description, error)

GetDescription returns a description if found

func (*Store) GetDisplayGuide

func (s *Store) GetDisplayGuide(name string) (DisplayGuide, error)

GetDisplayGuide returns a diplay guide if found

func (*Store) GetGroup added in v0.3.0

func (s *Store) GetGroup(name string) (GroupDescribed, error)

GetGroup returns a group if found do not use internally - it takes the lock

func (*Store) GetGroupsFor added in v0.3.0

func (s *Store) GetGroupsFor(user string) ([]string, error)

GetGroupsFor returns a list of groups that a user has access to

func (*Store) GetOldBookingsFor

func (s *Store) GetOldBookingsFor(user string) ([]Booking, error)

GetOldBookingsFor returns a slice of all the old bookings for the given user don't use mutex because called from functions that do

func (*Store) GetPolicy

func (s *Store) GetPolicy(name string) (Policy, error)

GetPolicy returns a policy if found this is not used internally

func (*Store) GetPolicyStatusFor

func (s *Store) GetPolicyStatusFor(user, policy string) (PolicyStatus, error)

GetPolicyStatusFor returns usage, and counts of current and old bookings Needs a write lock because it prunes

func (*Store) GetResourceIsAvailable added in v0.3.10

func (s *Store) GetResourceIsAvailable(resource string) (bool, string, error)

GetResourceIsAvailable checks the underlying resource's availability Use this version when calling externally

func (*Store) GetResources added in v0.3.10

func (s *Store) GetResources() map[string]Resource

ExportManifest returns the manifest from the store

func (*Store) GetSlot added in v0.3.4

func (s *Store) GetSlot(name string) (Slot, error)

GetSlot returns a slot if found

func (*Store) GetSlotIsAvailable

func (s *Store) GetSlotIsAvailable(slot string) (bool, string, error)

GetSlotIsAvailable checks the underlying resource's availability Use this version when calling externally

func (*Store) GetStoreStatusAdmin

func (s *Store) GetStoreStatusAdmin() StoreStatusAdmin

GetStoreStatusAdmin returns the status of the store with entity counts

func (*Store) GetStoreStatusUser

func (s *Store) GetStoreStatusUser() StoreStatusUser

GetStoreStatusUser returns the store status without entity counts

func (*Store) GraceCheck

func (s *Store) GraceCheck(bookings []string)

func (*Store) MakeBooking

func (s *Store) MakeBooking(slot, user string, when interval.Interval) (Booking, error)

MakeBooking makes bookings for users, according to the policy If a user does not exist, one is created. APIs for users should call this version do not use mutex, because it calls function that handles that

func (*Store) MakeBookingWithName

func (s *Store) MakeBookingWithName(slot, user string, when interval.Interval, name string, checkGroup bool) (Booking, error)

MakeBookingWithID makes bookings for users, according to the policy If a user does not exist, one is created. The booking ID is set by the caller, so that bookings can be edited/replaced This version should only be called by Admin users

func (*Store) Now

func (s *Store) Now() time.Time

func (*Store) PruneAll

func (s *Store) PruneAll()

PruneAll is maintenance operation ensuring all bookings are moved to the old bookings list, wherever that touches our implementation

func (*Store) RelaySecret

func (s *Store) RelaySecret() string

RelaySecret returns the relay secret don't use in internal functions because it will hang waiting for lock just use s.relaySecret directly in internal functions

func (*Store) ReplaceBookings

func (s *Store) ReplaceBookings(bm map[string]Booking) (error, []string)

ReplaceBookings will replace all bookings with a new set each booking must be valid for the manifest, i.e. all references to other entities must be valid. Note that the manifest should be set first Diaries need to be cleared by cancelling bookings to refund usage to users before making the replacement bookings through the standard method

func (*Store) ReplaceManifest

func (s *Store) ReplaceManifest(m Manifest) error

ReplaceManifest overwrites the existing manifest with a new one i.e. does not retain existing elements from any previous manifests but it does retain non-Manifest elements such as bookings.

func (*Store) ReplaceOldBookings

func (s *Store) ReplaceOldBookings(bm map[string]Booking) (error, []string)

ReplaceOldBookings will replace the map of old bookings with the supplied list or return an error if the bookings have issues. All existing users are deleted, and replaced with users with usages that match the old bookings use ReplaceUserGroups to add permissions for users, do not bother with old dummy bookings because these confer no future booking privileges (now that we get allowed policies by checking a user's groups).

func (*Store) ReplaceUserGroups added in v0.3.0

func (s *Store) ReplaceUserGroups(u map[string][]string) (error, []string)

ReplaceUsersGroups allows administrators to add and remove policies from users, e.g. to add or restrict access to experiments A user that does not exist, is created, and the groups added. Policies must exist or an error is thrown

func (*Store) ReplaceUsers

func (s *Store) ReplaceUsers(u map[string]UserExternal) (error, []string)

Replace Users is not implemented because it would allow the consistency of the store to be broken (e.g. which users were associated with which bookings). As for usage, the ReplaceBookings method already handles adjustments to usage automatically so there is no need to edit users. If a user needs more usage allowance, then they need a new policy, rather than an adjustment to their old usage value.

func (*Store) Run

func (s *Store) Run(ctx context.Context, pruneEvery time.Duration, checkEvery time.Duration)

Run handles the regular pruning of bookings and autocancellation checks

func (*Store) SetNow

func (s *Store) SetNow(now func() time.Time) *Store

SetNow sets the time function (useful for mocking in tests) Alternative named version for readability when updating the time function multiple times in a test

func (*Store) SetRelaySecret

func (s *Store) SetRelaySecret(secret string) *Store

SetRelaySecret sets the relay secret

func (*Store) SetRequestTimeout

func (s *Store) SetRequestTimeout(timeout time.Duration) *Store

SetRequestTimeout sets how long to wait for external API requests, e.g. deny requests to relay

func (*Store) SetResourceIsAvailable added in v0.3.10

func (s *Store) SetResourceIsAvailable(resource string, available bool, reason string) error

SetResourceIsAvailable sets the underlying resource's availability

func (*Store) SetSlotIsAvailable

func (s *Store) SetSlotIsAvailable(slot string, available bool, reason string) error

SetSlotIsAvailable sets the underlying resource's availability

func (*Store) WithDenyRequests

func (s *Store) WithDenyRequests(d chan deny.Request) *Store

for testing purposes, otherwise deny channel set to that of the deny.Client

func (*Store) WithDisableCancelAfterUse

func (s *Store) WithDisableCancelAfterUse(d bool) *Store

WithDisableCancelAfterUse stops users from cancelling bookings they already started using this is provided in case external API calls to relay cannot be supported (e.g. due to relay version) note all relays need to have the same secret!

func (*Store) WithGraceRebound

func (s *Store) WithGraceRebound(d time.Duration) *Store

func (*Store) WithNow

func (s *Store) WithNow(now func() time.Time) *Store

WithNow sets the time function

func (*Store) WithRelaySecret

func (s *Store) WithRelaySecret(secret string) *Store

WithRelaySecret sets the relay secret

func (*Store) WithRequestTimeout

func (s *Store) WithRequestTimeout(timeout time.Duration) *Store

WithRequestTimeout sets how long to wait for external API requests, e.g. deny requests to relay

type StoreStatusAdmin

type StoreStatusAdmin struct {
	Bookings     int64     `json:"bookings"  yaml:"bookings"`
	Descriptions int64     `json:"descriptions"  yaml:"descriptions"`
	Filters      int64     `json:"filters" yaml:"filters"`
	Groups       int64     `json:"groups" yaml:"groups"`
	Locked       bool      `json:"locked" yaml:"locked"`
	Message      string    `json:"message" yaml:"message"`
	Now          time.Time `json:"now" yaml:"now"`
	OldBookings  int64     `json:"old_bookings"  yaml:"old_bookings"`
	Policies     int64     `json:"policies" yaml:"policies"`
	Resources    int64     `json:"resources" yaml:"resources"`
	Slots        int64     `json:"slots" yaml:"slots"`
	Streams      int64     `json:"streams" yaml:"streams"`
	UIs          int64     `json:"uis" yaml:"uis"`
	UISets       int64     `json:"ui_sets" yaml:"ui_sets"`
	Users        int64     `json:"users" yaml:"users"`
	Windows      int64     `json:"windows" yaml:"windows"`
}

type StoreStatusUser

type StoreStatusUser struct {
	Locked  bool      `json:"locked" yaml:"locked"`
	Message string    `json:"message" yaml:"message"`
	Now     time.Time `json:"now" yaml:"now"`
}

type Stream

type Stream struct {
	Audience string `json:"audience" yaml:"audience"`
	// ConnectionType is whether for session or shell e.g. session
	ConnectionType string `json:"connection_type"  yaml:"connection_type"`

	// For is the key in the UI's URL in which the client puts
	// the relay (wss) address and code after getting them
	// from the relay, e.g. data
	For string `json:"for"  yaml:"for"`

	// Scopes represent what the client can do e.g. read, write
	Scopes []string `json:"scopes"  yaml:"scopes"`

	// Topic is the relay topic, usually <resource name>-<for>. e.g. pend03-data
	Topic string `json:"topic"  yaml:"topic"`

	// URL of the relay access point for this stream e.g. https://relay-access.practable.io
	URL string `json:"url"  yaml:"url"`
}

Stream represents a prototype for a type of stream from a relay Streams will typically be either data, video, or logging. If multiple relay access servers r1, r2 etc are used,just define separate prototypes for each type of stream, on each relay, e.g. data-r0, data-r1 etc. Note that in future, a single access point will reverse proxy for multiple actual relays, so it's only if there are multiple access points that this would be needed. Streams are typically accessed via POST with bearer token to an access API

type UI

type UI struct {
	Description string `json:"description"  yaml:"description"`
	// URL with moustache {{key}} templating for stream connections
	URL             string   `json:"url"  yaml:"url"`
	StreamsRequired []string `json:"streams_required"  yaml:"streams_required"`
}

UI represents a UI that can be used with a resource, for a given slot

type UIDescribed

type UIDescribed struct {
	Description Description `json:"description"  yaml:"description"`
	// Keep track of the description's name, needed for ExportManifest
	DescriptionReference string `json:"-" yaml:"-"`
	// URL with moustache {{key}} templating for stream connections
	URL             string   `json:"url"  yaml:"url"`
	StreamsRequired []string `json:"streams_required"  yaml:"streams_required"`
}

UIDescribed represents a UI that can be used with a resource, for a given slot with a description - for sending to users

type UISet

type UISet struct {
	UIs []string `json:"uis" yaml:"uis"`
}

UISet represents UIs that can be used with a slot

type User

type User struct {
	Bookings    map[string]*Booking       //map by id for retrieval
	OldBookings map[string]*Booking       //map by id, for admin dashboards
	Groups      map[string]bool           //map of groups of policies that the user can access
	Usage       map[string]*time.Duration //map by policy for checking usage
}

User represents bookings and usage information associated with a single user remembering policies allows us to direct a user to link to a policy for a course just once, and then have that remembered at least until a system restart -> should be logged as a transaction

func NewUser

func NewUser() *User

NewUser returns a pointer to a new User

type UserExternal

type UserExternal struct {
	Bookings    []string `json:"bookings" yaml:"bookings"`
	OldBookings []string `json:"old_bookings" yaml:"old_bookings"`
	Groups      []string `json:"groups" yaml:"groups"`
	//map humanised durations by policy name
	Usage map[string]string `json:"usage" yaml:"usage"`
}

type Window

type Window struct {
	Allowed []interval.Interval `json:"allowed"  yaml:"allowed"`
	Denied  []interval.Interval `json:"denied"  yaml:"denied"`
}

Window represents allowed and denied periods for slots

Jump to

Keyboard shortcuts

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