Skip to content

Commit

Permalink
feat: adding support for AUX_REPOSITORY to send sboms
Browse files Browse the repository at this point in the history
Signed-off-by: Batuhan Apaydın <batuhan.apaydin@trendyol.com>
  • Loading branch information
developer-guy committed Sep 12, 2022
1 parent bb84aa3 commit 012b1b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
8 changes: 6 additions & 2 deletions pkg/publish/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ type defalt struct {
base string
t http.RoundTripper
userAgent string
auth authn.Authenticator
namer Namer
auth authn.Authenticator
keychain authn.Keychain
tags []string
tagOnly bool
insecure bool
Expand All @@ -55,6 +56,7 @@ type defaultOpener struct {
t http.RoundTripper
userAgent string
auth authn.Authenticator
keychain authn.Keychain
namer Namer
tags []string
tagOnly bool
Expand Down Expand Up @@ -90,6 +92,7 @@ func (do *defaultOpener) Open() (Interface, error) {
t: do.t,
userAgent: do.userAgent,
auth: do.auth,
keychain: do.keychain,
namer: do.namer,
tags: do.tags,
tagOnly: do.tagOnly,
Expand All @@ -105,6 +108,7 @@ func NewDefault(base string, options ...Option) (Interface, error) {
t: http.DefaultTransport,
userAgent: "ko",
auth: authn.Anonymous,
keychain: authn.DefaultKeychain,
namer: identity,
tags: defaultTags,
}
Expand Down Expand Up @@ -203,7 +207,7 @@ func (d *defalt) Publish(ctx context.Context, br build.Result, s string) (name.R
// https://github.com/google/go-containerregistry/issues/212
s = strings.ToLower(s)

ro := []remote.Option{remote.WithAuth(d.auth), remote.WithTransport(d.t), remote.WithContext(ctx), remote.WithUserAgent(d.userAgent)}
ro := []remote.Option{remote.WithAuthFromKeychain(d.keychain), remote.WithTransport(d.t), remote.WithContext(ctx), remote.WithUserAgent(d.userAgent)}
no := []name.Option{}
if d.insecure {
no = append(no, name.Insecure)
Expand Down
23 changes: 1 addition & 22 deletions pkg/publish/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ package publish

import (
"crypto/tls"
"log"
"net/http"
"path"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
)

// WithTransport is a functional option for overriding the default transport
Expand Down Expand Up @@ -55,25 +52,7 @@ func WithAuth(auth authn.Authenticator) Option {
// authenticator on a default publisher using an authn.Keychain
func WithAuthFromKeychain(keys authn.Keychain) Option {
return func(i *defaultOpener) error {
// We parse this lazily because it is a repository prefix, which
// means that docker.io/mattmoor actually gets interpreted as
// docker.io/library/mattmoor, which gets tricky when we start
// appending things to it in the publisher.
//
// We append a fake path "ko" to KO_DOCKER_REPO in order to
// make parsing out the registry easier.
repo, err := name.NewRepository(path.Join(i.base, "ko"))
if err != nil {
return err
}
auth, err := keys.Resolve(repo.Registry)
if err != nil {
return err
}
if auth == authn.Anonymous {
log.Println("No matching credentials were found, falling back on anonymous")
}
i.auth = auth
i.keychain = keys
return nil
}
}
Expand Down

0 comments on commit 012b1b3

Please sign in to comment.