usage/gate.bend relies on unsafe/foreign
raw source on the hub · import cswap-bend-cli@0.1.0.0/usage/gate.bend as Gate
10 imports
import Base import ../clock.bend as Clock import ../fs.bend as Fs import ../lock.bend as Lock import ../b64.bend as B64 import ../fs/write.bend as FsW import ../store/base.bend as SBase import ./norm.bend as UNorm import ./cred.bend as UCred import ../json.bend as Json
Types
type Gated source · line 24 · raw
Data
Gated@cred:Maybe<&2, String> -> @error:Maybe<&2, String> -> @consumed:Maybe<&2, String> -> @account:0x0717344745a30ebad1f19045228e8f18/json.Json -> Gated
type Gate source · line 27 · raw
Data
NoGateGate
Gate@slot:String -> @email:String -> @root:String -> Gate
Definitions
def enc.path source · line 31 · raw
@+root:String -> @+slot:String -> @+email:String -> String
def consume.path source · line 34 · raw
@+root:String -> @+slot:String -> String
def fp.pick source · line 37 · raw
@+m:Maybe<&2, String> -> @+cred:String -> String
def fp source · line 47 · raw
@+cred:String -> String
Lineage identity, as the reference's credential_fingerprint (refresh token when there is one, else the whole credential), kept as text: it is only ever compared for equality, so no hash is needed.
def gated.err source · line 50 · raw
@+k:String -> @+consumed:Maybe<&2, String> -> Gated
def gated.ok source · line 53 · raw
@+c:String -> @+consumed:Maybe<&2, String> -> Gated
def gated.ok_a source · line 56 · raw
@+c:String -> @+consumed:Maybe<&2, String> -> @+acct:0x0717344745a30ebad1f19045228e8f18/json.Json -> Gated
def done.g source · line 59 · raw
@g:Gated -> IO(0x0717344745a30ebad1f19045228e8f18/fs.Res(Gated))
def stored source · line 62 · raw
@r:0x0717344745a30ebad1f19045228e8f18/fs.Res(String) -> Maybe<&2, String>
def adopt.pick source · line 71 · raw
@+cur:Maybe<&2, String> -> @+snap:Maybe<&2, String> -> @+ex:Bool -> Bool
The world moved past the caller's snapshot and the current generation is fresh: the refresh the caller wanted has happened.
def adopt source · line 78 · raw
@+cur:String -> @+snapshot:String -> @+now:U32 -> Bool
def write.back source · line 81 · raw
@+path:String -> @+old_text:String -> @+new:String -> @+acct:0x0717344745a30ebad1f19045228e8f18/json.Json -> IO(0x0717344745a30ebad1f19045228e8f18/fs.Res(Gated))
def cas.pick source · line 88 · raw
@+same:Bool -> @+path:String -> @+text:String -> @+new:String -> @+acct:0x0717344745a30ebad1f19045228e8f18/json.Json -> @+now_cred:String -> IO(0x0717344745a30ebad1f19045228e8f18/fs.Res(Gated))
CAS on the lineage: write the successor only when the store still holds the generation we consumed; a moved store keeps its newer lineage.
def cas.store source · line 95 · raw
@+m:Maybe<&2, String> -> @+path:String -> @+text:String -> @+cur:String -> @+new:String -> @+acct:0x0717344745a30ebad1f19045228e8f18/json.Json -> IO(0x0717344745a30ebad1f19045228e8f18/fs.Res(Gated))
def act.post source · line 102 · raw
@r:Result<&2, &2, String, 0x0717344745a30ebad1f19045228e8f18/usage/cred.Granted> -> @+path:String -> @+text:String -> @+cur:String -> IO(0x0717344745a30ebad1f19045228e8f18/fs.Res(Gated))
def act.decide source · line 109 · raw
@+adopt:Bool -> @+path:String -> @+text:String -> @+cur:String -> IO(0x0717344745a30ebad1f19045228e8f18/fs.Res(Gated))
def act.cur source · line 116 · raw
@+m:Maybe<&2, String> -> @+path:String -> @+text:String -> @+snapshot:String -> IO(0x0717344745a30ebad1f19045228e8f18/fs.Res(Gated))
def act.read source · line 123 · raw
@r:0x0717344745a30ebad1f19045228e8f18/fs.Res(String) -> @+path:String -> @+snapshot:String -> IO(0x0717344745a30ebad1f19045228e8f18/fs.Res(Gated))
def gate.act source · line 130 · raw
@+path:String -> @+snapshot:String -> IO(0x0717344745a30ebad1f19045228e8f18/fs.Res(Gated))
def busy.err source · line 133 · raw
@+code:U32 -> Gated
def locked.fail source · line 136 · raw
@ce:Pair(U32, String) -> Gated
def locked.res source · line 140 · raw
@r:0x0717344745a30ebad1f19045228e8f18/fs.Res(Gated) -> Gated
def timeout.of source · line 147 · raw
@r:Result<&1, &1, Pair(U32, String), String> -> U32
def gated.locked source · line 154 · raw
@+slot:String -> @+email:String -> @+snapshot:String -> @+root:String -> @+ms:U32 -> IO(Gated)
def gated.go source · line 159 · raw
@+slot:String -> @+email:String -> @+snapshot:String -> @+root:String -> IO(Gated)
def gated.env2 source · line 163 · raw
@+set:Bool -> @+slot:String -> @+email:String -> @+snapshot:String -> @+root:String -> IO(Gated)
def gated.env source · line 170 · raw
@r:Result<&1, &1, Pair(U32, String), String> -> @+slot:String -> @+email:String -> @+snapshot:String -> @+root:String -> IO(Gated)
def refresh_gated source · line 182 · raw
@+slot:String -> @+email:String -> @+snapshot:String -> @+root:String -> IO(Gated)
consume_backup_grant: refresh the slot's credential under its consume lock.
snapshot is the caller's copy; the gate consumes the freshest copy it can
read from <root>/credentials/.creds-<slot>-<email>.enc, or adopts a fresher fresh one
without any POST. Busy past the timeout (10 s, or
CSWAP_CONSUME_TIMEOUT_MS) is consume-busy.
def plain.pick source · line 186 · raw
@r:Result<&2, &2, String, String> -> @+cred:String -> Gated
def refresh_via source · line 194 · raw
@g:Gate -> @+cred:String -> IO(Gated)
Gate or direct POST, by the caller's choice.