def auth

bend-kit-postgres@0.3.0.0 · postgres.bend:329

import bend-kit-postgres@0.3.0.0/postgres.bend as Postgres
import Base
import bend-kit-postgres@0.3.0.0/codec.bend as Codec

329# The first message after StartupMessage picks the authentication method.
330def auth(+user: String, +pass: String, r: Result<&1, &1, Failure, Conn & Codec.Back>) -> IO(Result<&1, &1, Failure, Conn>):
331  match r:
332    case Fail{e}:
333      IO.pure(Result<&1, &1, Failure, Conn>, Fail{e})
334    case Done{(c, m)}:
335      match m:
336        case Codec.AuthOk{}:
337          ready(c)
338        case Codec.AuthCleartext{}:
339          do IO<Result<&1, &1, Failure, Conn>>:
340            a : Result<&1, &1, Failure, Conn & Codec.Back> <- exchange(c, Codec.Password{bytes(pass)})
341            auth.done(a)
342        case Codec.AuthSASL{mechs}:
343          sasl(has.mech(mechs), c, user, pass)
344        case Codec.ErrorResponse{fs}:
345          reject(Conn, c, fs)
346        case Codec.AuthOther{+code, data}:
347          abort(Conn, c, Auth{"unsupported authentication request " ++ U32.show(code)})
348        case _:
349          abort(Conn, c, Malformed{})

Uses (21)

Used by (1)