Documentation
¶
Overview ¶
Package trust remembers, for each document, whether its user let mdsh read the files the front matter's env.source names into its shells, so that mdsh, mdsh -i and mdsh-gui ask once per file, and again only when the list of files changes. The answers live in one JSON file, shared by every front end. A second store, at OutsidePath, keeps in the same way whether a document's includes and out= files may reach outside its folder, or hidden in it (see run.Outside).
Index ¶
- Constants
- func DefaultPath() (string, error)
- func OutsidePath() (string, error)
- type Choice
- type Store
- func (st *Store) Allowed() []string
- func (st *Store) Ask(file string, ask func(paths []string) run.Answer) func(paths []string) run.Answer
- func (st *Store) Forget(file string) error
- func (st *Store) Lookup(file string, sources []string) (allow, ok bool)
- func (st *Store) Remember(file string, sources []string, allow bool) error
Constants ¶
const Max = 500
Max is how many documents' answers are kept; the oldest go first.
Variables ¶
This section is empty.
Functions ¶
func DefaultPath ¶
DefaultPath is mdsh/sources.json in the user's config folder.
func OutsidePath ¶
OutsidePath is mdsh/outside.json in the user's config folder, where the answers to whether a document may reach outside its root live.
Types ¶
type Choice ¶
type Choice struct {
// File is the document's absolute path.
File string `json:"file"`
// Sources are the files approved or refused, as run.SourcePaths
// gives them. A document that names other files is asked again.
Sources []string `json:"sources"`
// Allow is whether they may be read.
Allow bool `json:"allow"`
// At is when the answer was given.
At time.Time `json:"at"`
}
Choice is the answer for one document.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps the answers in a JSON file. It reads the file on each lookup, so an answer given in one front end holds in the others.
func OpenDefault ¶
func OpenDefault() *Store
OpenDefault opens the store at DefaultPath, or returns nil, which remembers nothing, if there is no config folder.
func OpenOutside ¶
func OpenOutside() *Store
OpenOutside opens the store at OutsidePath, or returns nil, which remembers nothing, if there is no config folder.
func (*Store) Allowed ¶
Allowed lists the documents whose last answer allowed them, whatever their lists were then.
func (*Store) Ask ¶
func (st *Store) Ask(file string, ask func(paths []string) run.Answer) func(paths []string) run.Answer
Ask returns a run.Options.ApproveSources for the document at file that answers from the store when it can and otherwise asks ask, which may be nil when nobody can be asked. A Go or Skip answer from ask is remembered; Stop isn't, so the next run asks again.