annals.share#
Share links: one document (or a group) behind a public, unguessable, revocable link.
A share is a record under the data root, shares/<token>.json, written through the
same annals.target.Target as the documents, so annals share works over ssh
exactly like annals publish. The record is the whole contract; the owner’s API, the
page’s Share button, the CLI and the public share server (annals.share_api) are
surfaces over it:
{
"token": "<22 url-safe chars, 128 random bits>",
"title": "...", "created": "<iso>",
"root": {"kind": "doc" | "group", "id": "<id>"},
"docs": {"<doc id>": ["<file>", ...], ...}, # what the link may reach, and only that
"expires": "<iso>" | null,
"password": "scrypt$..." | null, # a hash; the password is never stored
"revoked": "<iso>" | null # a tombstone: a revoked link is a 404
}
docs is the scope. Every request of the public server is checked against it, never
against what the link was made from: a file not listed is a 404 even when it sits beside
the shared page, and a page or a link of the shared text that points outside the scope is
removed before the text leaves the server (filter_refs()), so the recipient sees
neither private ids nor private paths.
The link itself (the token, the password gate, expiry, revocation) is a
caplinks.CapabilityLinks over these records; what is annals’ own is the scope
and the filtering. The password is a gate on the link, not an account: anyone who knows
both may read. It is hashed (stdlib scrypt by default, the hasher seam takes
argon2), and a correct one earns an HMAC cookie keyed by that hash, so changing the
password or revoking the link ends every open session.
Module Attributes
an annals id (doc or group) as |
Functions
|
The absolute links to annals document and group pages in |
|
The directory part of a relative path, with its trailing slash ( |
|
|
|
|
|
What a page points at: files of its document, and annals pages (by id). |
|
|
|
A relative url as a file path inside the document, or |
|
The forms of one share link: |
|
The link a recipient opens, or |
Classes
|
Create, read, list and revoke shares of a |
- annals.share.ANNALS_ID = '\\d{8}-\\d{6}-[a-z0-9]+(?:-[a-z0-9]+)*'#
an annals id (doc or group) as
annals.store.mk_id()makes them
- class annals.share.Shares(store, *, hasher=None, clock=<function now_utc>)[source]#
Bases:
objectCreate, read, list and revoke shares of a
DocStore’s documents.What a share reaches (its scope) is decided here; the link itself is
links, acaplinks.CapabilityLinksover the records undershares/.hasherhashes link passwords (stdlib scrypt by default);clockreturns the current UTCdatetime(tests pin it).- create(ref, *, include=None, exclude=(), password=None, expires='7d', title=None, files_of=None)[source]#
Share a document or a group (
refis its id); return the record (no hash).A document is shared with all its files unless
includenames some (the page itself always goes);includemay also name annals pages the document links to, which then open inside the share. A group is shared with all its documents unlessincludenames some.excluderemoves files (or a group’s documents). A linked page goes with the files it shows.expiresis anythingparse_expires()reads, 7 days by default ("never"for none);passwordgates the link (at leastcaplinks.MIN_PASSWORD_LENcharacters).files_of(meta)narrows which files of each of a group’s documents go (all of them by default;annals.notebook.source_scope()keeps only the pages and what they show).- Return type:
- included(record)[source]#
(meta, files)for each document of a share still there, in the share’s order.filesare the document’s files the share includes; a document deleted or in the bin since the link was made is left out.
- list(*, all=False)[source]#
Every share, newest first, without hashes;
alladds revoked and expired.
- resources(doc_id)[source]#
What the Share dialog offers for a document: its files, and the pages it links.
{"main", "files": [{"rel", "kind", "size", "referenced"}], "pages": [{"id", "title", "kind"}]}.referencedmarks the files the page itself shows or links;pagesare the other annals documents its text links to.- Return type:
- revoke(token)[source]#
End a link now (idempotent). The record stays, as a tombstone, for the list.
- Return type:
- annals.share.annals_urls(text)[source]#
The absolute links to annals document and group pages in
text, once each, in order.Any host: which annals a link belongs to is the reader’s config to decide (
annals.config.link_target()). Relative links (../d/<id>) are not found: a document’s own links to its annals are absolute, asannals publishprints them.>>> annals_urls("see **[map](https://a.example.io/annals/d/20261119-075018-the-map-4a58)**, " ... "<https://b.example.com/annals/g/20261117-163049-set?f=x> and " ... "https://a.example.io/annals/d/20261119-075018-the-map-4a58 again") ['https://a.example.io/annals/d/20261119-075018-the-map-4a58', 'https://b.example.com/annals/g/20261117-163049-set']
- annals.share.dir_of(rel)[source]#
The directory part of a relative path, with its trailing slash (
""at the top).- Return type:
- annals.share.filter_refs(text, kind, *, files, shared, from_dir='', private_hosts=())[source]#
textwith every reference outside the share removed (or rewritten).filesare the document’s files the share includes;shared(id)maps an annals id to where the recipient opens it (in scope) orNone(not shared). A markdown image out of scope disappears, a link keeps its words; an html attribute goes; a bare annals url becomes “(link not shared)” and a bare annals id “(not shared)”. The text of the page itself is the owner’s: only references are touched. An absolute url on one ofprivate_hosts(the owner’s own) goes too, whatever its path. Every kind of text is filtered (markdown, html, plain text, svg): only markdown syntax is markdown’s. Best effort by design, and the second line of defence: the share server answers 404 for anything outside the share however the text names it.- Return type:
- annals.share.ref_decider(*, from_dir, files, shared, private_hosts=())[source]#
url -> new url(often the same) orNone(remove it).The one rule of what a shared text may point at;
filter_refs()applies it to the references it finds in text,annals.notebookto a rendered page’s links.
- annals.share.references(text, kind, *, from_dir='')[source]#
What a page points at: files of its document, and annals pages (by id).
{"files": [rel, ...], "ids": [annals id, ...]}, each in first-seen order; it feeds the Share dialog, which offers them to the owner.- Return type:
- annals.share.remove_unshared_ids(text, shared)[source]#
textwith every annals id thatshareddoes not map replaced by a marker.- Return type:
- annals.share.resolve_rel(url, from_dir='')[source]#
A relative url as a file path inside the document, or
Noneif it is not one.>>> resolve_rel("img/a.png?x=1#y", "notes/") 'notes/img/a.png' >>> resolve_rel("../../etc/passwd") is None, resolve_rel("https://x.org/a") is None (True, True)
- annals.share.share_links(base, token)[source]#
The forms of one share link:
page(people, and fetchers that run no script),markdown(agents: the whole share as one text) andpdf(images inside, or for an upload); empty when no share server is configured.annals.share_page.