safety

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package safety persists owner policy and enforces it at Plex request boundaries.

Index

Constants

View Source
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

func AllowedWithPolicy(u *core.User, t *core.Title, p Policy) bool

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

func CanPlayWithPolicy(u *core.User, p Policy, remote bool, now time.Time) bool

CanPlayWithPolicy evaluates the same playback rules against an owned policy snapshot. It does not establish freshness or an authorization interval.

func IsRemote

func IsRemote(r *http.Request) bool

func UserPolicyWithPolicy added in v0.3.0

func UserPolicyWithPolicy(u *core.User, p Policy) *core.User

UserPolicyWithPolicy applies restrictions from a caller-owned policy copy.

Types

type PlexShare added in v0.3.0

type PlexShare struct {
	FilterMovies     string
	FilterTelevision string
	AllowSync        *bool
}

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 {
	StreamLimit      int      `json:"streamLimit"`
	MaxContentRating string   `json:"maxContentRating"`
	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"`
}

func KidsPreset

func KidsPreset(age string) Policy

func (Policy) Validate added in v0.2.4

func (p Policy) Validate() error

Validate reports why p cannot be stored, if it cannot.

type Service

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

func New

func New(ctx context.Context, db *sql.DB) (*Service, error)

func (*Service) AllowDownloads added in v0.3.0

func (s *Service) AllowDownloads(u *core.User) bool

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) Allowed

func (s *Service) Allowed(u *core.User, t *core.Title) bool

func (*Service) BitrateLimit

func (s *Service) BitrateLimit(u *core.User) int

func (*Service) BrowseBlocks added in v0.3.0

func (s *Service) BrowseBlocks(u *core.User) (genres, keywords []string, maxRating string)

BrowseBlocks is the part of a viewer's policy that library SQL can apply before pagination: blocked genres, blocked keywords, and the rating cap.

func (*Service) BrowseShareFilter added in v0.3.0

func (s *Service) BrowseShareFilter(u *core.User, typ core.MediaType) core.Filter

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) CanPlay

func (s *Service) CanPlay(u *core.User, remote bool, now time.Time) bool

func (*Service) Close

func (s *Service) Close()

Close disconnects the cluster bus.

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) ForUser

func (s *Service) ForUser(u *core.User) Policy

ForUser is u's policy.

func (*Service) FreshPolicy added in v0.3.0

func (s *Service) FreshPolicy(ctx context.Context, viewerID int64) (Policy, error)

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

func (s *Service) Generation() uint64

Generation changes when a viewer's safety policy is saved.

func (*Service) Get

func (s *Service) Get(id int64) Policy

func (*Service) Handler

func (s *Service) Handler() http.Handler

func (*Service) PolicyInTx added in v0.3.0

func (s *Service) PolicyInTx(ctx context.Context, tx *sql.Tx, viewerID int64) (Policy, error)

PolicyInTx reads the durable policy row. A missing row is unrestricted.

func (*Service) Put

func (s *Service) Put(ctx context.Context, id int64, p Policy) error

func (*Service) Restricted

func (s *Service) Restricted(u *core.User) bool

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

func (s *Service) SetCatalogPolicy(fn func(*core.Title) bool)

SetCatalogPolicy installs the global catalogue policy during app construction.

func (*Service) SetFriendsDownloads added in v0.3.0

func (s *Service) SetFriendsDownloads(fn func() bool)

func (*Service) SetPlexShare added in v0.3.0

func (s *Service) SetPlexShare(fn func(*core.User) PlexShare)

func (*Service) UserPolicy

func (s *Service) UserPolicy(u *core.User) *core.User

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.

Jump to

Keyboard shortcuts

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