Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,6 @@ type Bundle struct {
staticFiles map[string]bool
}

// StaticFile returns a static file from the bundle, if it exists.
func (b *Bundle) StaticFile(filePath string) ([]byte, error) {
// normalize in case the caller added `/` or `./` to the filename.
filePath = NormalizeStaticFilename(filePath)

if _, exists := b.staticFiles[filePath]; !exists {
return nil, os.ErrNotExist
}

r, err := zip.OpenReader(b.filepath)
if err != nil {
return nil, errors.Wrap(err, "failed to open bundle")
}

defer r.Close()

// re-add the static/ prefix to ensure sandboxing to the static directory.
staticFilePath := ensurePrefix(filePath, "static/")

var contents []byte

for _, f := range r.File {
if f.Name == staticFilePath {
file, err := f.Open()
if err != nil {
return nil, errors.Wrap(err, "failed to Open static file")
}

defer file.Close()

contents, err = io.ReadAll(file)
if err != nil {
return nil, errors.Wrap(err, "failed to ReadAll static file")
}

break
}
}

return contents, nil
}

// Write writes a module bundle
// based loosely on https://golang.org/src/archive/zip/example_test.go
// staticFiles should be a map of *relative* filepaths to their associated files, with or without the `static/` prefix.
Expand Down
5 changes: 2 additions & 3 deletions system/bundle/bundlesource.go → bundle/bundlesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/pkg/errors"

"github.com/suborbital/systemspec/bundle"
"github.com/suborbital/systemspec/capabilities"
"github.com/suborbital/systemspec/system"
"github.com/suborbital/systemspec/tenant"
Expand All @@ -15,7 +14,7 @@ import (
// BundleSource is a Source backed by a bundle file.
type BundleSource struct {
path string
bundle *bundle.Bundle
bundle *Bundle

lock sync.RWMutex
}
Expand Down Expand Up @@ -215,7 +214,7 @@ func (b *BundleSource) Capabilities(ident, namespace string, version int64) (*ca
// findBundle loops forever until it finds a bundle at the configured path.
func (b *BundleSource) findBundle() error {
for {
bdl, err := bundle.Read(b.path)
bdl, err := Read(b.path)
if err != nil {
time.Sleep(time.Second)

Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/suborbital/go-kit v0.0.8 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/text v0.6.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,23 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/suborbital/go-kit v0.0.8 h1:yBsxUAlizy46p/eeHM1BfJZgEyx+dbK5oUYKd1N9szQ=
github.com/suborbital/go-kit v0.0.8/go.mod h1:1OWVnUwXri359OyolKOnthe8jetCQJY/daaObfwRaSs=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8=
golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/exp v0.0.0-20230206171751-46f607a40771 h1:xP7rWLUr1e1n2xkK5YB4LI0hPEy3LJC6Wk+D4pGlOJg=
golang.org/x/exp v0.0.0-20230206171751-46f607a40771/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -54,6 +60,8 @@ golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
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=
Expand Down
5 changes: 4 additions & 1 deletion request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/labstack/echo/v4"
"github.com/pkg/errors"
kitHttp "github.com/suborbital/go-kit/web/http"
)

const (
Expand Down Expand Up @@ -37,12 +38,14 @@ type CoordinatedRequest struct {
func FromEchoContext(c echo.Context) (*CoordinatedRequest, error) {
var err error
reqBody := make([]byte, 0)

if c.Request().Body != nil { // Read
reqBody, err = io.ReadAll(c.Request().Body)
if err != nil {
return nil, errors.Wrap(err, "io.ReadAll request body")
}
}

c.Request().Body = io.NopCloser(bytes.NewBuffer(reqBody)) // Reset

flatHeaders := map[string]string{}
Expand All @@ -59,7 +62,7 @@ func FromEchoContext(c echo.Context) (*CoordinatedRequest, error) {
return &CoordinatedRequest{
Method: c.Request().Method,
URL: c.Request().URL.RequestURI(),
ID: c.Request().Header.Get("requestID"),
ID: kitHttp.RID(c),
Body: reqBody,
Headers: flatHeaders,
RespHeaders: map[string]string{},
Expand Down