Skip to content

Commit

Permalink
Initial Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
deedubs committed Mar 13, 2019
1 parent bed6fcf commit f0843b8
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Binaries for programs and plugins
bin
*.exe
*.exe~
*.dll
Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
GOFILES = $(shell find . -name '*.go' -not -path './vendor/*')
GOPACKAGES = $(shell go list ./... | grep -v /vendor/)
LOCAL_BIN = $(shell pwd)/bin

default: build

bin/gox:
GOBIN=$(LOCAL_BIN) go get github.com/mitchellh/gox

bin/redakt_linux_amd64 bin/redakt_darwin_amd64 bin/redakt_windows_amd64.exe: bin/gox $(GOFILES)
$(LOCAL_BIN)/gox -osarch "linux/amd64 darwin/amd64 windows/amd64" -output "bin/redakt_{{.OS}}_{{.Arch}}" github.com/massiveco/redakt

build: bin/redakt_linux_amd64 bin/redakt_darwin_amd64 bin/redakt_windows_amd64.exe
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# redakt

Strip sensitive content out of YAML files

## Example Usage

> kustomize build | redakt --kind Namespace | kubectl diff
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module github.com/massiveco/redakt

require (
github.com/mitchellh/gox v1.0.0 // indirect
gopkg.in/yaml.v2 v2.2.2
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8=
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/mitchellh/gox v1.0.0 h1:7ENCygwtc/7barDq96k0JPZhvrpHO/7oihNahmrmAhg=
github.com/mitchellh/gox v1.0.0/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
46 changes: 46 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"bufio"
"flag"
"fmt"
"os"

"gopkg.in/yaml.v2"
)

var redactedFlags redactFlags

func init() {

flag.Var(&redactedFlags, "kind", "Kubernetes kind to ignore")

flag.Parse()
}
func main() {
reader := bufio.NewScanner(os.Stdin)
reader.Split(splitOnDashes)

for reader.Scan() {
manifest := reader.Text()
obj := manifestStub{}
yaml.Unmarshal([]byte(manifest), &obj)

if contains(redactedFlags, obj.Kind) {
continue
}

fmt.Fprint(os.Stdout, manifest)
}
fmt.Fprintln(os.Stdout)
}

// contains tells whether a contains x.
func contains(a []string, x string) bool {
for _, n := range a {
if x == n {
return true
}
}
return false
}
23 changes: 23 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import "strings"

type redactFlags []string

func (rf *redactFlags) String() string {
return strings.Join(*rf, ", ")
}

func (rf *redactFlags) Set(value string) error {
*rf = append(*rf, value)
return nil
}

type manifestStub struct {
Kind string
Metadata manifestMetadata
}

type manifestMetadata struct {
Name string
}
18 changes: 18 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import "strings"

var sep = []byte("---")

func splitOnDashes(data []byte, atEOF bool) (int, []byte, error) {
if atEOF && len(data) == 0 {
return 0, nil, nil
}
if i := strings.Index(string(data), "---"); i >= 0 {
return i + 3, append(data[0:i], sep...), nil
}
if atEOF {
return len(data), data, nil
}
return 0, nil, nil
}

0 comments on commit f0843b8

Please sign in to comment.