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.

55 lines
1.4 KiB

  1. # -*- mode: shell-script -*-
  2. CONFIG_FILE=/etc/docker-auth/config.yml
  3. HOST_CONFIG_FILE="$SERVICE_CONFIGSTORE$CONFIG_FILE"
  4. ini_merge_str() {
  5. local cfg="$1" \
  6. cache_file="$CACHEDIR/$FUNCNAME.cache.$(p0 "$@" "$(cat "$HOST_CONFIG_FILE")" | md5_compat)" \
  7. result
  8. if [ -z "$cfg" ]; then
  9. return 0
  10. fi
  11. if [ -e "$cache_file" ]; then
  12. #debug "$FUNCNAME: SESSION cache hit $1"
  13. cat "$cache_file" || return 1
  14. return 0
  15. fi
  16. result="$(merge_yaml_str "$(cat "$HOST_CONFIG_FILE")" "$cfg")" || return 1
  17. e "$result" | tee "$cache_file" || return 1
  18. }
  19. ini_merge() {
  20. local result
  21. result=$(ini_merge_str "$(cat -)")
  22. e "$result" > "$HOST_CONFIG_FILE"
  23. }
  24. make_users_config() {
  25. local users_charm_cfg="$1"
  26. echo "users:"
  27. while read-0 user config; do
  28. echo " \"$user\":"
  29. password="$config"
  30. ##$(e "$config" | shyaml get-value password) || return 1
  31. bcrypt=$(e "$password" | htpasswd -niB "$user" | cut -f 2 -d ":")
  32. echo " password: \"$bcrypt\""
  33. done < <(e "$users_charm_cfg" | shyaml key-values-0)
  34. echo " \"\": {}" ## Allow anonymous
  35. }
  36. registry_config_hash() {
  37. debug "Adding config hash to enable recreating upon config change."
  38. config_hash=$(cat "$HOST_CONFIG_FILE" | md5_compat) || exit 1
  39. init-config-add "
  40. $MASTER_BASE_SERVICE_NAME:
  41. labels:
  42. - compose.config_hash=$config_hash
  43. "
  44. }