fork 0k-charms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
2.8 KiB

  1. #!/bin/bash
  2. exname=$(basename $0)
  3. prefix_cmd="
  4. . /etc/shlib
  5. include common
  6. include parse
  7. . ../lib/common
  8. depends compose
  9. "
  10. ##
  11. ## Mocks
  12. ##
  13. relation-get() {
  14. local key="$1"
  15. echo "$CFG" | shyaml get-value "$key" 2>/dev/null
  16. }
  17. export -f relation-get
  18. relation-set() {
  19. local key="$1" value="$2"
  20. echo "relation-set $key:" >&2
  21. echo "$value" | prefix " | " >&2
  22. }
  23. export -f relation-set
  24. get_service_relations() {
  25. printf "%s\0" "${RELATIONS[@]}"
  26. }
  27. export -f get_service_relations
  28. merge_yaml_str() {
  29. printf "<merge_yaml_str("
  30. printf "'%s', " "$@"
  31. printf ")>"
  32. }
  33. export -f merge_yaml_str
  34. compose() {
  35. printf "Calling: compose "
  36. printf "%s " "$*"
  37. echo
  38. }
  39. export -f compose
  40. yaml_key_val_str() {
  41. printf "%s: %s" "$1" "$2"
  42. }
  43. export -f yaml_key_val_str
  44. file_put() {
  45. echo "file_put $1"
  46. cat - | prefix " | "
  47. }
  48. export -f file_put
  49. docker() {
  50. echo "docker" "$@"
  51. echo stdin:
  52. cat - | prefix " | "
  53. }
  54. export -f docker
  55. config-add() {
  56. echo "config-add"
  57. echo "$1" | prefix " | "
  58. }
  59. export -f config-add
  60. mkdir() {
  61. echo "called: $FUNCNAME $@" >&2
  62. }
  63. export -f mkdir
  64. setfacl() {
  65. echo "called: $FUNCNAME $@" >&2
  66. }
  67. export -f setfacl
  68. chgrp() {
  69. echo "called: $FUNCNAME $@" >&2
  70. }
  71. export -f chgrp
  72. chmod() {
  73. echo "called: $FUNCNAME $@" >&2
  74. }
  75. export -f chmod
  76. cached_cmd_on_base_image() {
  77. echo "called: $FUNCNAME $@" >&2
  78. echo "stdout:" >&2
  79. echo "<GID>" | prefix " | " >&2
  80. echo "<GID>"
  81. }
  82. export -f cached_cmd_on_base_image
  83. ##
  84. ## cert-provider
  85. ##
  86. try "
  87. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  88. export CONFIGSTORE='\$CONFIGSTORE'
  89. export BASE_SERVICE_NAME='\$BASE_SERVICE_NAME'
  90. export MASTER_TARGET_SERVICE_NAME='\$MASTER_TARGET_SERVICE_NAME'
  91. DOMAIN=www.example.com
  92. DOCKER_SITE_PATH=/var/www/\$DOMAIN
  93. CFG='
  94. ssl:
  95. foo: |
  96. a
  97. b
  98. '
  99. RELATIONS=()
  100. apache_vhost_create" "unknown cert key"
  101. is errlvl 1
  102. is err reg 'Error: .*cert-provider.*'
  103. try "
  104. export SERVICE_CONFIGSTORE='\$SERVICE_CONFIGSTORE'
  105. export CONFIGSTORE='\$CONFIGSTORE'
  106. export DATASTORE='\$DATASTORE'
  107. export BASE_SERVICE_NAME='\$BASE_SERVICE_NAME'
  108. export MASTER_TARGET_SERVICE_NAME='\$MASTER_TARGET_SERVICE_NAME'
  109. DOMAIN=www.example.com
  110. DOCKER_SITE_PATH=/var/www/\$DOMAIN
  111. CFG='
  112. ssl:
  113. foo: 12
  114. '
  115. RELATIONS=(cert-provider foo a True)
  116. apache_vhost_create" "known cert key"
  117. is errlvl 0
  118. is err part "\
  119. relation-set apache-custom-rules:
  120. | - |
  121. | ## Auto-redirection from http to https
  122. | RewriteEngine On
  123. | RewriteCond %{HTTPS} off
  124. | RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,QSA]
  125. |"
  126. is out reg 'Calling: compose .*foo: options: <merge_yaml_str\(.a., .12., )>.*run --rm --service-ports foo.*'
  127. is out part 'config-add
  128. | services:
  129. | $MASTER_TARGET_SERVICE_NAME:
  130. | volumes:
  131. | - $DATASTORE/foo/etc/letsencrypt:/etc/letsencrypt:ro'