Skip to content

Commit

Permalink
⬆️ v0.2.1
Browse files Browse the repository at this point in the history
- Fixes logging false negative write errors
- Fixes creating b64 encoded secret files for secret types other than 'Opaque'
- Updates readme to be more useful
  • Loading branch information
matthewhartstonge committed Oct 12, 2017
1 parent 4ecf815 commit 3d5cbba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 `.`
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
15 changes: 9 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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{
Expand All @@ -111,7 +115,6 @@ func createSecretsFile(fp string, wpf string) error {
return nil
}


func main() {
logger := log.WithFields(log.Fields{
"method": "main",
Expand All @@ -134,4 +137,4 @@ func main() {
}

logger.Info("b64secrets file conversions completed!")
}
}

0 comments on commit 3d5cbba

Please sign in to comment.