Skip to content

Commit

Permalink
cleanup: use ConvertSecrets from libk8soci
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Kotzbauer <[email protected]>
ckotzbauer committed Dec 23, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 8ae1834 commit 2f46234
Showing 3 changed files with 4 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ go 1.19
require (
github.com/anchore/stereoscope v0.0.0-20221208011002-c5ff155d72f1
github.com/anchore/syft v0.63.0
github.com/ckotzbauer/libk8soci v0.0.0-20221216164241-860d8e82111e
github.com/ckotzbauer/libk8soci v0.0.0-20221223154257-bd3f36fa6c82
github.com/ckotzbauer/libstandard v0.0.0-20221211123229-8434bdf8eece
github.com/google/uuid v1.3.0
github.com/novln/docker-parser v1.0.0
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -588,8 +588,8 @@ github.com/cilium/ebpf v0.6.2/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJ
github.com/cilium/ebpf v0.7.0/go.mod h1:/oI2+1shJiTGAMgl6/RgJr36Eo1jzrRcAWbcXO2usCA=
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
github.com/ckotzbauer/libk8soci v0.0.0-20221216164241-860d8e82111e h1:gHdtP9pOrkrhn98baDTnScVPF/cqXl863eEfW4qeIbI=
github.com/ckotzbauer/libk8soci v0.0.0-20221216164241-860d8e82111e/go.mod h1:iCyFGATOCWbtM7ompmb6194mK8Ye2u2pcpxOrande9A=
github.com/ckotzbauer/libk8soci v0.0.0-20221223154257-bd3f36fa6c82 h1:nuBMfAHObfmu+AnVxd8LOqU42pGWCp0lXrGXAnNiLkU=
github.com/ckotzbauer/libk8soci v0.0.0-20221223154257-bd3f36fa6c82/go.mod h1:CDB4JaydrC/0HiiFA1t8uwyTy0rdXxpB+LZqZf8+i1w=
github.com/ckotzbauer/libstandard v0.0.0-20221211123229-8434bdf8eece h1:iYcSspfI75B4QVf/j6dMmqx1vOk+YxbCUVML3RE7p4A=
github.com/ckotzbauer/libstandard v0.0.0-20221211123229-8434bdf8eece/go.mod h1:9W+F8tlDH+PqLUQmV+NA2awzzawEoaVfNg3nqwsluQI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
@@ -1915,8 +1915,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20221215174704-0915cd710c24 h1:6w3iSY8IIkp5OQtbYj8NeuKG1jS9d+kYaubXqsoOiQ8=
golang.org/x/exp v0.0.0-20221215174704-0915cd710c24/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15 h1:5oN1Pz/eDhCpbMbLstvIPa0b/BEQo6g6nwV3pLjfM6w=
golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
29 changes: 1 addition & 28 deletions internal/syft/syft.go
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ func (s *Syft) ExecuteSyft(img *oci.RegistryImage) (string, error) {
return "", err
}

opts := &image.RegistryOptions{Credentials: s.convertSecrets(*img)}
opts := &image.RegistryOptions{Credentials: oci.ConvertSecrets(*img)}
src, cleanup, err := source.New(*input, opts, nil)
if err != nil {
logrus.WithError(fmt.Errorf("failed to construct source from input registry:%s: %w", img.ImageID, err)).Error("Source-Creation failed")
@@ -124,33 +124,6 @@ func getSyftVersion() string {
return ""
}

func (s *Syft) convertSecrets(img oci.RegistryImage) []image.RegistryCredentials {
credentials := make([]image.RegistryCredentials, 0)
for _, secret := range img.PullSecrets {
cfg, err := oci.ResolveAuthConfigWithPullSecret(img, *secret)
if err != nil {
logrus.WithError(err).Warnf("image: %s, Read authentication configuration from secret: %s failed", img.ImageID, secret.SecretName)
continue
}

for registryToReplace, proxyRegistry := range s.proxyRegistryMap {
if cfg.ServerAddress == registryToReplace ||
(strings.Contains(cfg.ServerAddress, docker.DefaultHostname) && strings.Contains(registryToReplace, docker.DefaultHostname)) {
cfg.ServerAddress = proxyRegistry
}
}

credentials = append(credentials, image.RegistryCredentials{
Username: cfg.Username,
Password: cfg.Password,
Token: cfg.RegistryToken,
Authority: cfg.ServerAddress,
})
}

return credentials
}

func (s *Syft) ApplyProxyRegistry(img *oci.RegistryImage) error {
imageRef, err := parser.Parse(img.ImageID)
if err != nil {

0 comments on commit 2f46234

Please sign in to comment.