Files
buildkit/source/http/identifier.go
Tonis Tiigi 93999f4071 sourcepolicy: normalize parsed source identifiers
Render parsed source identifiers back to their canonical SourceOp form before
source policy evaluation. This lets Git subdir cleanup use the existing source
parser and avoids policy-specific Git parsing.

Add String methods for source identifiers and cover them with unit tests, plus
a client integration regression for canonical Git subdir policy matching.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-07-22 11:36:47 +02:00

67 lines
1.4 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
VerifySignature *HTTPSignatureVerifyOptions
}
type HTTPSignatureVerifyOptions struct {
PubKey []byte
Signature []byte
}
type HeaderField struct {
Name string
Value string
}
var _ source.Identifier = (*HTTPIdentifier)(nil)
func (id *HTTPIdentifier) String() string {
return id.URL
}
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
}