gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3c425edd3c425eddReference PR content styles and explain dynamic state classesmre3c425edd/components/sshkeys.hl

5.0 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. next = [r.row]
  67. for (x of keyItems) { if (x.id != r.row.id) { next.push(x) } }
  68. keyItems = next
  69. showNone = shown && keyItems.length == 0
  70. }
  71. on removeKey(id) {
  72. r = emit server gitoriaRemoveKey(id)
  73. if (r == null || r.error != null) {
  74. keyError = r != null ? r.error : 'could not remove the key'
  75. return null
  76. }
  77. keyError = ''
  78. next = []
  79. for (x of keyItems) { if (x.id != id) { next.push(x) } }
  80. keyItems = next
  81. showNone = shown && keyItems.length == 0
  82. }
  83. // a login / logout (the shell's faces push them) shows or hides the section
  84. on client gitoriaSignedIn(tag, info) {
  85. shown = enabled
  86. showHead = shown
  87. showForm = shown
  88. showNone = shown && keyItems.length == 0
  89. }
  90. on client gitoriaSignedOut(tag) {
  91. shown = false
  92. keyItems = []
  93. showHead = false
  94. showForm = false
  95. showNone = false
  96. }
  97. on server gitoriaAddKey(name, text, session) {
  98. if (!sshEnabled) { return { error = 'SSH is not set up on this server' } }
  99. u = userOfSession(session)
  100. if (u == null) { return { error = 'log in with ident (top right) first' } }
  101. return addKey(u.id, name, text)
  102. }
  103. on server gitoriaRemoveKey(id, session) {
  104. u = userOfSession(session)
  105. if (u == null) { return { error = 'log in with ident (top right) first' } }
  106. return revokeKey(u.id, id)
  107. }
  108. Style {
  109. #keyerror {
  110. margin = '0'
  111. color = 'var(--color-danger)'
  112. empty { display = 'none' }
  113. }
  114. sshKeys {
  115. display = 'grid'
  116. gap = '.75rem'
  117. minWidth = '0'
  118. // Direct-child universal selectors have no bare language form.
  119. '> *' {
  120. margin = '0'
  121. }
  122. }
  123. #keyform {
  124. display = 'grid'
  125. gap = '.75rem'
  126. padding = '1rem'
  127. background = 'var(--color-surface)'
  128. borderRadius = 'var(--radius-large)'
  129. // Direct-child universal selectors have no bare language form.
  130. '> *' {
  131. margin = '0'
  132. }
  133. }
  134. #keylist {
  135. display = 'grid'
  136. gap = '.5rem'
  137. margin = '0'
  138. padding = '0'
  139. listStyle = 'none'
  140. li {
  141. display = 'flex'
  142. flexWrap = 'wrap'
  143. alignItems = 'center'
  144. gap = '.2rem 1rem'
  145. margin = '0'
  146. padding = '.4rem .5rem .4rem 1rem'
  147. background = 'var(--color-surface)'
  148. borderRadius = 'var(--radius-large)'
  149. }
  150. }
  151. #keytext {
  152. font = '1rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'
  153. }
  154. #span {
  155. fontWeight = '700'
  156. marginRight = 'auto'
  157. overflowWrap = 'anywhere'
  158. }
  159. #code {
  160. overflowWrap = 'anywhere'
  161. color = 'var(--color-text-muted)'
  162. }
  163. }

Branches

Latest commits

  • 3c425eddReference PR content styles and explain dynamic state classesmre
  • e46fa222Own shell feedback styles and retain documented selector formsmre
  • c26084c4Reference repository list styles and nest its breakpointmre
  • f3e196b5Document Markdown direct-child selector remaindersmre
  • 70597528Reference pull list rules and explain runtime class predicatesmre
  • 1ce7ac24Reference ticket row and feedback styles from its Viewmre
  • 10cdf54bGive organization repository rows their own Style referencesmre
  • 0d019521Document shared class selectors in the styles-only filemre
  • c67404a7Scope token labels and feedback through the token Viewmre
  • 944e3dabScope key names, fingerprints and errors to the keys Viewmre
  • 7bcf7bc2Nest repo navigation media rules and document selector gapsmre
  • 46a76272Reference release row styles from the Viewmre
  • a383f428Tie README definition and path styles to its own Viewmre
  • a90812ffConsolidate add-code styles under its existing View idmre
  • 89107a3eDocument the index direct-child selector remaindermre
  • 07403362Scope reply form layout through the component form rulemre
  • 097c52baStyle the login error through its View idmre
  • c6d9c86aOwn the not-found code rule in its componentmre
  • 055424c2Record W61 replacement theme gates, sidebar repro and baselinemre
  • 2ed09441Use layouts theme 17e0f03 for W61 compatibilitymre