mirror of https://github.com/markbates/pkger.git
remove hepa dep
This commit is contained in:
parent
8dd173a225
commit
cc9286edec
|
@ -1,14 +1,5 @@
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI=
|
|
||||||
github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc=
|
|
||||||
github.com/markbates/hepa v0.0.0-20190718154049-1d900199db5b h1:ns0oO2sMEoFJMmrbiWzGQO5AR3GgqfYRAos0gz8C0Cw=
|
github.com/markbates/hepa v0.0.0-20190718154049-1d900199db5b h1:ns0oO2sMEoFJMmrbiWzGQO5AR3GgqfYRAos0gz8C0Cw=
|
||||||
github.com/markbates/hepa v0.0.0-20190718154049-1d900199db5b/go.mod h1:jHlCX3RNqF+epcY1FxjLyDGzr3l9+mNCh3YDDw6BFvY=
|
github.com/markbates/hepa v0.0.0-20190718154049-1d900199db5b/go.mod h1:jHlCX3RNqF+epcY1FxjLyDGzr3l9+mNCh3YDDw6BFvY=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
@ -18,7 +9,5 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -5,7 +5,6 @@ go 1.13
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
github.com/kr/pretty v0.1.0 // indirect
|
||||||
github.com/markbates/hepa v0.0.0-20190718154049-1d900199db5b
|
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -7,8 +7,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/markbates/hepa v0.0.0-20190718154049-1d900199db5b h1:ns0oO2sMEoFJMmrbiWzGQO5AR3GgqfYRAos0gz8C0Cw=
|
|
||||||
github.com/markbates/hepa v0.0.0-20190718154049-1d900199db5b/go.mod h1:jHlCX3RNqF+epcY1FxjLyDGzr3l9+mNCh3YDDw6BFvY=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/markbates/hepa"
|
"github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa"
|
||||||
"github.com/markbates/hepa/filters"
|
"github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa/filters"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Info represents details about the directory/package
|
// Info represents details about the directory/package
|
||||||
|
|
|
@ -3,8 +3,8 @@ package here
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/markbates/hepa"
|
"github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa"
|
||||||
"github.com/markbates/hepa/filters"
|
"github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa/filters"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Module struct {
|
type Module struct {
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2019 Mark Bates
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -0,0 +1,35 @@
|
||||||
|
package hepa
|
||||||
|
|
||||||
|
import "bytes"
|
||||||
|
|
||||||
|
type Filter interface {
|
||||||
|
Filter([]byte) ([]byte, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type FilterFunc func([]byte) ([]byte, error)
|
||||||
|
|
||||||
|
func (f FilterFunc) Filter(b []byte) ([]byte, error) {
|
||||||
|
return f(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Rinse(p Purifier, s, r []byte) Purifier {
|
||||||
|
return WithFunc(p, func(b []byte) ([]byte, error) {
|
||||||
|
b = bytes.ReplaceAll(b, s, r)
|
||||||
|
return b, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func Clean(p Purifier, s []byte) Purifier {
|
||||||
|
return WithFunc(p, func(b []byte) ([]byte, error) {
|
||||||
|
if bytes.Contains(b, s) {
|
||||||
|
return []byte{}, nil
|
||||||
|
}
|
||||||
|
return b, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func Noop() FilterFunc {
|
||||||
|
return func(b []byte) ([]byte, error) {
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package filters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var env = func() map[string]string {
|
||||||
|
m := map[string]string{}
|
||||||
|
|
||||||
|
for _, line := range os.Environ() {
|
||||||
|
kv := strings.Split(line, "=")
|
||||||
|
|
||||||
|
k, v := kv[0], kv[1]
|
||||||
|
kt, vt := strings.TrimSpace(k), strings.TrimSpace(v)
|
||||||
|
|
||||||
|
if len(kt) == 0 || len(vt) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch k {
|
||||||
|
case "GO111MODULE":
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch v {
|
||||||
|
case "true", "TRUE", "false", "FALSE", "null", "nil", "NULL":
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := strconv.Atoi(k); err == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, err := strconv.Atoi(v); err == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
m[k] = v
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}()
|
|
@ -0,0 +1,12 @@
|
||||||
|
package filters
|
||||||
|
|
||||||
|
type FilterFunc func([]byte) ([]byte, error)
|
||||||
|
|
||||||
|
func (f FilterFunc) Filter(b []byte) ([]byte, error) {
|
||||||
|
return f(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
type dir struct {
|
||||||
|
Dir string
|
||||||
|
Err error
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package filters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Golang() FilterFunc {
|
||||||
|
return func(b []byte) ([]byte, error) {
|
||||||
|
gp, err := gopath(home)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
b = bytes.ReplaceAll(b, []byte(gp.Dir), []byte("$GOPATH"))
|
||||||
|
|
||||||
|
gru, err := goroot(gp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
b = bytes.ReplaceAll(b, []byte(gru.Dir), []byte("$GOROOT"))
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func goroot(gp dir) (dir, error) {
|
||||||
|
gru, ok := os.LookupEnv("GOROOT")
|
||||||
|
if !ok {
|
||||||
|
if gp.Err != nil {
|
||||||
|
return gp, gp.Err
|
||||||
|
}
|
||||||
|
gru = filepath.Join(string(gp.Dir), "go")
|
||||||
|
}
|
||||||
|
return dir{
|
||||||
|
Dir: gru,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func gopath(home dir) (dir, error) {
|
||||||
|
gp, ok := os.LookupEnv("GOPATH")
|
||||||
|
if !ok {
|
||||||
|
if home.Err != nil {
|
||||||
|
return home, home.Err
|
||||||
|
}
|
||||||
|
gp = filepath.Join(string(home.Dir), "go")
|
||||||
|
}
|
||||||
|
return dir{
|
||||||
|
Dir: gp,
|
||||||
|
}, nil
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package filters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
var home = func() dir {
|
||||||
|
var d dir
|
||||||
|
home, ok := os.LookupEnv("HOME")
|
||||||
|
if !ok {
|
||||||
|
pwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
d.Err = err
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
home = pwd
|
||||||
|
}
|
||||||
|
d.Dir = home
|
||||||
|
|
||||||
|
return d
|
||||||
|
}()
|
||||||
|
|
||||||
|
func Home() FilterFunc {
|
||||||
|
return func(b []byte) ([]byte, error) {
|
||||||
|
if home.Err != nil {
|
||||||
|
return b, home.Err
|
||||||
|
}
|
||||||
|
return bytes.ReplaceAll(b, []byte(home.Dir), []byte("$HOME")), nil
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,29 @@
|
||||||
|
package filters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Secrets() FilterFunc {
|
||||||
|
return func(b []byte) ([]byte, error) {
|
||||||
|
for k, v := range env {
|
||||||
|
for _, s := range secretSuffixes {
|
||||||
|
if !strings.HasSuffix(k, s) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
b = bytes.ReplaceAll(b, []byte(v), []byte(mask()))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var secretSuffixes = []string{
|
||||||
|
"_KEY",
|
||||||
|
"_SECRET",
|
||||||
|
"_TOKEN",
|
||||||
|
"_PASSWORD",
|
||||||
|
"_PASS",
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package hepa
|
||||||
|
|
||||||
|
func WithFunc(p Purifier, fn FilterFunc) Purifier {
|
||||||
|
c := New()
|
||||||
|
c.parent = &p
|
||||||
|
c.filter = fn
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func With(p Purifier, f Filter) Purifier {
|
||||||
|
c := New()
|
||||||
|
c.parent = &p
|
||||||
|
c.filter = f
|
||||||
|
return c
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package hepa
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa/filters"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Purifier struct {
|
||||||
|
parent *Purifier
|
||||||
|
filter Filter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Purifier) Filter(b []byte) ([]byte, error) {
|
||||||
|
if p.filter == nil {
|
||||||
|
p.filter = filters.Home()
|
||||||
|
}
|
||||||
|
b, err := p.filter.Filter(b)
|
||||||
|
if err != nil {
|
||||||
|
return b, err
|
||||||
|
}
|
||||||
|
if p.parent != nil {
|
||||||
|
return p.parent.Filter(b)
|
||||||
|
}
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Purifier) Clean(r io.Reader) ([]byte, error) {
|
||||||
|
bb := &bytes.Buffer{}
|
||||||
|
|
||||||
|
if p.filter == nil {
|
||||||
|
if p.parent != nil {
|
||||||
|
return p.parent.Clean(r)
|
||||||
|
}
|
||||||
|
_, err := io.Copy(bb, r)
|
||||||
|
return bb.Bytes(), err
|
||||||
|
}
|
||||||
|
|
||||||
|
home := filters.Home()
|
||||||
|
reader := bufio.NewReader(r)
|
||||||
|
for {
|
||||||
|
input, _, err := reader.ReadLine()
|
||||||
|
if err != nil && err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
input, err = p.Filter(input)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
input, err = home(input)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
bb.Write(input)
|
||||||
|
// if len(input) > 0 {
|
||||||
|
bb.Write([]byte("\n"))
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
return bb.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() Purifier {
|
||||||
|
return Purifier{}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package hepa
|
||||||
|
|
||||||
|
// Version of hepa
|
||||||
|
const Version = "v0.0.1"
|
Loading…
Reference in New Issue