-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Julien Bouyoud <jBouyoud@users.noreply.github.com>
- Loading branch information
Showing
31 changed files
with
633 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
/tests/coverage/ | ||
/node_modules/ | ||
/repository/ | ||
/.bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -eu | ||
|
||
# Create temporary directory | ||
TMP_DIR="${HELM_CONFIG_SCHEME_TMP_DIR:-$(mktemp -d)}" | ||
|
||
YQ_PATH="${HELM_PLUGIN_DIR}/.bin/" | ||
|
||
_trap_hook() { | ||
unset_subst_args | ||
rm -rf "${TMP_DIR}" | ||
} | ||
|
||
_yq() { | ||
if [ -f "${YQ_PATH}/yq" ]; then | ||
"${YQ_PATH}/yq" "$@" | ||
else | ||
"${YQ_PATH}/yq.exe" "$@" | ||
fi | ||
} | ||
|
||
downloader() { | ||
if [ $# -ne 2 ]; then | ||
log_error "[downloader] Not able to download config, missing args" | ||
exit 2 | ||
fi | ||
uri="${1}" | ||
parent_process_cmd_line="${2}" | ||
|
||
case "${uri}" in | ||
"config://"*) ;; | ||
|
||
*) | ||
log_error "[downloader] URI '${uri}' not supported" | ||
exit 2 | ||
;; | ||
esac | ||
|
||
scheme_name=$(printf '%s' "${uri}" | sed 's!config://!!') | ||
|
||
if ! repository_scheme_exists "${scheme_name}"; then | ||
log_error "[downloader] Scheme '${scheme_name}' doesn't exists" | ||
exit 2 | ||
fi | ||
|
||
# build parameters | ||
export_subst_args "${parent_process_cmd_line}" | ||
|
||
idx=0 | ||
repository_view_scheme "${scheme_name}" | while read -r file_template; do | ||
log_info "[downloader] Looking for '${file_template}'..." | ||
|
||
eval "file=${file_template}" | ||
# shellcheck disable=SC2154 | ||
file_content="$( (_file_get "${file}" || printf ''))" | ||
|
||
if [ -z "${file_content}" ]; then | ||
log_info "[downloader] Ignored config source : ${file}" | ||
else | ||
log_info "[downloader] Loaded config source : ${file}" | ||
printf '%s\n' "${file_content}" >"${TMP_DIR}/file-${idx}" | ||
idx=$((idx + 1)) | ||
fi | ||
done | ||
|
||
if [ "$(find "${TMP_DIR}" -type f | wc -l)" -le 1 ]; then | ||
cat "${TMP_DIR}/file-0" 2>/dev/null || printf '' | ||
else | ||
_yq merge -x "${TMP_DIR}"/file-* | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -eu | ||
|
||
# Path to current directory | ||
SCRIPT_DIR="$(dirname "$0")" | ||
|
||
if [ "$(uname)" = "Darwin" ]; then | ||
if ! command -v realpath >/dev/null; then | ||
brew install coreutils | ||
fi | ||
fi | ||
|
||
YQ_PATH="${HELM_PLUGIN_DIR}/.bin/" | ||
mkdir -p "${YQ_PATH}" | ||
|
||
YQ_DEFAULT_VERSION="3.4.1" | ||
YQ_VERSION="${YQ_VERSION:-"${YQ_DEFAULT_VERSION}"}" | ||
|
||
YQ_PLATFORM="windows" | ||
if [ "$(uname)" = "Darwin" ]; then | ||
YQ_PLATFORM="darwin" | ||
elif [ "$(uname)" = "Linux" ]; then | ||
YQ_PLATFORM="linux" | ||
fi | ||
|
||
YQ_ARCH="386" | ||
if [ "$(uname -m)" = "x86_64" ]; then | ||
YQ_ARCH="amd64" | ||
fi | ||
|
||
YQ_SUFFIX="" | ||
if [ "${YQ_PLATFORM}" = "windows" ]; then | ||
YQ_SUFFIX=".exe" | ||
fi | ||
|
||
YQ_URL="${YQ_URL:-"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_${YQ_PLATFORM}_${YQ_ARCH}${YQ_SUFFIX}"}" | ||
|
||
# shellcheck disable=SC2034 | ||
YQ_SHA_darwin_amd64="5553d4640550debed5213a5eb6016d3a3485ca8a36e9c71996610280755d5a50" | ||
# shellcheck disable=SC2034 | ||
YQ_SHA_linux_368="ba57700f41cf21bf019af0eec47cf9884f70c25bc5abb0f3347bd42f19609739" | ||
# shellcheck disable=SC2034 | ||
YQ_SHA_linux_amd64="adbc6dd027607718ac74ceac15f74115ac1f3caef68babfb73246929d4ffb23c" | ||
# shellcheck disable=SC2034 | ||
YQ_SHA_windows_368="6292e14b0c199f2bd33e18a8bfe67f100084837163e1e2bc4934bcd7990a5087" | ||
# shellcheck disable=SC2034 | ||
YQ_SHA_windows_amd64="987d31d3a9b75f9cb0f202173aab033d333d2406ba2caa7dba9d16a5204c2167" | ||
|
||
YQ_SHA_DEFAULT_NAME="YQ_SHA_${YQ_PLATFORM}_${YQ_ARCH}" | ||
eval YQ_SHA_DEFAULT="\$${YQ_SHA_DEFAULT_NAME}" | ||
YQ_SHA="${YQ_SHA:-"${YQ_SHA_DEFAULT}"}" | ||
|
||
RED='\033[0;31m' | ||
NOC='\033[0m' | ||
|
||
get_sha_256() { | ||
if [ ! -f "${1}" ]; then | ||
res='' | ||
elif command -v sha256sum >/dev/null; then | ||
res=$(sha256sum "$1") | ||
elif command -v shasum >/dev/null; then | ||
res=$(shasum -a 256 "$1") | ||
else | ||
res='' | ||
fi | ||
|
||
echo "$res" | cut -d ' ' -f 1 | ||
} | ||
|
||
# shellcheck source=scripts/lib/http.sh | ||
. "${SCRIPT_DIR}/lib/http.sh" | ||
|
||
if [ -n "${SKIP_YQ_INSTALL+x}" ] && [ "${SKIP_YQ_INSTALL}" = "true" ]; then | ||
echo "Skipping yq installation." | ||
exit 0 | ||
fi | ||
|
||
YQ_SHA256="$(get_sha_256 "${YQ_PATH}")" | ||
|
||
if [ "${YQ_SHA256}" != "${YQ_SHA}" ] || [ "${YQ_SHA256}" = "" ]; then | ||
echo "Installing/Upgrading yq dependency..." | ||
|
||
if ! download "${YQ_URL}" >/tmp/yq; then | ||
printf "${RED}%s${NOC}\n" "Can't download yq ..." | ||
exit 1 | ||
fi | ||
|
||
YQ_SHA256="$(get_sha_256 /tmp/yq)" | ||
if [ "${YQ_SHA256}" = "${YQ_SHA}" ] || [ "${YQ_SHA256}" = "" ]; then | ||
chmod +x /tmp/yq | ||
mv /tmp/yq "${YQ_PATH}/yq${YQ_SUFFIX}" | ||
else | ||
printf "${RED}%s${NOC}\n" "Checksum mismatch : expected ${YQ_SHA} but was ${YQ_SHA256}" | ||
if [ "${YQ_VERSION}" != "${YQ_DEFAULT_VERSION}" ]; then | ||
printf "${RED}%s${NOC}\n" "Forgot to set YQ_SHA?" | ||
fi | ||
echo "Ignoring ..." | ||
fi | ||
rm -f /tmp/yq | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -eu | ||
|
||
# shellcheck source=scripts/lib/file/local.sh | ||
. "${SCRIPT_DIR}/lib/file/local.sh" | ||
|
||
# shellcheck source=scripts/lib/file/custom.sh | ||
. "${SCRIPT_DIR}/lib/file/custom.sh" | ||
|
||
_file_get_protocol() { | ||
case "$1" in | ||
*://*) | ||
echo "custom" | ||
;; | ||
*) | ||
echo "local" | ||
;; | ||
esac | ||
} | ||
|
||
_file_get() { | ||
file_type=$(_file_get_protocol "${1}") | ||
|
||
_file_"${file_type}"_get "$@" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env sh | ||
|
||
_file_custom_get() { | ||
helm template "${SCRIPT_DIR}/lib/file/helm-values-getter" -f "${1}" | | ||
sed -E -e "s/^# Source: .+$//" -e "s/^---$//" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
apiVersion: v2 | ||
name: helm-values-getter | ||
version: 1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{- .Values | toYaml -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env sh | ||
|
||
set -eu | ||
|
||
_file_local_get() { | ||
cat "${1}" 2>/dev/null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.