Matrix Docker Ansible eploy
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

146 lignes
5.2 KiB

  1. #!/usr/bin/awk
  2. # Hackish approach to get a machine-readable list of current matrix
  3. # synapse REST API endpoints from the official documentation at
  4. # https://github.com/matrix-org/synapse/raw/master/docs/workers.md
  5. #
  6. # invoke in shell with:
  7. # URL=https://github.com/matrix-org/synapse/raw/master/docs/workers.md
  8. # curl -L ${URL} | awk -f workers-doc-to-yaml.awk -
  9. function worker_stanza_append(string) {
  10. worker_stanza = worker_stanza string
  11. }
  12. function line_is_endpoint_url(line) {
  13. # probably API endpoint if it starts with white-space and ^ or /
  14. return (line ~ /^ +[\^\/].*\//)
  15. }
  16. # Put YAML marker at beginning of file.
  17. BEGIN {
  18. endpoint_conditional_comment = " # FIXME: ADDITIONAL CONDITIONS REQUIRED: to be enabled manually\n"
  19. }
  20. # Enable further processing after the introductory text.
  21. # Read each synapse worker section as record and its lines as fields.
  22. /Available worker applications/ {
  23. enable_parsing = 1
  24. # set record separator to markdown section header
  25. RS = "\n### "
  26. # set field separator to newline
  27. FS = "\n"
  28. }
  29. # Once parsing is active, this will process each section as record.
  30. enable_parsing {
  31. # Each worker section starts with a synapse.app.X headline
  32. if ($1 ~ /synapse\.app\./) {
  33. # get rid of the backticks and extract worker type from headline
  34. gsub("`", "", $1)
  35. gsub("synapse.app.", "", $1)
  36. worker_type = $1
  37. # initialize empty worker stanza
  38. worker_stanza = ""
  39. # track if any endpoints are mentioned in a specific section
  40. worker_has_urls = 0
  41. # some endpoint descriptions contain flag terms
  42. endpoints_seem_conditional = 0
  43. # also, collect a list of available workers
  44. workers = (workers ? workers "\n" : "") " - " worker_type
  45. # loop through the lines (2 - number of fields in record)
  46. for (i = 2; i < NF + 1; i++) {
  47. # copy line for gsub replacements
  48. line = $i
  49. # end all lines but the last with a linefeed
  50. linefeed = (i < NF - 1) ? "\n" : ""
  51. # line starts with white-space and a hash: endpoint block headline
  52. if (line ~ /^ +#/) {
  53. # copy to output verbatim, normalizing white-space
  54. gsub(/^ +/, "", line)
  55. worker_stanza_append(" " line linefeed)
  56. } else if (line_is_endpoint_url(line)) {
  57. # mark section for special output formatting
  58. worker_has_urls = 1
  59. # remove leading white-space
  60. gsub(/^ +/, "", line)
  61. api_endpoint_regex = line
  62. # FIXME: https://github.com/matrix-org/synapse/issues/new
  63. # munge inconsistent media_repository endpoint notation
  64. if (api_endpoint_regex == "/_matrix/media/") {
  65. api_endpoint_regex = "^" line
  66. }
  67. # FIXME: https://github.com/matrix-org/synapse/issues/7530
  68. # https://github.com/spantaleev/matrix-docker-ansible-deploy/pull/456#issuecomment-719015911
  69. if (api_endpoint_regex == "^/_matrix/client/(r0|v3|unstable)/auth/.*/fallback/web$") {
  70. worker_stanza_append(" # FIXME: possible bug with SSO and multiple generic workers\n")
  71. worker_stanza_append(" # see https://github.com/matrix-org/synapse/issues/7530\n")
  72. worker_stanza_append(" # " api_endpoint_regex linefeed)
  73. continue
  74. }
  75. # disable endpoints which specify complications
  76. if (endpoints_seem_conditional) {
  77. # only add notice if previous line didn't match
  78. if (!line_is_endpoint_url($(i - 1))) {
  79. worker_stanza_append(endpoint_conditional_comment)
  80. }
  81. worker_stanza_append(" # " api_endpoint_regex linefeed)
  82. } else {
  83. # output endpoint regex
  84. worker_stanza_append(" - " api_endpoint_regex linefeed)
  85. }
  86. # white-space only line?
  87. } else if (line ~ /^ *$/) {
  88. if (i > 3 && i < NF) {
  89. # print white-space lines unless 1st or last line in section
  90. worker_stanza_append(line linefeed)
  91. }
  92. # nothing of the above: the line is regular documentation text
  93. } else {
  94. # include this text line as comment
  95. worker_stanza_append(" # " line linefeed)
  96. # and take note of words hinting at additional conditions to be met
  97. if (line ~ /(^[Ii]f|care must be taken|can be handled for)/) {
  98. endpoints_seem_conditional = 1
  99. }
  100. }
  101. }
  102. if (worker_has_urls) {
  103. print "\nmatrix_synapse_workers_" worker_type "_endpoints:"
  104. print worker_stanza
  105. } else {
  106. # include workers without endpoints as well for reference
  107. print "\n# " worker_type " worker (no API endpoints) ["
  108. print worker_stanza
  109. print "# ]"
  110. }
  111. }
  112. }
  113. END {
  114. print "\nmatrix_synapse_workers_avail_list:"
  115. print workers | "sort"
  116. }
  117. # vim: tabstop=4 shiftwidth=4 expandtab autoindent