From 3d5cbbae4fe54580f8cf379238cc98d24f8eefb3 Mon Sep 17 00:00:00 2001 From: Matthew Hartstonge Date: Fri, 13 Oct 2017 00:00:11 +1300 Subject: [PATCH] :arrow_up: v0.2.1 - Fixes logging false negative write errors - Fixes creating b64 encoded secret files for secret types other than 'Opaque' - Updates readme to be more useful --- CHANGELOG.md | 5 +++++ README.md | 14 +++++++------- main.go | 15 +++++++++------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3de26b..6755217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # b64secrets changelog +## v0.2.1 +- Fixes logging false negative write errors +- Fixes creating b64 encoded secret files for secret types other than 'Opaque' +- Updates readme to be more useful + ## v0.2.0 - Added logging - Changed to use a recursive glob from `.` diff --git a/README.md b/README.md index 5ad637e..3275fc4 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,16 @@ I love Infrastructure as Code (IaC). It drove me nuts that k8s secret values in secret files had to have values in base64 encoding. -For now, this little utility serves my purposes by globbing recursively with the pattern -`./**/*.yml` writing the encoded secrets to `./**/*.base64.yml` ready for uploading to a k8s -cluster via `kubectl` commands. +This little utility globs recursively with the pattern `./**/*.yml` writing the encoded secrets +to `./**/*.base64.yml` ready for uploading to a k8s cluster via applicable `kubectl` commands. ## Usage -in a given directory containing `secrets-*.yml` files, simply run: +in a given directory containing `*.yml` files, simply run: ```sh $ b64secrets +INFO[0000] b64secrets is converting secrets.. method=main +INFO[0000] Created conformed secrets file conformedPath="super-secrets-development.base64.yml" method=createSecretsFile originalPath="config\\super-secrets-development.yml" +INFO[0000] Created conformed secrets file conformedPath="/secrets/within/a/folder/finds-love.base64.yml" method=createSecretsFile originalPath="secrets/within/a/folder/finds-love.yml" +INFO[0000] b64secrets file conversions completed! method=main ``` - -## Disclaimer -Use at your own risk! \ No newline at end of file diff --git a/main.go b/main.go index fddcc8f..e8b5100 100644 --- a/main.go +++ b/main.go @@ -54,7 +54,9 @@ func createSecretsFile(fp string, wpf string) error { secretDefinition := models.Secret{} yaml.Unmarshal([]byte(doc), &secretDefinition) - if secretDefinition.Kind != "Secret" && secretDefinition.Type != "Opaque" { + if secretDefinition.Kind != "Secret" { + continue + } else if secretDefinition.Type != "Opaque" { continue } @@ -99,9 +101,11 @@ func createSecretsFile(fp string, wpf string) error { // Flush file to disk err = base64SecretsFile.Sync() - logger.WithFields(log.Fields{ - "error": err, - }).Error("file write failure") + if err != nil { + logger.WithFields(log.Fields{ + "error": err, + }).Error("file write failure") + } } logger.WithFields(log.Fields{ @@ -111,7 +115,6 @@ func createSecretsFile(fp string, wpf string) error { return nil } - func main() { logger := log.WithFields(log.Fields{ "method": "main", @@ -134,4 +137,4 @@ func main() { } logger.Info("b64secrets file conversions completed!") -} \ No newline at end of file +}