gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit80307ae280307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre80307ae2/components/sshkeys.hl

4.9 KB

  1. // components/sshkeys.hl — SSH KEYS (gitoria#7): what a developer's git uses to push over SSH (docker/sshd asks sshkeys.hl). On the
  2. // main address, for a logged-in user: paste a PUBLIC key with a name, list the own keys (name, fingerprint), remove one. Only shown
  3. // when the sshd container is set up (GITORIA_SSH_SECRET). Composed into list.hl (`#sshkeys`).
  4. import { infoOfSession, userOfSession, userIdOfSession } from '../lib/users.hl'
  5. import { sshEnabled, keyRows, addKey, revokeKey } from '../lib/sshkeys.hl'
  6. session = null
  7. me = infoOfSession(session)
  8. enabled = sshEnabled
  9. shown = enabled && me != null
  10. myUserId = userIdOfSession(session)
  11. keyItems = myUserId != null && enabled ? keyRows(myUserId) : []
  12. showHead = shown
  13. showForm = shown
  14. showNone = shown && keyItems.length == 0
  15. keyError = ''
  16. keyNameText = ''
  17. keyText = ''
  18. View {
  19. sshKeys { id = "sshkeys"
  20. if (showHead) { h2 { "SSH keys" } }
  21. if (showHead) { p { class = "muted" "To push with git over SSH, add your public key (the .pub file, for example ~/.ssh/id_ed25519.pub). Reading a repository needs no key." } }
  22. if (showForm) {
  23. form { id = "keyform"
  24. on submit(e) {
  25. e.preventDefault()
  26. emit makeKey(e)
  27. }
  28. label { "Name (for example the computer it is for)"
  29. input { id = "keyname" name = "keyname" required = "required" maxlength = "60" autocomplete = "off" value = keyNameText on input(e) { emit setKeyName(e.target.value) } }
  30. }
  31. label { "Public key"
  32. textarea { id = "keytext" name = "keytext" required = "required" rows = "3" spellcheck = "false" autocomplete = "off" placeholder = "ssh-ed25519 AAAA… you@computer" value = keyText on input(e) { emit setKeyText(e.target.value) } }
  33. }
  34. button { id = "keysave" type = "submit" "Add key" }
  35. p { id = "keyerror" keyError }
  36. }
  37. }
  38. if (showNone) { p { id = "nokeys" class = "muted" "You have no SSH keys yet." } }
  39. ol { id = "keylist"
  40. for (k of keyItems) {
  41. li {
  42. span { k.name }
  43. code { k.fingerprint }
  44. time { k.created }
  45. // Existing theme and test-hook classes have no component Style rule.
  46. button { class = "quiet removekey" type = "button" value = k.@id "Remove" on click(e) { emit removeKey(e.target.value) } }
  47. }
  48. }
  49. }
  50. }
  51. }
  52. // one `if` per element, none inside another (a nested `if` broke the client's repaint on logout)
  53. on setKeyName(v) { keyNameText = v }
  54. on setKeyText(v) { keyText = v }
  55. on makeKey(e) {
  56. r = emit server gitoriaAddKey(keyNameText, keyText)
  57. if (r == null || r.error != null) {
  58. keyError = r != null ? r.error : 'could not add the key'
  59. return null
  60. }
  61. keyError = ''
  62. keyNameText = ''
  63. keyText = ''
  64. // the face's answer can bring `keyItems` fresh from the server already (hl:web ships a member derived from
  65. // `session` in the ack's sync, hybriel 64527baa) — so the new row is put on top ONCE, never twice
  66. keyItems.remove(r.row.@id)
  67. keyItems = [r.row, for (x of keyItems) { x }]
  68. showNone = shown && keyItems.length == 0
  69. }
  70. on removeKey(id) {
  71. r = emit server gitoriaRemoveKey(id)
  72. if (r == null || r.error != null) {
  73. keyError = r != null ? r.error : 'could not remove the key'
  74. return null
  75. }
  76. keyError = ''
  77. keyItems.remove(id)
  78. showNone = shown && keyItems.length == 0
  79. }
  80. // a login / logout (the shell's faces push them) shows or hides the section
  81. on client gitoriaSignedIn(tag, info) {
  82. shown = enabled
  83. showHead = shown
  84. showForm = shown
  85. showNone = shown && keyItems.length == 0
  86. }
  87. on client gitoriaSignedOut(tag) {
  88. shown = false
  89. keyItems = []
  90. showHead = false
  91. showForm = false
  92. showNone = false
  93. }
  94. on server gitoriaAddKey(name, text, session) {
  95. if (!sshEnabled) { return { error = 'SSH is not set up on this server' } }
  96. u = userOfSession(session)
  97. if (u == null) { return { error = 'log in with ident (top right) first' } }
  98. return addKey(u.id, name, text)
  99. }
  100. on server gitoriaRemoveKey(id, session) {
  101. u = userOfSession(session)
  102. if (u == null) { return { error = 'log in with ident (top right) first' } }
  103. return revokeKey(u.id, id)
  104. }
  105. Style {
  106. #keyerror {
  107. margin = '0'
  108. color = 'var(--color-danger)'
  109. empty { display = 'none' }
  110. }
  111. sshKeys {
  112. display = 'grid'
  113. gap = '.75rem'
  114. minWidth = '0'
  115. // Direct-child universal selectors have no bare language form.
  116. '> *' {
  117. margin = '0'
  118. }
  119. }
  120. #keyform {
  121. display = 'grid'
  122. gap = '.75rem'
  123. padding = '1rem'
  124. background = 'var(--color-surface)'
  125. borderRadius = 'var(--radius-large)'
  126. // Direct-child universal selectors have no bare language form.
  127. '> *' {
  128. margin = '0'
  129. }
  130. }
  131. #keylist {
  132. display = 'grid'
  133. gap = '.5rem'
  134. margin = '0'
  135. padding = '0'
  136. listStyle = 'none'
  137. li {
  138. display = 'flex'
  139. flexWrap = 'wrap'
  140. alignItems = 'center'
  141. gap = '.2rem 1rem'
  142. margin = '0'
  143. padding = '.4rem .5rem .4rem 1rem'
  144. background = 'var(--color-surface)'
  145. borderRadius = 'var(--radius-large)'
  146. }
  147. }
  148. #keytext {
  149. font = '1rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'
  150. }
  151. #span {
  152. fontWeight = '700'
  153. marginRight = 'auto'
  154. overflowWrap = 'anywhere'
  155. }
  156. #code {
  157. overflowWrap = 'anywhere'
  158. color = 'var(--color-text-muted)'
  159. }
  160. }

