Skip to content
This repository has been archived by the owner on May 22, 2019. It is now read-only.

Commit

Permalink
Vault patch (#181)
Browse files Browse the repository at this point in the history
* Vault patch.

* Add warning message if vault isn't installed or logged in.
  • Loading branch information
sjparkinson authored May 25, 2017
1 parent 80c1c52 commit f53914d
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,35 @@ ENV_MSG_CANT_GET = "Error: Cannot get config vars for this service. Check you ar
@if [ ! -z $(CIRCLECI) ]; then (echo $(ENV_MSG_CIRCLECI) && exit 1); fi
@$(call CONFIG_VARS,development,env) > .env && perl -pi -e 's/="(.*)"/=\1/' .env && $(DONE) || (echo $(ENV_MSG_CANT_GET) && rm .env && exit 1);

# replace .env with this .env2 when you want to use the vault instead of config-vars
.env-vault:
# replace .env with this when you want to use the vault instead of config-vars
.env-vault: vault-cli
@if [[ $(shell grep --count *.env* .gitignore) -eq 0 ]]; then (echo $(ENV_MSG_IGNORE_ENV) && exit 1); fi
@if [ ! -e package.json ]; then (echo $(ENV_MSG_PACKAGE_JSON) && exit 1); fi
@if [ ! -z $(CIRCLECI) ]; then (echo $(ENV_MSG_CIRCLECI) && exit 1); fi
# get development config from the vault
# - the tail command removes the first three lines (vault metadata)
# - the 1st sed command removes the last line (empty line)
# - the 2nd sed command changes remaining lines to key=value format
@vault auth --method github \
&& vault read secret/teams/next/$(APP_NAME)/development \
# - the sed command removes the last line (empty line)
# - the perl command changes remaining lines to key=value format
@vault read secret/teams/next/$$(echo $(APP_NAME) | sed 's/^ft-//')/development \
| tail -n +4 \
| sed -e '$$ d' \
| sed -E 's/^([^ ]*)[[:blank:]]*([^ ].*)$$/\1=\2/' \
| perl -pe 's/^([^ \t]+)\s+(.+)$$/\1=\2/' \
> .env
@vault read secret/teams/next/next-globals/development \
| tail -n +4 \
| sed -e '$$ d' \
| perl -pe 's/^([^ \t]+)\s+(.+)$$/\1=\2/' \
>> .env
@$(DONE)

MSG_HEROKU_CLI = "Please make sure the Heroku CLI toolbelt is installed - see https://toolbelt.heroku.com/. And make sure you are authenticated by running ‘heroku login’. If this is not an app, delete Procfile."
heroku-cli:
@if [ -e Procfile ]; then heroku auth:whoami &>/dev/null || (echo $(MSG_HEROKU_CLI) && exit 1); fi

MSG_VAULT_CLI = "Please make sure the Vault CLI is installed - see https://github.com/Financial-Times/vault/wiki/Getting-Started. And make sure you are authenticated."
vault-cli:
@if [ -e Procfile ] && [[ $$(vault token-lookup 2>&1 | grep -c error) -gt 0 ]]; then (echo $(MSG_VAULT_CLI) && exit 1); fi

# VERIFY SUB-TASKS

_verify_eslint:
Expand Down

0 comments on commit f53914d

Please sign in to comment.