Repository: helm/helm
File: pkg/registry/client.go (Go)

Code before:
		if c.debug {
			fmt.Fprintf(c.out, "[WARNING] Invalid registry passed: registries should NOT include a repository. Use %q instead\n", host)
		}
		return host
	}

	return host
}

// Login logs into a registry
func (c *Client) Login(host string, options ...LoginOption) error {
	// This is the lowest available point to strip incorrect URL parts
	host = c.stripURL(host)

	for _, option := range options {
		option(&loginOperation{host, c})
	}

	reg, err := remote.NewRegistry(host)
	if err != nil {
		return err
	}
	reg.PlainHTTP = c.plainHTTP
	cred := auth.Credential{Username: c.username, Password: c.password}
	c.authorizer.ForceAttemptOAuth2 = true
	c.authorizer.Credential = auth.StaticCredential(reg.Reference.Registry, cred)
	reg.Client = c.authorizer

	ctx := context.Background()
	if err := reg.Ping(ctx); err != nil {
		c.authorizer.ForceAttemptOAuth2 = false
		if err := reg.Ping(ctx); err != nil {
			return fmt.Errorf("authenticating to %q: %w", host, err)
		}
	}

	// The credentialsStore loader does not handle empty files. So, there is a workaround.
	// This can be removed when the credentials loader can handle empty files.
	// When Helm catches an empty file error it causes the loader to trigger its fault
	// tolerance for a file not existing and records it with a bool. If that bool is set and the
	// file needs to be written, the file needs to be put into a usable state and loaded
	// properly.
	// See the NewClient function for the bypass setup.
	if c.credentialsFileTemp {
		err = os.WriteFile(c.credentialsFile, []byte("{}"), 0600)
		if err != nil {
			return err
		}
		storeOptions := credentials.StoreOptions{
			AllowPlaintextPut:        true,
			DetectDefaultNativeStore: true,

Review comment (security):
The `authorizer.Credential` is already set at ...

https://github.com/helm/helm/blob/2198f0f5cd72222e6fa7ffcb54388bc3e2e8c077/pkg/registry/client.go#L340-L346

Should it be removed from that function since it's no longer being used there or updated there and removed from here?

Code after:
		if c.debug {
			fmt.Fprintf(c.out, "[WARNING] Invalid registry passed: registries should NOT include a repository. Use %q instead\n", host)
		}
		return host
	}

	return host
}

// Login logs into a registry
func (c *Client) Login(host string, options ...LoginOption) error {
	// This is the lowest available point to strip incorrect URL parts
	host = c.stripURL(host)

	for _, option := range options {
		option(&loginOperation{host, c})
	}

	reg, err := remote.NewRegistry(host)
	if err != nil {
		return err
	}
	reg.PlainHTTP = c.plainHTTP
	cred := auth.Credential{Username: c.username, Password: c.password}
	c.authorizer.ForceAttemptOAuth2 = true
	reg.Client = c.authorizer

	ctx := context.Background()
	if err := reg.Ping(ctx); err != nil {
		c.authorizer.ForceAttemptOAuth2 = false
		if err := reg.Ping(ctx); err != nil {
			return fmt.Errorf("authenticating to %q: %w", host, err)
		}
	}

	// The credentialsStore loader does not handle empty files. So, there is a workaround.
	// This can be removed when the credentials loader can handle empty files.
	// When Helm catches an empty file error it causes the loader to trigger its fault
	// tolerance for a file not existing and records it with a bool. If that bool is set and the
	// file needs to be written, the file needs to be put into a usable state and loaded
	// properly.
	// See the NewClient function for the bypass setup.
	if c.credentialsFileTemp {
		err = os.WriteFile(c.credentialsFile, []byte("{}"), 0600)
		if err != nil {
			return err
		}
		storeOptions := credentials.StoreOptions{
			AllowPlaintextPut:        true,
			DetectDefaultNativeStore: true,
		}