source.v
1//! A repo stolen from a Kepr that is not signed in: its own address, kept read-only.2//!3//! This is the addendum's one exception to the machine-wide remote rule. The4//! address lives in the repo's `state`, so nothing about it can leak into another5//! repo, and it is dropped the moment this machine signs in to that Kepr.67module exchange89import src.machine10import src.remote11import src.storage1213const source_key = 'source'1415/// The address a stolen repo came from, `<base>/<repo>`, or '' for an ordinary repo.16pub fn source_of(store &storage.Store) string {17 return store.state(source_key) or { '' }18}1920/// The Kepr part of a source: what `koh remote <host>` would have to name.21pub fn source_host(source string) string {22 return source.all_before_last('/')23}2425/// True when this machine was set up by `koh remote <host>` for the same host, so that host's26/// addresses are this machine's own bucket (Part 2 of the addendum).27pub fn signed_in_to(host string) bool {28 settings := machine.load_remote() or { return false }29 return settings.kind == machine.kind_s3 && settings.kepr != '' && settings.kepr == host30}3132/// read_only opens the backend a stolen repo came from: public, and never written to.33pub fn read_only(source string) !remote.Backend {34 return remote.new_web(source_host(source))!35}3637/// remember_source and forget_source are the only two writes: a repo is either a stolen one or an38/// ordinary one, never both.39pub fn remember_source(store &storage.Store, source string) ! {40 store.set_state(source_key, source)!41}4243pub fn forget_source(store &storage.Store) ! {44 store.set_state(source_key, '')!45}