gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5dccbe385dccbe38gitoria#43: in-flight rows are left alone by the other process; gate in deploy.sh; READMEmre5dccbe38/lib/app-auth.hl

2.0 KB

  1. // lib/app-auth.hl — WHO IS THE APP BEHIND AN API REQUEST (gitoria#42; contract docs/apps-api.md §2 and §6). ONE helper for every route of the apps API:
  2. // appOfRequest(route, req) → { app, repo } the connected app and the repo its token is bound to
  3. // or { error } the contract's error answer (a Response), to be returned as it is:
  4. // 401 unauthorized no Bearer token, a token that is unknown, expired, or whose app was removed or re-connected
  5. // 404 not_found the token is good but the request's address names another repo (or none): the same as a repo that does not exist
  6. // and keyOfRequest / tokenOfRequest read the Bearer header. Statics only.
  7. import { apiError, repoOfRequest } from './api-helpers.hl'
  8. import { appsTable } from './apps-table.hl'
  9. import { rowOfToken } from './app-tokens.hl'
  10. // the credential of `Authorization: Bearer <x>` (the scheme in any case) or null
  11. static bearerOf = (req) => {
  12. h = req.headers['authorization']
  13. if (h == null || hlTypeName(h) != 'String') { return null }
  14. t = h.trim()
  15. if (t.length < 8 || t.slice(0, 7).toLowerCase() != 'bearer ') { return null }
  16. return t.slice(7).trim()
  17. }
  18. static unauthorized = () => {
  19. return apiError(401, 'unauthorized', 'missing, unknown or expired token: get a new one with POST /apps/token', null)
  20. }
  21. static notFound = () => {
  22. return apiError(404, 'not_found', 'no such repository', null)
  23. }
  24. // the live token → { app, repo (records) } or null; the app must still exist and still belong to the token's repo
  25. static appOfToken = (token) => {
  26. row = rowOfToken(token)
  27. if (row == null) { return null }
  28. app = appsTable.fetch(row.app)
  29. if (app == null || app.repo != row.repo) { return null }
  30. return { app = app repoId = row.repo }
  31. }
  32. static appOfRequest = (route, req) => {
  33. found = appOfToken(bearerOf(req))
  34. if (found == null) { return { error = unauthorized() } }
  35. repo = repoOfRequest(route, req)
  36. if (repo == null || repo.id != found.repoId) { return { error = notFound() } }
  37. return { app = found.app repo = repo }
  38. }

Branches

Latest commits

  • 5dccbe38gitoria#43: in-flight rows are left alone by the other process; gate in deploy.sh; READMEmre
  • 8c8805f3merge main (gitoria#42), delivery log and redelivery routes, sweep fixmre
  • 5a996ea8gitoria#42: short-lived app tokens, read-only git fetch with them (merge w42-app-token)mre
  • afdb0cbfgitoria#43: rename the moved helper (name clash in the browser build)mre
  • 15e01e94gitoria#43: tests/events.mjs and its probemre
  • 77829b73gitoria#43: signed events to connected apps (deliveries table, sender timer, pull_request events, ping)mre
  • b5d696fegitoria#42: app tokens (gat_, one hour), appOfRequest, app token as the git read passwordmre
  • 1997e77dgitoria#40: stable PR numbers, refs/pull/N/head, ssh pushes reach the app (merge w40-pr-number)mre
  • 9364fb16gitoria#40: ssh pushes call /__git/pushed before and after (ensurePulls, notifyPush, syncPulls); gate over the sshd imagemre
  • fdb9ed28gitoria#41: repo owners can connect an app (merge w41-apps-connect)mre
  • 2ef23df0gitoria#40: the browser gate reads the title without the #Nmre
  • 9af07ecegitoria#41: connect an app to a repo (apps table, connect flow, manual add, allow-list, settings)mre
  • b9137ff0gitoria#40: pull requests are stored with a number, refs/pull/N/head, syncPulls and pullObject; /pulls shows #Nmre
  • 06d622daown image tag gitoria-runtime:debian12 for gitoria and standby (shared tag lost git)mre
  • 20caa33agitoria#37: media queries in the language's @media block (minWidth = '60rem') in list, codebrowser and repomre
  • c4175e6dgitoria: a startup error prints its message before exit 1 (hybriel#247)mre
  • c50d17efKeep function-route not-found style in shared stylesheetmre
  • e42d78d3Preserve ticket state CSS and document function-route style gapmre
  • c6b7154eWIP gitoria#26: move styles into nested component blocksmre
  • 77a2c31cgitoria#31: plain declarations instead of needless let in lib/ and tools/ (103 let removed, 137 kept because reassigned); no other changemre