mirror of
https://github.com/moby/buildkit.git
synced 2025-08-01 02:04:26 +03:00
Support additional request header fields for HTTP sources, "Accept" and "User-Agent" as a start. The "Accept" header is required in some cases and some servers may vary the response body based on the header value. The "User-Agent" header may be useful in custom frontends and potentially other cases. - llb: Add `llb.Header` and `HTTPInfo.Header` to allow `client/llb` users to set these header fields on HTTP sources. The argument to `llb.Header` is a struct to effectively limit header fields to a subset. - llb: Define and flag new `source.http.header` capability when `llb.Header` is used. - solver: Define new `http.header.` source attribute prefix. Giving each header field its own attribute (opposed to JSON encoding the header struct) will allow source policy to make assertions on individual header fields. - source/http: Parse `http.header.` attributes into a sorted slice and include them in cache key digest. - source/http: Set request headers accordingly. Signed-off-by: Dan Duvall <dduvall@wikimedia.org>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package http
|
|
|
|
import (
|
|
"github.com/moby/buildkit/solver/llbsolver/provenance"
|
|
provenancetypes "github.com/moby/buildkit/solver/llbsolver/provenance/types"
|
|
"github.com/moby/buildkit/source"
|
|
srctypes "github.com/moby/buildkit/source/types"
|
|
digest "github.com/opencontainers/go-digest"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func NewHTTPIdentifier(str string, tls bool) (*HTTPIdentifier, error) {
|
|
proto := "https://"
|
|
if !tls {
|
|
proto = "http://"
|
|
}
|
|
return &HTTPIdentifier{TLS: tls, URL: proto + str}, nil
|
|
}
|
|
|
|
type HTTPIdentifier struct {
|
|
TLS bool
|
|
URL string
|
|
Checksum digest.Digest
|
|
Filename string
|
|
Perm int
|
|
UID int
|
|
GID int
|
|
AuthHeaderSecret string
|
|
Header []HeaderField
|
|
}
|
|
|
|
type HeaderField struct {
|
|
Name string
|
|
Value string
|
|
}
|
|
|
|
var _ source.Identifier = (*HTTPIdentifier)(nil)
|
|
|
|
func (id *HTTPIdentifier) Scheme() string {
|
|
if id.TLS {
|
|
return srctypes.HTTPSScheme
|
|
}
|
|
return srctypes.HTTPScheme
|
|
}
|
|
|
|
func (id *HTTPIdentifier) Capture(c *provenance.Capture, pin string) error {
|
|
dgst, err := digest.Parse(pin)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "failed to parse HTTP digest %s", pin)
|
|
}
|
|
c.AddHTTP(provenancetypes.HTTPSource{
|
|
URL: id.URL,
|
|
Digest: dgst,
|
|
})
|
|
return nil
|
|
}
|