mirror of
https://github.com/helm/helm.git
synced 2026-08-08 00:51:55 +00:00
Merge pull request #11086 from souleb/registry-cache-optin
Make token caching an opt in feature in OCI registry client
This commit is contained in:
@@ -154,6 +154,7 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string
|
||||
|
||||
registryClient, err := registry.NewClient(
|
||||
registry.ClientOptDebug(settings.Debug),
|
||||
registry.ClientOptEnableCache(true),
|
||||
registry.ClientOptWriter(out),
|
||||
registry.ClientOptCredentialsFile(settings.RegistryConfig),
|
||||
)
|
||||
|
||||
@@ -63,7 +63,9 @@ func (g *OCIGetter) get(href string) (*bytes.Buffer, error) {
|
||||
|
||||
// NewOCIGetter constructs a valid http/https client as a Getter
|
||||
func NewOCIGetter(ops ...Option) (Getter, error) {
|
||||
registryClient, err := registry.NewClient()
|
||||
registryClient, err := registry.NewClient(
|
||||
registry.ClientOptEnableCache(true),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -85,7 +85,9 @@ func (pusher *OCIPusher) push(chartRef, href string) error {
|
||||
|
||||
// NewOCIPusher constructs a valid OCI client as a Pusher
|
||||
func NewOCIPusher(ops ...Option) (Pusher, error) {
|
||||
registryClient, err := registry.NewClient()
|
||||
registryClient, err := registry.NewClient(
|
||||
registry.ClientOptEnableCache(true),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -53,7 +53,8 @@ a plus (+) when pulling from a registry.`
|
||||
type (
|
||||
// Client works with OCI-compliant registries
|
||||
Client struct {
|
||||
debug bool
|
||||
debug bool
|
||||
enableCache bool
|
||||
// path to repository config file e.g. ~/.docker/config.json
|
||||
credentialsFile string
|
||||
out io.Writer
|
||||
@@ -95,12 +96,18 @@ func NewClient(options ...ClientOption) (*Client, error) {
|
||||
}
|
||||
client.resolver = resolver
|
||||
}
|
||||
|
||||
// allocate a cache if option is set
|
||||
var cache registryauth.Cache
|
||||
if client.enableCache {
|
||||
cache = registryauth.DefaultCache
|
||||
}
|
||||
if client.registryAuthorizer == nil {
|
||||
client.registryAuthorizer = ®istryauth.Client{
|
||||
Header: http.Header{
|
||||
"User-Agent": {version.GetUserAgent()},
|
||||
},
|
||||
Cache: registryauth.DefaultCache,
|
||||
Cache: cache,
|
||||
Credential: func(ctx context.Context, reg string) (registryauth.Credential, error) {
|
||||
dockerClient, ok := client.authorizer.(*dockerauth.Client)
|
||||
if !ok {
|
||||
@@ -138,6 +145,13 @@ func ClientOptDebug(debug bool) ClientOption {
|
||||
}
|
||||
}
|
||||
|
||||
// ClientOptEnableCache returns a function that sets the enableCache setting on a client options set
|
||||
func ClientOptEnableCache(enableCache bool) ClientOption {
|
||||
return func(client *Client) {
|
||||
client.enableCache = enableCache
|
||||
}
|
||||
}
|
||||
|
||||
// ClientOptWriter returns a function that sets the writer setting on client options set
|
||||
func ClientOptWriter(out io.Writer) ClientOption {
|
||||
return func(client *Client) {
|
||||
|
||||
@@ -70,6 +70,7 @@ func (suite *RegistryClientTestSuite) SetupSuite() {
|
||||
var err error
|
||||
suite.RegistryClient, err = NewClient(
|
||||
ClientOptDebug(true),
|
||||
ClientOptEnableCache(true),
|
||||
ClientOptWriter(suite.Out),
|
||||
ClientOptCredentialsFile(credentialsFile),
|
||||
)
|
||||
|
||||
@@ -153,6 +153,7 @@ func (srv *OCIServer) Run(t *testing.T, opts ...OCIServerOpt) {
|
||||
// init test client
|
||||
registryClient, err := ociRegistry.NewClient(
|
||||
ociRegistry.ClientOptDebug(true),
|
||||
ociRegistry.ClientOptEnableCache(true),
|
||||
ociRegistry.ClientOptWriter(os.Stdout),
|
||||
ociRegistry.ClientOptCredentialsFile(credentialsFile),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user