Change strategy per maintainer slack chat

Signed-off-by: Scott Rigby <scott@r6by.com>
pull/30924/head
Scott Rigby 4 months ago
parent 5ba0cf904a
commit 1eb6cf851f
No known key found for this signature in database
GPG Key ID: C7C6FBB5B91C1155

@ -90,10 +90,11 @@ type (
// TODO remove in Helm 4 // TODO remove in Helm 4
// Deprecated // Deprecated
// Helm 3 shim for ORAS v2 not tolerant of an empty config file // Fix for regression in v3.18.0
// to workaround this, set configFile path to a non-existing path // ORAS v1 was tolerant of an empty config file
// so that ORAS v2 [config.Load] will handle this for us // ORAS v2 is not
func orasV1CredentialsFileShim(credentialsFile string, client *Client) string { // to workaround this regression, ensure configfile is valid JSON
func handleEmptyConfgFile(credentialsFile string, client *Client) string {
f, err := os.Open(credentialsFile) f, err := os.Open(credentialsFile)
defer func(f *os.File) { defer func(f *os.File) {
err := f.Close() err := f.Close()
@ -101,14 +102,20 @@ func orasV1CredentialsFileShim(credentialsFile string, client *Client) string {
client.err = err client.err = err
} }
}(f) }(f)
if err != nil { // handle only if credentials file exists
// handle if credentials file does not exist // ORAS already handles if file does not exist
client.credentialsFile = "" if err == nil {
} else {
// handle if credentials file is empty
var configData map[string]json.RawMessage var configData map[string]json.RawMessage
// handle only if credentials file is empty
if err := json.NewDecoder(f).Decode(&configData); err != nil && !errors.Is(err, io.EOF) { if err := json.NewDecoder(f).Decode(&configData); err != nil && !errors.Is(err, io.EOF) {
// Attempt to write empty JSON map to config file
// Note that <3.18.0
client.credentialsFile = "" client.credentialsFile = ""
encoder := json.NewEncoder(f)
err = encoder.Encode(configData)
if err != nil {
client.err = err
}
} }
} }
return client.credentialsFile return client.credentialsFile
@ -129,7 +136,7 @@ func NewClient(options ...ClientOption) (*Client, error) {
client.credentialsFile = helmpath.ConfigPath(CredentialsFileBasename) client.credentialsFile = helmpath.ConfigPath(CredentialsFileBasename)
} }
client.credentialsFile = orasV1CredentialsFileShim(client.credentialsFile, client) client.credentialsFile = handleEmptyConfgFile(client.credentialsFile, client)
if client.httpClient == nil { if client.httpClient == nil {
transport := newTransport() transport := newTransport()

Loading…
Cancel
Save