Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat secret internal key #10

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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"
Expand All @@ -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}
Expand All @@ -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 ./...)

Expand Down
28 changes: 23 additions & 5 deletions pkg/templating/templating.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
}
Loading