Matrix Docker Ansible eploy
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

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