refactor: cleanup GetArtifactRegistryCredentials error handling
Update fluxcd/pkg/auth to v0.18.0 and simplify error handling for GetArtifactRegistryCredentials() following the improvements made in the library. Similar to fluxcd/image-reflector-controller#786, this removes unnecessary nil checks as the function now returns errors directly for unsupported providers. - Replace authentication code in push_artifact.go with loginWithProvider() - Remove unnecessary authenticator nil check in oci.go - Remove unused imports (errors, auth packages) Signed-off-by: cappyzawa <cappyzawa@gmail.com>
This commit is contained in:
@@ -18,7 +18,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-containerregistry/pkg/crane"
|
||||
@@ -38,8 +37,5 @@ func loginWithProvider(ctx context.Context, url, provider string) (crane.Option,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not login to provider %s with url %s: %w", provider, url, err)
|
||||
}
|
||||
if authenticator == nil {
|
||||
return nil, errors.New("unsupported provider")
|
||||
}
|
||||
return crane.WithAuth(authenticator), nil
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -34,9 +33,6 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/fluxcd/pkg/auth"
|
||||
"github.com/fluxcd/pkg/auth/azure"
|
||||
authutils "github.com/fluxcd/pkg/auth/utils"
|
||||
"github.com/fluxcd/pkg/oci"
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1"
|
||||
|
||||
@@ -229,18 +225,11 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if provider := pushArtifactArgs.provider.String(); provider != sourcev1.GenericOCIProvider {
|
||||
logger.Actionf("logging in to registry with provider credentials")
|
||||
var authOpts []auth.Option
|
||||
if provider == azure.ProviderName {
|
||||
authOpts = append(authOpts, auth.WithAllowShellOut())
|
||||
}
|
||||
authenticator, err = authutils.GetArtifactRegistryCredentials(ctx, provider, url, authOpts...)
|
||||
authOpt, err := loginWithProvider(ctx, url, provider)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error during login with provider: %w", err)
|
||||
}
|
||||
if authenticator == nil {
|
||||
return errors.New("unsupported provider")
|
||||
}
|
||||
opts = append(opts, crane.WithAuth(authenticator))
|
||||
opts = append(opts, authOpt)
|
||||
}
|
||||
|
||||
if rootArgs.timeout != 0 {
|
||||
|
||||
Reference in New Issue
Block a user