Skip to content

Commit

Permalink
Merge pull request #51 from alauda/patch/docker-like-insecure
Browse files Browse the repository at this point in the history
Patch/docker like insecure
  • Loading branch information
youyongsong authored Mar 27, 2022
2 parents 48dfe82 + 7d50efe commit dee855b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
36 changes: 34 additions & 2 deletions internal/experimental/registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,27 @@ func (c *Client) PushChart(ref *Reference, insecure bool, plainHTTP bool) error
fmt.Fprintf(c.out, "The push refers to repository [%s]\n", r.Repo)
c.printCacheRefSummary(r)
layers := []ocispec.Descriptor{*r.ContentLayer}

_, err = oras.Push(ctx(c.out, c.debug), c.resolver, r.Name, c.cache.Provider(), layers,
oras.WithConfig(*r.Config), oras.WithNameValidation(nil))
if err != nil {
if err != nil && insecure {
resolver, err := c.newResolver(insecure, true)
if err != nil {
return err
}
c.resolver = &Resolver{
Resolver: resolver,
}

_, err = oras.Push(ctx(c.out, c.debug), c.resolver, r.Name, c.cache.Provider(), layers,
oras.WithConfig(*r.Config), oras.WithNameValidation(nil))
if err != nil {
return err
}
} else if err != nil {
return err
}

s := ""
numLayers := len(layers)
if 1 < numLayers {
Expand Down Expand Up @@ -179,7 +195,23 @@ func (c *Client) PullChart(ref *Reference, insecure bool, plainHTTP bool) error
oras.WithPullEmptyNameAllowed(),
oras.WithAllowedMediaTypes(KnownMediaTypes()),
oras.WithContentProvideIngester(c.cache.ProvideIngester()))
if err != nil {
if err != nil && insecure {
resolver, err := c.newResolver(insecure, true)
if err != nil {
return err
}
c.resolver = &Resolver{
Resolver: resolver,
}

manifest, _, err = oras.Pull(ctx(c.out, c.debug), c.resolver, ref.FullName(), c.cache.Ingester(),
oras.WithPullEmptyNameAllowed(),
oras.WithAllowedMediaTypes(KnownMediaTypes()),
oras.WithContentProvideIngester(c.cache.ProvideIngester()))
if err != nil {
return err
}
} else if err != nil {
return err
}
err = c.cache.AddManifest(ref, &manifest)
Expand Down
3 changes: 1 addition & 2 deletions pkg/gates/gates.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package gates

import (
"fmt"
"os"
)

// Gate is the name of the feature gate.
Expand All @@ -30,7 +29,7 @@ func (g Gate) String() string {

// IsEnabled determines whether a certain feature gate is enabled.
func (g Gate) IsEnabled() bool {
return os.Getenv(string(g)) != ""
return true
}

func (g Gate) Error() error {
Expand Down

0 comments on commit dee855b

Please sign in to comment.