51 lines
989 B
Go
51 lines
989 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"github.com/goccy/go-yaml"
|
|
"github.com/spf13/cobra"
|
|
"os"
|
|
)
|
|
|
|
type Options struct {
|
|
}
|
|
|
|
func execute(files []string, options *Options) error {
|
|
if len(files) != 1 {
|
|
return fmt.Errorf("File expected")
|
|
}
|
|
yamlFile, err := os.ReadFile(files[0])
|
|
if err != nil {
|
|
return fmt.Errorf("Error reading YAML file: %v", err)
|
|
}
|
|
|
|
// Parse the YAML content
|
|
dec := yaml.NewDecoder(bytes.NewReader(yamlFile),
|
|
yaml.UseJSONUnmarshaler(),
|
|
yaml.DisallowUnknownField(),
|
|
)
|
|
var config Config
|
|
err = dec.Decode(&config)
|
|
if err != nil {
|
|
return fmt.Errorf("Error parsing YAML: %v", err)
|
|
}
|
|
|
|
fmt.Printf("PARSED %+v\n", config)
|
|
return nil
|
|
}
|
|
|
|
func main() {
|
|
options := Options{}
|
|
cmd := &cobra.Command{
|
|
Use: "policygen",
|
|
Short: "Generate network policies",
|
|
Long: "Generated policies based on a more compact representation of topology",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return execute(args, &options)
|
|
},
|
|
}
|
|
|
|
cmd.Execute()
|
|
}
|