Upgrade fluxcd/pkg packages
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
This commit is contained in:
@@ -91,6 +91,15 @@ func diffArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||
opts = append(opts, crane.Insecure)
|
||||
}
|
||||
|
||||
if diffArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||
logger.Actionf("logging in to registry with provider credentials")
|
||||
opt, err := loginWithProvider(ctx, url, diffArtifactArgs.provider.String())
|
||||
if err != nil {
|
||||
return fmt.Errorf("error during login with provider: %w", err)
|
||||
}
|
||||
opts = append(opts, opt)
|
||||
}
|
||||
|
||||
ociClient := oci.NewClient(opts)
|
||||
|
||||
if diffArtifactArgs.provider.String() == sourcev1.GenericOCIProvider && diffArtifactArgs.creds != "" {
|
||||
@@ -100,13 +109,6 @@ func diffArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if diffArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||
logger.Actionf("logging in to registry with provider credentials")
|
||||
if err := ociClient.LoginWithProvider(ctx, url, diffArtifactArgs.provider.String()); err != nil {
|
||||
return fmt.Errorf("error during login with provider: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := ociClient.Diff(ctx, url, diffArtifactArgs.path, diffArtifactArgs.ignorePaths); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -83,6 +83,15 @@ func listArtifactsCmdRun(cmd *cobra.Command, args []string) error {
|
||||
|
||||
ociOpts := oci.DefaultOptions()
|
||||
|
||||
if listArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||
logger.Actionf("logging in to registry with provider credentials")
|
||||
ociOpt, err := loginWithProvider(ctx, url, listArtifactArgs.provider.String())
|
||||
if err != nil {
|
||||
return fmt.Errorf("error during login with provider: %w", err)
|
||||
}
|
||||
ociOpts = append(ociOpts, ociOpt)
|
||||
}
|
||||
|
||||
if listArtifactArgs.insecure {
|
||||
ociOpts = append(ociOpts, crane.Insecure)
|
||||
}
|
||||
@@ -96,13 +105,6 @@ func listArtifactsCmdRun(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if listArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||
logger.Actionf("logging in to registry with provider credentials")
|
||||
if err := ociClient.LoginWithProvider(ctx, url, listArtifactArgs.provider.String()); err != nil {
|
||||
return fmt.Errorf("error during login with provider: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
opts := oci.ListOptions{
|
||||
RegexFilter: listArtifactArgs.regexFilter,
|
||||
SemverFilter: listArtifactArgs.semverFilter,
|
||||
|
||||
39
cmd/flux/oci.go
Normal file
39
cmd/flux/oci.go
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright 2025 The Flux authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/go-containerregistry/pkg/crane"
|
||||
|
||||
authutils "github.com/fluxcd/pkg/auth/utils"
|
||||
)
|
||||
|
||||
// loginWithProvider gets a crane authentication option for the given provider and URL.
|
||||
func loginWithProvider(ctx context.Context, url, provider string) (crane.Option, error) {
|
||||
authenticator, err := authutils.GetArtifactRegistryCredentials(ctx, provider, url)
|
||||
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
|
||||
}
|
||||
@@ -92,6 +92,15 @@ func pullArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||
opts = append(opts, crane.Insecure)
|
||||
}
|
||||
|
||||
if pullArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||
logger.Actionf("logging in to registry with provider credentials")
|
||||
opt, err := loginWithProvider(ctx, url, pullArtifactArgs.provider.String())
|
||||
if err != nil {
|
||||
return fmt.Errorf("error during login with provider: %w", err)
|
||||
}
|
||||
opts = append(opts, opt)
|
||||
}
|
||||
|
||||
ociClient := oci.NewClient(opts)
|
||||
|
||||
if pullArtifactArgs.provider.String() == sourcev1.GenericOCIProvider && pullArtifactArgs.creds != "" {
|
||||
@@ -101,13 +110,6 @@ func pullArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if pullArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||
logger.Actionf("logging in to registry with provider credentials")
|
||||
if err := ociClient.LoginWithProvider(ctx, url, pullArtifactArgs.provider.String()); err != nil {
|
||||
return fmt.Errorf("error during login with provider: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Actionf("pulling artifact from %s", url)
|
||||
|
||||
meta, err := ociClient.Pull(ctx, url, pullArtifactArgs.output)
|
||||
|
||||
@@ -19,6 +19,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -230,6 +231,9 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||
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))
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,18 @@ func tagArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
|
||||
defer cancel()
|
||||
|
||||
ociClient := oci.NewClient(oci.DefaultOptions())
|
||||
opts := oci.DefaultOptions()
|
||||
|
||||
if tagArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||
logger.Actionf("logging in to registry with provider credentials")
|
||||
opt, err := loginWithProvider(ctx, url, tagArtifactArgs.provider.String())
|
||||
if err != nil {
|
||||
return fmt.Errorf("error during login with provider: %w", err)
|
||||
}
|
||||
opts = append(opts, opt)
|
||||
}
|
||||
|
||||
ociClient := oci.NewClient(opts)
|
||||
|
||||
if tagArtifactArgs.provider.String() == sourcev1.GenericOCIProvider && tagArtifactArgs.creds != "" {
|
||||
logger.Actionf("logging in to registry with credentials")
|
||||
@@ -87,13 +98,6 @@ func tagArtifactCmdRun(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if tagArtifactArgs.provider.String() != sourcev1.GenericOCIProvider {
|
||||
logger.Actionf("logging in to registry with provider credentials")
|
||||
if err := ociClient.LoginWithProvider(ctx, url, tagArtifactArgs.provider.String()); err != nil {
|
||||
return fmt.Errorf("error during login with provider: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Actionf("tagging artifact")
|
||||
|
||||
for _, tag := range tagArtifactArgs.tags {
|
||||
|
||||
Reference in New Issue
Block a user