From 6540a2dbbf588bb948f59f3be882a5267ba4c9e7 Mon Sep 17 00:00:00 2001 From: Sebastian Rau Date: Mon, 2 Oct 2023 11:05:04 +0200 Subject: [PATCH 1/2] feat(makeile tool) --- Makefile | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 51de954..2706b28 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ BUILD_DIR = build APP = deployer CMD= cmd/deployer/main.go +APP_TOOL = secretSealer +CMD_TOOL= cmd/secretSealer/main.go MC_DIR = build/bin LOG_DIR= build/log GIT_VER=$(shell git rev-parse HEAD) @@ -11,7 +13,7 @@ LDFLAGS=-ldflags "-X main.version=${GIT_VER}" # Build the project -all: +help: @echo "cmd:" @echo "" @echo " app build all app for all os" @@ -24,8 +26,9 @@ all: @echo " clean remove dut binarys" @echo " distclean remove build folder" -app: app.windows app.windows64 app.darwin64 app.darwinArm app.linux64 +all: app tool +app: app.windows app.windows64 app.darwin64 app.darwinArm app.linux64 app.windows: GOOS=windows GOARCH=386 go build ${LDFLAGS} -o ${BUILD_DIR}/${APP}.exe -v ${CMD} @@ -43,6 +46,26 @@ app.linux64: GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o ${BUILD_DIR}/${APP}-linux -v ${CMD} + + +tool: tool.windows tool.windows64 tool.darwin64 tool.darwinArm tool.linux64 + +tool.windows: + GOOS=windows GOARCH=386 go build ${LDFLAGS} -o ${BUILD_DIR}/${APP_TOOL}.exe -v ${CMD_TOOL} + +tool.windows64: + GOOS=windows GOARCH=amd64 go build ${LDFLAGS} -o ${BUILD_DIR}/${APP_TOOL}64.exe -v ${CMD_TOOL} + +tool.darwin64: + GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o ${BUILD_DIR}/${APP_TOOL}-darwin -v ${CMD_TOOL} + +tool.darwinArm: + GOOS=darwin GOARCH=arm64 go build ${LDFLAGS} -o ${BUILD_DIR}/${APP_TOOL}-darwin-arm -v ${CMD_TOOL} + +tool.linux64: + GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o ${BUILD_DIR}/${APP_TOOL}-linux -v ${CMD_TOOL} + + lint: golint -set_exit_status $(shell go list ./...) From f470c8be3a723ba984408c3da1ec143337f8c809 Mon Sep 17 00:00:00 2001 From: Sebastian Rau Date: Mon, 2 Oct 2023 11:10:35 +0200 Subject: [PATCH 2/2] feat(secrets): added global secrets key --- pkg/templating/templating.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pkg/templating/templating.go b/pkg/templating/templating.go index 652e039..068b040 100644 --- a/pkg/templating/templating.go +++ b/pkg/templating/templating.go @@ -13,6 +13,13 @@ import ( yaml "gopkg.in/yaml.v3" ) +type TemplateConfig struct { + active bool + globalSecretKey []byte +} + +var templateCfg TemplateConfig + func add(a, b int) int { return a + b } @@ -39,13 +46,19 @@ func arrayJoin(array []interface{}, separator string, addLast bool) string { } func secret(secretText string, keyFile string) string { - secretFile, err := os.Open(keyFile) - if err != nil { - return "" + var keyBytes []byte + + if templateCfg.active { + keyBytes = templateCfg.globalSecretKey + } else { + secretFile, err := os.Open(keyFile) + if err != nil { + return "" + } + defer secretFile.Close() + keyBytes, _ = io.ReadAll(secretFile) } - defer secretFile.Close() - keyBytes, _ := io.ReadAll(secretFile) return Decrypt(secretText, keyBytes) } @@ -100,3 +113,8 @@ func ParseTemplateJsonData(templ string, data string) ([]byte, error) { return tpl.Bytes(), nil } + +func ActivateGlobalConfig(key []byte) { + templateCfg.active = true + templateCfg.globalSecretKey = key +}