From 6b00da9832032212d067d1f3ab7816804a8e701e Mon Sep 17 00:00:00 2001 From: Noel Georgi Date: Thu, 23 May 2024 19:13:15 +0530 Subject: [PATCH] chore: explicitly pass the pkg name This simplifies the code a bit. Signed-off-by: Noel Georgi --- cmd/extensions-validator/cmd/validate.go | 31 ++++-------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/cmd/extensions-validator/cmd/validate.go b/cmd/extensions-validator/cmd/validate.go index 6cebc79..3514bfb 100644 --- a/cmd/extensions-validator/cmd/validate.go +++ b/cmd/extensions-validator/cmd/validate.go @@ -7,13 +7,11 @@ package cmd import ( "errors" "fmt" - "os" "strings" "github.com/blang/semver/v4" "github.com/siderolabs/talos/pkg/machinery/extensions" "github.com/spf13/cobra" - "gopkg.in/yaml.v3" ) var validateCmd = &cobra.Command{ @@ -29,22 +27,16 @@ var validateCmd = &cobra.Command{ var ( rootfsPath string - pkgFile string + pkgName string ) func init() { validateCmd.Flags().StringVar(&rootfsPath, "rootfs", "", "Path to the rootfs") validateCmd.MarkFlagRequired("rootfs") //nolint:errcheck - validateCmd.Flags().StringVar(&pkgFile, "pkg-file", "", "Path to the pkg.yaml file") + validateCmd.Flags().StringVar(&pkgName, "pkg-name", "", "Pkg name defined in the pkg file") rootCmd.AddCommand(validateCmd) } -// PartialPkgFile represents a partial package file -// we only care about the name field. -type PartialPkgFile struct { - Name string `yaml:"name"` -} - func validateRootfs() error { if rootfsPath == "" { return errors.New("rootfs path is required") @@ -55,22 +47,9 @@ func validateRootfs() error { return fmt.Errorf("error loading extension: %w", err) } - if pkgFile != "" { - // load the pkg file - pkgFileData, err := os.ReadFile(pkgFile) - if err != nil { - return fmt.Errorf("error loading pkg file: %w", err) - } - - var pkg PartialPkgFile - - // unmarshal the pkg file - if err := yaml.Unmarshal(pkgFileData, &pkg); err != nil { - return fmt.Errorf("error unmarshalling pkg file: %w", err) - } - - if pkg.Name != extension.Manifest.Metadata.Name { - return fmt.Errorf("pkg name does not match extension name: %s != %s", pkg.Name, extension.Manifest.Metadata.Name) + if pkgName != "" { + if pkgName != extension.Manifest.Metadata.Name { + return fmt.Errorf("pkg name does not match extension name: %s != %s", pkgName, extension.Manifest.Metadata.Name) } }