From ac621759beaf0d148ee097e6e8fd05d5c22dbc62 Mon Sep 17 00:00:00 2001 From: Joshua B Date: Fri, 30 Jul 2021 10:50:53 -0600 Subject: [PATCH] feat: add colors using tput and secrets goals for git-secret (#7) * feat: add colors using tput and secrets goals for git-secret * fix log tests * try only doing color vars if tput is there --- makefiles/Shipkit-main.make | 15 +++++++++ makefiles/env-goals.make | 8 ++--- makefiles/secrets.make | 62 ++++++++++++++++++++++++++++++++++--- tests/secrets_gpg.bats | 4 +-- tests/semver.bats | 2 +- 5 files changed, 79 insertions(+), 12 deletions(-) diff --git a/makefiles/Shipkit-main.make b/makefiles/Shipkit-main.make index 2ded2fd..e06400c 100644 --- a/makefiles/Shipkit-main.make +++ b/makefiles/Shipkit-main.make @@ -110,6 +110,13 @@ TPUT_SUFFIX := $(TPUT) sgr0 TPUT_RED := $(TPUT) setaf 1; TPUT_GREEN := $(TPUT) setaf 2; TPUT_YELLOW := $(TPUT) setaf 3; +TPUT_BLUE := $(TPUT) setaf 4; +TPUT_CYAN := $(TPUT) setaf 6; +cgreen := +cbold := +cnormal := +cblue := +ccyan := LOG_PREFIX ?= ===> # if not TPUT then blank out the vars @@ -119,6 +126,14 @@ TPUT_SUFFIX := TPUT_RED := TPUT_GREEN := TPUT_YELLOW := +TPUT_BLUE := +TPUT_CYAN := +else +cgreen := $(shell $(TPUT_GREEN)) +cbold := $(shell $(TPUT_PREFIX)) +cnormal := $(shell $(TPUT_SUFFIX)) +cblue := $(shell $(TPUT_BLUE)) +ccyan := $(shell $(TPUT_CYAN)) endif # end tput check define _log diff --git a/makefiles/env-goals.make b/makefiles/env-goals.make index b7cc349..1854107 100644 --- a/makefiles/env-goals.make +++ b/makefiles/env-goals.make @@ -2,14 +2,14 @@ # BUILD_ENV is used to to pass to gradle/liquibase and to build the database name etc.... BUILD_ENV = dev # MAKECMDGOALS has the list of all target goals that are passed into make cmd -ifeq (test-env,$(filter test-env,$(MAKECMDGOALS))) +ifeq (testenv,$(filter testenv,$(MAKECMDGOALS))) BUILD_ENV = test -else ifeq (seed,$(filter seed,$(MAKECMDGOALS))) - BUILD_ENV = seed +else ifeq (prod,$(filter prod,$(MAKECMDGOALS))) + BUILD_ENV = prod endif # dummy targets so we dont get the make[1]: Nothing to be done for `xxx'. -dummy_targets = dev seed test-env +dummy_targets = dev prod testenv .PHONY: $(dummy_targets) $(dummy_targets): @: diff --git a/makefiles/secrets.make b/makefiles/secrets.make index 14f3f93..3ed2a87 100644 --- a/makefiles/secrets.make +++ b/makefiles/secrets.make @@ -21,11 +21,63 @@ secrets.import-gpg-key: | _verify_BOT_EMAIL fi # gpg above --batch doesn't ask for prompt and -v is verbose -git-secret-version: $(GIT_SECRET_SH) +## run this to show help for secret goals +secrets.help: + echo + echo -e "${cbold}Git-secrets make tasks. see https://git-secret.io/ for more info on using installed version$(cnormal)\n" + echo -e "Targets:\n" + echo "$(ccyan)secrets.init $(cnormal)| initializes new project " + echo "$(ccyan)secrets.add email=jim@gmail.com $(cnormal)| adds an authorized user key, should only be by email that matched their public key " + echo "$(ccyan)secrets.add file=secret.env $(cnormal)| adds a file to the secrets" + echo "$(ccyan)secrets.hide $(cnormal)| encrypts and hides all the files in the secret list " + echo "$(ccyan)secrets.reveal $(cnormal)| decrytps all the files in the secret list " + echo "$(ccyan)secrets.remove file=abc.env $(cnormal)| removes a file to the secrets" + echo "$(ccyan)secrets.remove email=... $(cnormal)| removes an authroized user key" + echo "$(ccyan)secrets.list $(cnormal)| list files and authorized users" + echo "$(ccyan)secrets.clean $(cnormal)| removes all the hidden files" + echo + +# Shows the git-secret version +secrets.show-version: $(GIT_SECRET_SH) $(GIT_SECRET_SH) --version -secrets-encrypt: - @$(GIT_SECRET_SH) hide +# initializes the project +secrets.init: $(GIT_SECRET_SH) + $(GIT_SECRET_SH) init + +secrets.add: + if [ "$(file)" ]; then + $(GIT_SECRET_SH) add $(file) + elif [ "$(email)" ]; then + $(GIT_SECRET_SH) tell $(email) + else + echo "must set either the 'file' var or 'email' var" + fi + +secrets.remove: + if [ "$(file)" ]; then + $(GIT_SECRET_SH) remove $(file) + elif [ "$(email)" ]; then + $(GIT_SECRET_SH) removeperson $(email) + else + echo "must set either the 'file' var or 'email' var" + fi + +# alias to hide +secrets.encrypt: secrets.hide + +secrets.hide: $(GIT_SECRET_SH) + $(GIT_SECRET_SH) hide -d + +# alias to reveal +secrets.decrypt: secrets.reveal + +secrets.reveal: + $(GIT_SECRET_SH) reveal -p "$(GPG_PASS)" -secrets-decrypt: - @$(GIT_SECRET_SH) reveal -p "$(GPG_PASS)" +secrets.list: + echo "$(cgreen) -- Secret Files --" + $(GIT_SECRET_SH) list + echo + echo "$(cblue) -- Secret Users --" + $(GIT_SECRET_SH) whoknows diff --git a/tests/secrets_gpg.bats b/tests/secrets_gpg.bats index 0952e76..08d2b50 100644 --- a/tests/secrets_gpg.bats +++ b/tests/secrets_gpg.bats @@ -12,8 +12,8 @@ teardown() { PATH=$OLD_PATH } -@test 'make sure git-secret-version works' { - run make -f $FIXTURE_DIR/Makefile git-secret-version +@test 'make sure secrets.show-version works' { + run make -f $FIXTURE_DIR/Makefile secrets.show-version __debug "${status}" "${output}" "${lines[@]}" [ "$status" -eq 0 ] diff --git a/tests/semver.bats b/tests/semver.bats index 7e42280..00b7e1e 100644 --- a/tests/semver.bats +++ b/tests/semver.bats @@ -37,7 +37,7 @@ setup() { } -@test 'make sure git-secret-version works' { +@test 'make sure gsecrets.show-version works' { semverFile=$VERSION_FILENAME echo "version=1.0.1" > $semverFile