Skip to content

Commit

Permalink
Merge pull request #56 from robnester-rh/oci_changes
Browse files Browse the repository at this point in the history
Update oci to convert localhost to 127.0.0.1
  • Loading branch information
robnester-rh authored Jun 27, 2024
2 parents 078be0e + 4b34f5a commit 5b79785
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
12 changes: 6 additions & 6 deletions gather/oci/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ module github.com/enterprise-contract/go-gather/gather/oci
go 1.21.9

require (
github.com/open-policy-agent/conftest v0.53.0
oras.land/oras-go/v2 v2.5.0

github.com/enterprise-contract/go-gather/metadata v0.0.2
github.com/enterprise-contract/go-gather/metadata/oci v0.0.1
oras.land/oras-go/v2 v2.5.0
)

require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/google/go-containerregistry v0.19.2
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -25,7 +23,7 @@ require (
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/spf13/viper v1.18.2
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
Expand All @@ -36,4 +34,6 @@ require (
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
)

require github.com/google/go-cmp v0.6.0 // indirect
14 changes: 10 additions & 4 deletions gather/oci/go.sum
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/enterprise-contract/go-gather/metadata v0.0.2 h1:BxPXXZFjX7lrYnlJosPmvISgjF13HpawEtZTDxjnjcQ=
github.com/enterprise-contract/go-gather/metadata v0.0.2/go.mod h1:m2HxByQBWZyc99HDs/Lqy7QzU9+XQ2tU0X/mzkCPgPw=
github.com/enterprise-contract/go-gather/metadata/oci v0.0.1 h1:12hqwNYsvo49UOu5P+YjwDX3f0q93fUfUcY9p0u5ta4=
github.com/enterprise-contract/go-gather/metadata/oci v0.0.1/go.mod h1:kJSMxYth37g604Cvsa18ibgTU33zagsadeQ7p1DYIak=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-containerregistry v0.19.2 h1:TannFKE1QSajsP6hPWb5oJNgKe1IKjHukIKDUmvsV6w=
github.com/google/go-containerregistry v0.19.2/go.mod h1:YCMFNQeeXeLF+dnhhWkqDItx/JSkH01j1Kis4PsjzFI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/open-policy-agent/conftest v0.53.0 h1:tLj0NMOBMmxnr1wTpNIuhCyuLf6D4+ksti56OX7wzAY=
github.com/open-policy-agent/conftest v0.53.0/go.mod h1:ABFOf9kIX6cvP4lCa9vwCVaXaEw23aRKL+BXR0Lr7DM=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
Expand All @@ -28,6 +33,7 @@ github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
Expand Down
2 changes: 1 addition & 1 deletion gather/oci/internal/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ func IsLoopback(host string) bool {
}

return false
}
}
5 changes: 3 additions & 2 deletions gather/oci/internal/registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package registry
import (
"net/http"

"github.com/enterprise-contract/go-gather/gather/oci/internal/network"
"github.com/spf13/viper"
"oras.land/oras-go/v2/registry/remote"
"oras.land/oras-go/v2/registry/remote/auth"
"oras.land/oras-go/v2/registry/remote/credentials"
"oras.land/oras-go/v2/registry/remote/retry"

"github.com/enterprise-contract/go-gather/gather/oci/internal/network"
)

func SetupClient(repository *remote.Repository) error {
Expand Down Expand Up @@ -43,4 +44,4 @@ func SetupClient(repository *remote.Repository) error {
repository.Client = client

return nil
}
}
19 changes: 10 additions & 9 deletions gather/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"os"
"strings"

r "github.com/enterprise-contract/go-gather/gather/oci/internal/registry"

"github.com/enterprise-contract/go-gather/metadata"
"github.com/enterprise-contract/go-gather/metadata/oci"
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content/file"
"oras.land/oras-go/v2/registry"
"oras.land/oras-go/v2/registry/remote"

r "github.com/enterprise-contract/go-gather/gather/oci/internal/registry"
"github.com/enterprise-contract/go-gather/metadata"
"github.com/enterprise-contract/go-gather/metadata/oci"
)

// OCIGatherer is a struct that implements the Gatherer interface
Expand All @@ -24,6 +24,10 @@ type OCIGatherer struct{}
// It returns the metadata of the gathered file or directory and any error encountered.
// Portions of this file are derivative from the open-policy-agent/conftest project.
func (f *OCIGatherer) Gather(ctx context.Context, source, destination string) (metadata.Metadata, error) {
if strings.Contains(source, "localhost") {
source = strings.ReplaceAll(source, "localhost", "127.0.0.1")
}

// Parse the source URI
repo := ociURLParse(source)

Expand Down Expand Up @@ -68,10 +72,7 @@ func (f *OCIGatherer) Gather(ctx context.Context, source, destination string) (m
return nil, fmt.Errorf("pulling policy: %w", err)
}

m := &oci.OCIMetadata{
Digest: a.Digest.String(),
}
return m, nil
return &oci.OCIMetadata{Digest: a.Digest.String()}, nil
}

func ociURLParse(source string) string {
Expand All @@ -80,4 +81,4 @@ func ociURLParse(source string) string {
src = scheme
}
return src
}
}

0 comments on commit 5b79785

Please sign in to comment.