Skip to content

Commit

Permalink
pass publickeypath everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: schristoff <[email protected]>
  • Loading branch information
schristoff committed Sep 24, 2024
1 parent 0fbab7d commit 6039d7c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ var packageInspectCmd = &cobra.Command{
ListImages: pkgConfig.InspectOpts.ListImages,
ViewSBOM: pkgConfig.InspectOpts.ViewSBOM,
SBOMOutputDir: pkgConfig.InspectOpts.SBOMOutputDir,
PublicKeyPath: pkgConfig.PkgOpts.PublicKeyPath,
}

if pkgConfig.InspectOpts.ListImages {
Expand Down Expand Up @@ -293,6 +294,7 @@ var packageRemoveCmd = &cobra.Command{
Cluster: cluster,
Filter: filter,
SkipSignatureValidation: pkgConfig.PkgOpts.SkipSignatureValidation,
PublicKeyPath: pkgConfig.PkgOpts.PublicKeyPath,
}
err = packager2.Remove(cmd.Context(), removeOpt)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion src/internal/packager2/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type ZarfInspectOptions struct {
SBOMOutputDir string
ListImages bool
SkipSignatureValidation bool
PublicKeyPath string
}

// Inspect list the contents of a package.
Expand Down Expand Up @@ -66,7 +67,7 @@ func InspectList(ctx context.Context, opt ZarfInspectOptions) ([]string, error)
}

func getPackageMetadata(ctx context.Context, opt ZarfInspectOptions) (v1alpha1.ZarfPackage, error) {
pkg, err := packageFromSourceOrCluster(ctx, opt.Cluster, opt.Source, opt.SkipSignatureValidation)
pkg, err := packageFromSourceOrCluster(ctx, opt.Cluster, opt.Source, opt.SkipSignatureValidation, opt.PublicKeyPath)
if err != nil {
return pkg, err
}
Expand All @@ -79,6 +80,7 @@ func handleSBOMOptions(ctx context.Context, pkg v1alpha1.ZarfPackage, opt ZarfIn
Source: opt.Source,
SkipSignatureValidation: opt.SkipSignatureValidation,
Filter: filters.Empty(),
PublicKeyPath: opt.PublicKeyPath,
}
layout, err := LoadPackage(ctx, loadOpt)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion src/internal/packager2/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func assembleSplitTar(src, tarPath string) error {
return nil
}

func packageFromSourceOrCluster(ctx context.Context, cluster *cluster.Cluster, src string, skipSignatureValidation bool) (v1alpha1.ZarfPackage, error) {
func packageFromSourceOrCluster(ctx context.Context, cluster *cluster.Cluster, src string, skipSignatureValidation bool, publicKeyPath string) (v1alpha1.ZarfPackage, error) {
_, err := identifySource(src)
if err != nil {
if cluster == nil {
Expand All @@ -244,6 +244,7 @@ func packageFromSourceOrCluster(ctx context.Context, cluster *cluster.Cluster, s
Source: src,
SkipSignatureValidation: skipSignatureValidation,
Filter: filters.Empty(),
PublicKeyPath: publicKeyPath,
}
pkgPaths, err := LoadPackage(ctx, loadOpt)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions src/internal/packager2/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ func TestPackageFromSourceOrCluster(t *testing.T) {

ctx := testutil.TestContext(t)

_, err := packageFromSourceOrCluster(ctx, nil, "test", false)
_, err := packageFromSourceOrCluster(ctx, nil, "test", false, "")
require.EqualError(t, err, "cannot get Zarf package from Kubernetes without configuration")

pkg, err := packageFromSourceOrCluster(ctx, nil, "./testdata/zarf-package-test-amd64-0.0.1.tar.zst", false)
pkg, err := packageFromSourceOrCluster(ctx, nil, "./testdata/zarf-package-test-amd64-0.0.1.tar.zst", false, "")
require.NoError(t, err)
require.Equal(t, "test", pkg.Metadata.Name)

Expand All @@ -154,7 +154,7 @@ func TestPackageFromSourceOrCluster(t *testing.T) {
}
_, err = c.RecordPackageDeployment(ctx, pkg, nil, 1)
require.NoError(t, err)
pkg, err = packageFromSourceOrCluster(ctx, c, "test", false)
pkg, err = packageFromSourceOrCluster(ctx, c, "test", false, "")
require.NoError(t, err)
require.Equal(t, "test", pkg.Metadata.Name)
}
3 changes: 2 additions & 1 deletion src/internal/packager2/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ type RemoveOptions struct {
Cluster *cluster.Cluster
Filter filters.ComponentFilterStrategy
SkipSignatureValidation bool
PublicKeyPath string
}

// Remove removes a package that was already deployed onto a cluster, uninstalling all installed helm charts.
func Remove(ctx context.Context, opt RemoveOptions) error {
pkg, err := packageFromSourceOrCluster(ctx, opt.Cluster, opt.Source, opt.SkipSignatureValidation)
pkg, err := packageFromSourceOrCluster(ctx, opt.Cluster, opt.Source, opt.SkipSignatureValidation, opt.PublicKeyPath)
if err != nil {
return err
}
Expand Down

0 comments on commit 6039d7c

Please sign in to comment.