Skip to content

Instantly share code, notes, and snippets.

@brightzheng100
Created January 3, 2019 02:38
Show Gist options
  • Save brightzheng100/de0b56f69e0e82b77c8c187a5891a231 to your computer and use it in GitHub Desktop.
Save brightzheng100/de0b56f69e0e82b77c8c187a5891a231 to your computer and use it in GitHub Desktop.
credhub-interpolate.yml
# The inputs, outputs, params, filename, and filepath
# of this task file are part of its semantically versioned API.
# See our documentation for a detailed discussion of our semver API.
# See www.semver.org for an explanation of semantic versioning.
# code_snippet credhub-interpolate start yaml
---
platform: linux
inputs:
- name: files
# contains YAML files with extension `.yml`
# each one of these files will have their values interpolated from credhub
# For some example, run: `credhub interpolate --help` (minimum version >= 2.1.0 required)
outputs:
- name: interpolated-files
#contains all the *.yml files from `files/` input but after interpolation
# all params are required to be filled out
params:
# credentials to talk to credhub server
CREDHUB_CA_CERT:
CREDHUB_CLIENT:
CREDHUB_SECRET:
CREDHUB_SERVER:
# prefix of CredHub's namespace used by credhub interpolate
PREFIX:
# optional, if you have subfolder(s) to interpolate, set them here
INTERPOLATE_FOLDERS:
run:
path: bash
args:
- "-c"
- |
cat /var/version && echo ""
set -eux
credhub --version
if [ -z "$PREFIX" ]; then
echo "Please specify a PREFIX. It is required."
exit 1
fi
# root folder first
for file in files/*.yml; do
[ -f "$file" ] || continue
echo "interpolating $file"
credhub interpolate --prefix "$PREFIX" --file "$file" > interpolated-files/"$(basename "$file")"
done
# subfoler(s), if any
if [ ! -z "$INTERPOLATE_FOLDERS" ]; then
IFS=',' read -a subfolders <<< $(echo $INTERPOLATE_FOLDERS | tr -d '[]' | tr -d '"')
if [ ! ${#subfolders[@]} -eq 0 ]; then
for folder in ${subfolders[@]}; do
for file in files/$folder/*.yml; do
[ -f "$file" ] || continue
mkdir -p "interpolated-files/$folder"
credhub interpolate --prefix "$PREFIX" --file "$file" > interpolated-files/$folder/"$(basename "$file")"
done
done
fi
fi
# code_snippet credhub-interpolate end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment