Skip to content

Commit

Permalink
feat: add colors using tput and secrets goals for git-secret (#7)
Browse files Browse the repository at this point in the history
* feat: add colors using tput and secrets goals for git-secret

* fix log tests

* try only doing color vars if tput is there
  • Loading branch information
basejump authored Jul 30, 2021
1 parent 19ec191 commit ac62175
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 12 deletions.
15 changes: 15 additions & 0 deletions makefiles/Shipkit-main.make
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions makefiles/env-goals.make
Original file line number Diff line number Diff line change
Expand Up @@ -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):
@:
Expand Down
62 changes: 57 additions & 5 deletions makefiles/secrets.make
Original file line number Diff line number Diff line change
Expand Up @@ -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 protected] $(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
4 changes: 2 additions & 2 deletions tests/secrets_gpg.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
2 changes: 1 addition & 1 deletion tests/semver.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ac62175

Please sign in to comment.