Documentation
¶
Overview ¶
Package safety persists owner policy and enforces it at Plex request boundaries.
Index ¶
- Constants
- func AllowedWithPolicy(u *core.User, t *core.Title, p Policy) bool
- func CanPlayWithPolicy(u *core.User, p Policy, remote bool, now time.Time) bool
- func IsRemote(r *http.Request) bool
- func StricterRating(account, policy string) string
- func StricterStreamLimit(a, b int) int
- type PlexShare
- type Policy
- type Preset
- type Service
- func (s *Service) AllowDownloads(u *core.User) bool
- func (s *Service) Allowed(u *core.User, t *core.Title) bool
- func (s *Service) BitrateLimit(u *core.User) int
- func (s *Service) BrowseBlocks(u *core.User) (genres, keywords []string)
- func (s *Service) BrowseShareFilter(u *core.User, typ core.MediaType) core.Filter
- func (s *Service) CanPlay(u *core.User, remote bool, now time.Time) bool
- func (s *Service) Close()
- func (s *Service) ConfirmPlayback(ctx context.Context, u *core.User, remote bool, now time.Time) (*core.User, error)
- func (s *Service) ForUser(u *core.User) Policy
- func (s *Service) FreshPolicy(ctx context.Context, viewerID int64) (Policy, error)
- func (s *Service) Generation() uint64
- func (s *Service) Get(id int64) Policy
- func (s *Service) Handler() http.Handler
- func (s *Service) PolicyInTx(ctx context.Context, tx *sql.Tx, viewerID int64) (Policy, error)
- func (s *Service) Put(ctx context.Context, id int64, p Policy) error
- func (s *Service) Restricted(u *core.User) bool
- func (s *Service) SetBus(bus clusterbus.Bus)
- func (s *Service) SetCatalogPolicy(fn func(*core.Title) bool)
- func (s *Service) SetFriendsDownloads(fn func() bool)
- func (s *Service) SetPlexShare(fn func(*core.User) PlexShare)
- func (s *Service) UserPolicy(u *core.User) *core.User
- type ShareFilterPart
Constants ¶
const LabelMapNote = "" /* 140-byte string literal not displayed */
LabelMapNote records what a plex.tv label clause can match on Ether. Owner collections and Plex item labels are not stored on the title row; looking them up on a browse path would scale with library size. A title without a TMDB collection name is allowed (the clause is a no-op).
Variables ¶
This section is empty.
Functions ¶
func AllowedWithPolicy ¶ added in v0.3.0
AllowedWithPolicy evaluates caller-owned policy facts. The caller must separately enforce the catalog visibility gate and durable policy fence.
func CanPlayWithPolicy ¶ added in v0.3.0
CanPlayWithPolicy evaluates the same playback rules against an owned policy snapshot. It does not establish freshness or an authorization interval.
func StricterRating ¶ added in v0.3.2
StricterRating is the more restrictive of two content rating limits, where "" is unrestricted. It orders labels by contentrating level, as the old account-and-policy merge did.
func StricterStreamLimit ¶ added in v0.3.2
StricterStreamLimit is the tighter of two per-viewer stream limits, where 0 adds no limit of its own: the smaller non-zero value.
Types ¶
type PlexShare ¶ added in v0.3.0
type PlexShare struct {
}
PlexShare is the cached plex.tv grant for one viewer. Ether owner policy for that viewer overrides every field here.
type Policy ¶
type Policy struct {
BlockedGenres []string `json:"blockedGenres"`
BlockedKeywords []string `json:"blockedKeywords"`
RemoteDisabled bool `json:"remoteDisabled"`
MaxBitrateKbps int `json:"maxBitrateKbps"`
// AllowedHours is empty for any time, otherwise hours 0..23 in Timezone.
AllowedHours []int `json:"allowedHours"`
Timezone string `json:"timezone"`
// AllowDownloads is an owner override of plex.tv allowSync. Nil means
// the plex.tv default (and the server AllowFriends setting) still apply.
AllowDownloads *bool `json:"allowDownloads,omitempty"`
}
Policy is the owner's per-viewer content and playback policy. A viewer's stream limit and content rating limit are not here: they live on the user record (core.User.StreamLimit, core.User.MaxContentRating), which every protocol already reads.
type Preset ¶ added in v0.3.2
Preset is a parental-controls starting point. MaxContentRating belongs on the viewer's user record; Policy is stored here. JSON flattens both.
func KidsPreset ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) AllowDownloads ¶ added in v0.3.0
AllowDownloads implements core.DownloadAccessPolicy. An owner-set Ether flag wins; otherwise plex.tv allowSync=0 refuses the queue. Friends then follow the owner's AllowFriends setting.
func (*Service) BrowseBlocks ¶ added in v0.3.0
BrowseBlocks is the part of a viewer's policy that library SQL can apply before pagination: blocked genres and blocked keywords. The rating limit is on the user record, which browse filters already read.
func (*Service) BrowseShareFilter ¶ added in v0.3.0
BrowseShareFilter is the parsed plex.tv share predicate for one library type, ready to push into catalog SQL. Owner rating caps drop plex.tv rating clauses and keep label clauses.
func (*Service) ConfirmPlayback ¶ added in v0.3.0
func (s *Service) ConfirmPlayback(ctx context.Context, u *core.User, remote bool, now time.Time) (*core.User, error)
ConfirmPlayback reads membership and safety policy inside one fenced transaction. Restricted viewers fail closed when the store is unavailable. Unrestricted viewers return ErrPolicyUnconfirmed so cached playback can continue. An unrestricted viewer whose epoch has not moved since the last fence is answered from that snapshot, so a play does not take a write lock.
func (*Service) FreshPolicy ¶ added in v0.3.0
FreshPolicy reads the durable policy without consulting the process cache. The caller must fence the corresponding durable viewer-policy epoch across authorization; a standalone result is not itself an authorization. A missing row has the same unrestricted policy value as Service.Get.
func (*Service) Generation ¶ added in v0.3.0
Generation changes when a viewer's safety policy is saved.
func (*Service) PolicyInTx ¶ added in v0.3.0
PolicyInTx reads the durable policy row. A missing row is unrestricted.
func (*Service) SetBus ¶
func (s *Service) SetBus(bus clusterbus.Bus)
SetBus connects the cluster bus (nil disconnects): policy changes made on this node reach the others' caches and vice versa.
func (*Service) SetCatalogPolicy ¶ added in v0.2.12
SetCatalogPolicy installs the global catalogue policy during app construction.
func (*Service) SetFriendsDownloads ¶ added in v0.3.0
func (*Service) SetPlexShare ¶ added in v0.3.0
type ShareFilterPart ¶ added in v0.3.0
type ShareFilterPart = sharefilter.Part
ShareFilterPart is one owner-readable clause of a plex.tv share filter.
func FormatShareFilter ¶ added in v0.3.0
func FormatShareFilter(spec string) []ShareFilterPart
FormatShareFilter turns a plex.tv filter spec into owner-readable parts.