forked from mirror/pkger
Merge pull request #102 from requaos/requaos/gzip
Remove hepa library for revision at a later date
This commit is contained in:
commit
0273362499
39
README.md
39
README.md
|
@ -24,9 +24,10 @@ Paths:
|
|||
* Packages can specified in at the beginning of a path with a `:` seperator.
|
||||
github.com/markbates/pkger:/cmd/pkger/main.go
|
||||
* There are no relative paths. All paths are absolute to the modules root.
|
||||
* Fully-qualified paths are embedded into the metadata of your static assets. If this behavior is undesirable, a preference is to build in a containerized environ, like docker, where the path strings are not ex-filtrating data about your development environment.
|
||||
|
||||
```
|
||||
"github.com/gobuffalo/buffalo:/go.mod" => $GOPATH/pkg/mod/github.com/gobuffalo/buffalo@v0.14.7/go.mod
|
||||
"github.com/gobuffalo/buffalo:/go.mod" => /go/pkg/mod/github.com/gobuffalo/buffalo@v0.14.7/go.mod
|
||||
```
|
||||
|
||||
## CLI
|
||||
|
@ -284,26 +285,26 @@ $ pkger parse
|
|||
".": [
|
||||
{
|
||||
"file": {
|
||||
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/foo/bar/baz",
|
||||
"Abs": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/foo/bar/baz",
|
||||
"Path": {
|
||||
"Pkg": "app",
|
||||
"Name": "/foo/bar/baz"
|
||||
},
|
||||
"Here": {
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"Dir": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"ImportPath": "app",
|
||||
"Module": {
|
||||
"Path": "app",
|
||||
"Main": true,
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
|
||||
"Dir": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"GoMod": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
|
||||
"GoVersion": "1.13"
|
||||
},
|
||||
"Name": "main"
|
||||
}
|
||||
},
|
||||
"pos": {
|
||||
"Filename": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/main.go",
|
||||
"Filename": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/main.go",
|
||||
"Offset": 629,
|
||||
"Line": 47,
|
||||
"Column": 27
|
||||
|
@ -313,26 +314,26 @@ $ pkger parse
|
|||
},
|
||||
{
|
||||
"file": {
|
||||
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/foo/bar/baz/biz.txt",
|
||||
"Abs": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/foo/bar/baz/biz.txt",
|
||||
"Path": {
|
||||
"Pkg": "app",
|
||||
"Name": "/foo/bar/baz/biz.txt"
|
||||
},
|
||||
"Here": {
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"Dir": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"ImportPath": "app",
|
||||
"Module": {
|
||||
"Path": "app",
|
||||
"Main": true,
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
|
||||
"Dir": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"GoMod": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
|
||||
"GoVersion": "1.13"
|
||||
},
|
||||
"Name": "main"
|
||||
}
|
||||
},
|
||||
"pos": {
|
||||
"Filename": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/main.go",
|
||||
"Filename": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/main.go",
|
||||
"Offset": 706,
|
||||
"Line": 51,
|
||||
"Column": 25
|
||||
|
@ -388,38 +389,38 @@ $ pkger list -json
|
|||
"ImportPath": "app",
|
||||
"Files": [
|
||||
{
|
||||
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
|
||||
"Abs": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
|
||||
"Path": {
|
||||
"Pkg": "app",
|
||||
"Name": "/assets"
|
||||
},
|
||||
"Here": {
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
|
||||
"Dir": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
|
||||
"ImportPath": "",
|
||||
"Module": {
|
||||
"Path": "app",
|
||||
"Main": true,
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
|
||||
"Dir": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"GoMod": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
|
||||
"GoVersion": "1.13"
|
||||
},
|
||||
"Name": "assets"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Abs": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets/css",
|
||||
"Abs": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets/css",
|
||||
"Path": {
|
||||
"Pkg": "app",
|
||||
"Name": "/assets/css"
|
||||
},
|
||||
"Here": {
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
|
||||
"Dir": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/assets",
|
||||
"ImportPath": "",
|
||||
"Module": {
|
||||
"Path": "app",
|
||||
"Main": true,
|
||||
"Dir": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"GoMod": "$GOPATH/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
|
||||
"Dir": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref",
|
||||
"GoMod": "/go/src/github.com/markbates/pkger/pkging/pkgtest/testdata/ref/go.mod",
|
||||
"GoVersion": "1.13"
|
||||
},
|
||||
"Name": "assets"
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/markbates/pkger"
|
||||
"github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa"
|
||||
"github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa/filters"
|
||||
"github.com/markbates/pkger/parser"
|
||||
)
|
||||
|
||||
|
@ -71,15 +69,7 @@ func (e *listCmd) Exec(args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
hep := hepa.New()
|
||||
hep = hepa.With(hep, filters.Home())
|
||||
hep = hepa.With(hep, filters.Golang())
|
||||
|
||||
b, err := hep.Filter(bb.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = os.Stdout.Write(b)
|
||||
_, err = os.Stdout.Write(bb.Bytes())
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
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.
|
|
@ -1,35 +0,0 @@
|
|||
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
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
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
|
||||
}()
|
|
@ -1,12 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
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
|
@ -1,29 +0,0 @@
|
|||
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",
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
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
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
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{}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package hepa
|
||||
|
||||
// Version of hepa
|
||||
const Version = "v0.0.1"
|
|
@ -7,8 +7,6 @@ import (
|
|||
"io"
|
||||
|
||||
"github.com/markbates/pkger/here"
|
||||
"github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa"
|
||||
"github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa/filters"
|
||||
)
|
||||
|
||||
func Decode(src []byte) ([]byte, error) {
|
||||
|
@ -31,15 +29,6 @@ func Decode(src []byte) ([]byte, error) {
|
|||
}
|
||||
|
||||
func Encode(b []byte) ([]byte, error) {
|
||||
hep := hepa.New()
|
||||
hep = hepa.With(hep, filters.Home())
|
||||
hep = hepa.With(hep, filters.Golang())
|
||||
|
||||
b, err := hep.Filter(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bb := &bytes.Buffer{}
|
||||
gz := gzip.NewWriter(bb)
|
||||
|
||||
|
|
Loading…
Reference in New Issue