Branches

Latest commits

  • 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
  • 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
  • 155861f6Merge branch 'w52-person-approval' into mainGitoria
  • b5435de8|||PR person approvals: second Kunibert round (#52)mre
  • 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre
  • 2a89d8d0|||PR person approvals: Approve button for people; merge needs the required checks or a listed person's approval (#52)mre
  • 83f0c953Report person approval verificationmre
  • 3ae94b86Record browser failures and verify owned tab cleanupmre
  • 54eec687Gate person approvals and merge alternativesmre
  • 12b08829Add person approvals for pull request headsmre
  • 55c84779Merge branch 'gp-gate-ports' into mainGitoria
  • 57af42bbREADME: point to deploy.sh for the port listmre
  • d63375d2README: gate commands with explicit portsmre
  • feeaa701|||PR gates: explicit ports only, deploy.sh passes themmre
  • 6cc1f943Merge branch 'records-1112' into mainGitoria
  • 9448c438|||PR records: LOG, missions and reports since 11-09mre
  • 6dc08a8eMerge branch 'p51-public-pr-reads' into mainGitoria
  • 7b88cfe0Type publicReaderOfRequest parameters (L10)Gitoria
  • 2a4b3dc1|||PR Anonymous reads of public repos' pulls and statusesmre
  • 21b2c141Merge branch 's25-no-session-on-login-error' into mainGitoria