MCPcopy Create free account
hub / github.com/docker/buildx / sourceToInput

Function sourceToInput

policy/validate.go:534–805  ·  view source on GitHub ↗
(ctx context.Context, getVerifier PolicyVerifierProvider, src *gwpb.ResolveSourceMetaResponse, platform *ocispecs.Platform, logf func(logrus.Level, string))

Source from the content-addressed store, hash-verified

532}
533
534func sourceToInput(ctx context.Context, getVerifier PolicyVerifierProvider, src *gwpb.ResolveSourceMetaResponse, platform *ocispecs.Platform, logf func(logrus.Level, string)) (Input, []string, error) {
535 var inp Input
536 var unknowns []string
537
538 if src == nil || src.Source == nil {
539 return inp, nil, errors.Errorf("no source info in request")
540 }
541
542 scheme, refstr, ok := strings.Cut(src.Source.Identifier, "://")
543 if !ok {
544 return inp, nil, errors.Errorf("invalid source identifier: %s", src.Source.Identifier)
545 }
546
547 switch scheme {
548 case "http", "https":
549 u, err := url.Parse(src.Source.Identifier)
550 if err != nil {
551 return inp, nil, errors.Wrapf(err, "failed to parse http source url")
552 }
553 inp.HTTP = &HTTP{
554 URL: src.Source.Identifier,
555 Schema: scheme,
556 Host: u.Host,
557 Path: u.Path,
558 Query: u.Query(),
559 }
560 if src.HTTP != nil {
561 inp.HTTP.Checksum = src.HTTP.Checksum
562 if src.HTTP.ChecksumResponse != nil {
563 inp.HTTP.checksumResponseForSignature = &httpChecksumResponseForSignature{
564 Digest: src.HTTP.ChecksumResponse.Digest,
565 Suffix: slices.Clone(src.HTTP.ChecksumResponse.Suffix),
566 }
567 }
568 }
569 if inp.HTTP.Checksum == "" {
570 unknowns = append(unknowns, "input.http.checksum")
571 }
572 if _, ok := src.Source.Attrs[pb.AttrHTTPAuthHeaderSecret]; ok {
573 inp.HTTP.HasAuth = true
574 }
575 case "git":
576 if !gitutil.IsGitTransport(refstr) {
577 refstr = "https://" + refstr
578 }
579 u, err := gitutil.ParseURL(refstr)
580 if err != nil {
581 return inp, nil, err
582 }
583 g := &Git{
584 Schema: u.Scheme,
585 Remote: u.Remote,
586 Host: u.Host,
587 }
588 var ref string
589 var isFullRef bool
590 if u.Opts != nil {
591 ref = u.Opts.Ref

Callers 3

resolveTestInputFunction · 0.85
sourceToInputRecursiveFunction · 0.85

Calls 10

ActorStruct · 0.85
parseGitSignatureFunction · 0.85
withPrefixFunction · 0.85
parseProvenanceFunction · 0.85
parseSignaturesFunction · 0.85
DigestMethod · 0.80
FormatMethod · 0.80
NameMethod · 0.65
StringMethod · 0.45
TagMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…