Skip to content

Commit

Permalink
chore: explicitly pass the pkg name
Browse files Browse the repository at this point in the history
This simplifies the code a bit.

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed May 23, 2024
1 parent 69b32c1 commit 6b00da9
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions cmd/extensions-validator/cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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")
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 6b00da9

Please sign in to comment.