diff --git a/README.md b/README.md index 7517b5df..02410f5c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,15 @@ # PAN-OS Code Generation Repository (pan-os-codegen) -Welcome to the PAN-OS Code Generation Repository! This repository provides tools for generating the [pango SDK](https://github.com/PaloAltoNetworks/pango) and the `panos` [Terraform provider](https://github.com/PaloAltoNetworks/terraform-provider-panos) for Palo Alto Networks PAN-OS devices. +Welcome to the PAN-OS Code Generation Repository! This repository provides tools for generating +the [pango SDK](https://github.com/PaloAltoNetworks/pango) and +the `panos` [Terraform provider](https://github.com/PaloAltoNetworks/terraform-provider-panos) for Palo Alto Networks +PAN-OS devices. ## Overview -PAN-OS is the operating system for Palo Alto Networks next-generation firewalls and Panorama, providing advanced security features and capabilities. This repository aims to simplify the process of building and maintainging the Go SDK and Terraform provider. +PAN-OS is the operating system for Palo Alto Networks next-generation firewalls and Panorama, providing advanced +security features and capabilities. This repository aims to simplify the process of building and maintainging the Go SDK +and Terraform provider. The repository contains: @@ -13,7 +18,8 @@ The repository contains: ## Roadmap -We are maintaining a [public roadmap](https://github.com/orgs/PaloAltoNetworks/projects/62) to help users understand when we will release new features, bug fixes and enhancements. +We are maintaining a [public roadmap](https://github.com/orgs/PaloAltoNetworks/projects/62) to help users understand +when we will release new features, bug fixes and enhancements. ## Getting Help @@ -21,6 +27,14 @@ Open an [issue](https://github.com/PaloAltoNetworks/pan-os-codegen/issues) on Gi ## Usage +The code have run login in `cmd/codegen` directory, to run it with default option please use: + ```bash -go run cmd/mktp/main.go cmd/mktp/config.yaml -``` \ No newline at end of file +go run cmd/codegen/main.go +``` +This command can be parametrizes using options: +- `-t/-type` - operation type, default is to create both Terraform + - `mktp` - create only Terraform provider + - `mksdk` - create only PAN-OS SDK +- `config` - specify path for the config file, default is `cmd/codegen/config.yaml` + diff --git a/SUPPORT.md b/SUPPORT.md index b67ba409..84e99291 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -1,3 +1,7 @@ # Community Supported -This template/script/solution is released “as-is”, with no warranty and no support. These should be seen as community supported and Palo Alto Networks may contribute its expertise at its discretion. Palo Alto Networks, including through its Authorized Support Centers (ASC) partners and backline support options, will not provide technical support or help in using or troubleshooting this template/script/solution. The underlying product used by this template/script/solution will still be supported in accordance with the product’s applicable support policy and the customer’s entitlements. \ No newline at end of file +This template/script/solution is released “as-is”, with no warranty and no support. These should be seen as community +supported and Palo Alto Networks may contribute its expertise at its discretion. Palo Alto Networks, including through +its Authorized Support Centers (ASC) partners and backline support options, will not provide technical support or help +in using or troubleshooting this template/script/solution. The underlying product used by this template/script/solution +will still be supported in accordance with the product’s applicable support policy and the customer’s entitlements. \ No newline at end of file diff --git a/cmd/mktp/config.yaml b/cmd/codegen/config.yaml similarity index 100% rename from cmd/mktp/config.yaml rename to cmd/codegen/config.yaml diff --git a/cmd/codegen/main.go b/cmd/codegen/main.go new file mode 100644 index 00000000..75f25a27 --- /dev/null +++ b/cmd/codegen/main.go @@ -0,0 +1,86 @@ +package main + +import ( + "context" + "flag" + "log" + + "github.com/paloaltonetworks/pan-os-codegen/pkg/commands/codegen" +) + +// Config holds the configuration values for the application +type Config struct { + ConfigFile string + OpType string +} + +// parseFlags parses the command line flags +func parseFlags() Config { + var cfg Config + flag.StringVar(&cfg.ConfigFile, "config", "./cmd/codegen/config.yaml", "Path to the configuration file") + flag.StringVar(&cfg.OpType, "t", "", "Operation type: 'mktp', 'mksdk' or leave empty for both") + flag.StringVar(&cfg.OpType, "type", "", "Operation type: 'mktp', 'mksdk' or leave empty for both") + flag.Parse() + return cfg +} + +func main() { + cfg := parseFlags() + + ctx := context.Background() + log.SetFlags(log.Ldate | log.Lshortfile) + + // Log the operation type and configuration file being used + opTypeMessage := "Operation type: " + if cfg.OpType == "" { + opTypeMessage += "default option, create both PAN-OS SDK and Terraform Provider" + } else { + opTypeMessage += cfg.OpType + } + log.Printf("Using configuration file: %s\n", cfg.ConfigFile) + log.Println(opTypeMessage) + + cmdType := codegen.CommandTypeSDK // Default command type + if cfg.OpType == "mktp" { + cmdType = codegen.CommandTypeTerraform + } else if cfg.OpType == "mksdk" { + cmdType = codegen.CommandTypeSDK + } + + if cfg.OpType == "mktp" || cfg.OpType == "mksdk" { + cmd, err := codegen.NewCommand(ctx, cmdType, cfg.ConfigFile) + if err != nil { + log.Fatalf("Failed to create command: %s", err) + } + if err := cmd.Setup(); err != nil { + log.Fatalf("Setup failed: %s", err) + } + if err := cmd.Execute(); err != nil { + log.Fatalf("Execution failed: %s", err) + } + } else { // Default behavior to execute both if no specific OpType is provided + // Execute SDK + cmdSDK, err := codegen.NewCommand(ctx, codegen.CommandTypeSDK, cfg.ConfigFile) + if err != nil { + log.Fatalf("Failed to create command: %s", err) + } + if err := cmdSDK.Setup(); err != nil { + log.Fatalf("Setup SDK failed: %s", err) + } + if err := cmdSDK.Execute(); err != nil { + log.Fatalf("Execution SDK failed: %s", err) + } + + // Execute Terraform + cmdTP, err := codegen.NewCommand(ctx, codegen.CommandTypeTerraform, cfg.ConfigFile) + if err != nil { + log.Fatalf("Failed to create command: %s", err) + } + if err := cmdTP.Setup(); err != nil { + log.Fatalf("Setup Terraform failed: %s", err) + } + if err := cmdTP.Execute(); err != nil { + log.Fatalf("Execution Terraform failed: %s", err) + } + } +} diff --git a/cmd/mktp/main.go b/cmd/mktp/main.go deleted file mode 100644 index 6a05fb77..00000000 --- a/cmd/mktp/main.go +++ /dev/null @@ -1,25 +0,0 @@ -package main - -import ( - "context" - "fmt" - "os" - - "github.com/paloaltonetworks/pan-os-codegen/pkg/mktp" -) - -func main() { - var err error - ctx := context.Background() - - cmd := mktp.Command(ctx, os.Args[1:]...) - err = cmd.Setup() - if err == nil { - err = cmd.Execute() - } - - if err != nil { - fmt.Fprintf(os.Stderr, err.Error()+"\n") - os.Exit(1) - } -} diff --git a/pkg/commands/codegen/codegen.go b/pkg/commands/codegen/codegen.go new file mode 100644 index 00000000..e35bcc48 --- /dev/null +++ b/pkg/commands/codegen/codegen.go @@ -0,0 +1,105 @@ +package codegen + +import ( + "context" + "fmt" + "log" + + "github.com/paloaltonetworks/pan-os-codegen/pkg/generate" + "github.com/paloaltonetworks/pan-os-codegen/pkg/load" + "github.com/paloaltonetworks/pan-os-codegen/pkg/properties" +) + +type CommandType string + +const ( + CommandTypeSDK CommandType = "sdk" + CommandTypeTerraform CommandType = "terraform" +) + +type Command struct { + ctx context.Context + args []string + specs []string + config string + commandType CommandType + templatePath string +} + +func NewCommand(ctx context.Context, commandType CommandType, args ...string) (*Command, error) { + var templatePath string + switch commandType { + case CommandTypeSDK: + templatePath = "templates/sdk" + case CommandTypeTerraform: + templatePath = "templates/terraform" + default: + return nil, fmt.Errorf("unsupported command type: %s", commandType) + } + + return &Command{ + ctx: ctx, + args: args, + commandType: commandType, + templatePath: templatePath, + }, nil +} + +func (c *Command) Setup() error { + var err error + if c.specs == nil { + c.specs, err = properties.GetNormalizations() + if err != nil { + return fmt.Errorf("error getting normalizations: %s", err) + } + } + return nil +} + +func (c *Command) Execute() error { + log.Printf("Generating %s\n", c.commandType) + + if len(c.args) == 0 { + return fmt.Errorf("path to configuration file is required") + } + configPath := c.args[0] + + content, err := load.File(configPath) + if err != nil { + return fmt.Errorf("error loading %s - %s", configPath, err) + } + + config, err := properties.ParseConfig(content) + if err != nil { + return fmt.Errorf("error parsing %s - %s", configPath, err) + } + + for _, specPath := range c.specs { + log.Printf("Parsing %s...\n", specPath) + content, err := load.File(specPath) + if err != nil { + return fmt.Errorf("error loading %s - %s", specPath, err) + } + + spec, err := properties.ParseSpec(content) + if err != nil { + return fmt.Errorf("error parsing %s - %s", specPath, err) + } + + if err = spec.Sanity(); err != nil { + return fmt.Errorf("%s sanity failed: %s", specPath, err) + } + + generator := generate.NewCreator(config.Output.GoSdk, c.templatePath, spec) + if err = generator.RenderTemplate(); err != nil { + return fmt.Errorf("error rendering %s - %s", specPath, err) + } + } + + if err = generate.CopyAssets(config); err != nil { + return fmt.Errorf("error copying assets %s", err) + } + + log.Println("Generation complete.") + return nil +} diff --git a/pkg/commands/codegen/codegen_test.go b/pkg/commands/codegen/codegen_test.go new file mode 100644 index 00000000..7216608e --- /dev/null +++ b/pkg/commands/codegen/codegen_test.go @@ -0,0 +1,83 @@ +package codegen + +import ( + "context" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNewCommand(t *testing.T) { + // given + tests := []struct { + name string + commandType CommandType + wantPath string + }{ + {"SDK Command", CommandTypeSDK, "templates/sdk"}, + {"Terraform Command", CommandTypeTerraform, "templates/terraform"}, + } + + for _, tt := range tests { + // when + t.Run(tt.name, func(t *testing.T) { + ctx := context.Background() + cmd, err := NewCommand(ctx, tt.commandType, "dummyArg") + + // then + assert.NoError(t, err) + assert.Equal(t, tt.wantPath, cmd.templatePath) + }) + } +} + +func TestCommandFunctionality(t *testing.T) { + // given + ctx := context.Background() + cmdType := CommandTypeSDK + + // Create a temporary file to simulate the config file + tmpDir := t.TempDir() + tmpFile, err := os.Create(filepath.Join(tmpDir, "config-*.yaml")) + assert.NoError(t, err) + defer func(name string) { + err := os.Remove(name) + if err != nil { + assert.NoError(t, err) + } + }(tmpFile.Name()) + + // Write the necessary configuration data to the temporary file + configData := ` +output: + go_sdk: "../generated/pango" + terraform_provider: "../generated/terraform-provider-panos" +` + _, err = tmpFile.WriteString(configData) + assert.NoError(t, err) + err = tmpFile.Close() + assert.NoError(t, err) + + // when + cmd, err := NewCommand(ctx, cmdType, tmpFile.Name()) + assert.NoError(t, err) + + // then + assert.NoError(t, cmd.Setup(), "Setup should not return an error") +} +func TestCommandSetup(t *testing.T) { + //given + ctx := context.Background() + + cmd, err := NewCommand(ctx, CommandTypeSDK, "config.yml") + assert.NoError(t, err) + + // when + err = cmd.Setup() + + //then + assert.NoError(t, err) + +} diff --git a/pkg/generate/assets.go b/pkg/generate/assets.go index 2b0c9904..39078e78 100644 --- a/pkg/generate/assets.go +++ b/pkg/generate/assets.go @@ -2,10 +2,10 @@ package generate import ( "bytes" - "fmt" "github.com/paloaltonetworks/pan-os-codegen/pkg/properties" "io" "io/fs" + "log" "os" "path/filepath" ) @@ -64,7 +64,7 @@ func copyAsset(target string, asset *properties.Asset, files []string) error { for _, sourceFilePath := range files { // Prepare destination path destinationFilePath := filepath.Join(destinationDir, filepath.Base(sourceFilePath)) - fmt.Printf("Copy file from %s to %s\n", sourceFilePath, destinationFilePath) + log.Printf("Copy file from %s to %s\n", sourceFilePath, destinationFilePath) // Read the contents of the source file data, err := os.ReadFile(sourceFilePath) diff --git a/pkg/generate/generator.go b/pkg/generate/generator.go index 58aac891..62224c90 100644 --- a/pkg/generate/generator.go +++ b/pkg/generate/generator.go @@ -2,14 +2,14 @@ package generate import ( "fmt" - "github.com/paloaltonetworks/pan-os-codegen/pkg/properties" - "github.com/paloaltonetworks/pan-os-codegen/pkg/translate" - "io" - "io/fs" + "log" "os" "path/filepath" "strings" "text/template" + + "github.com/paloaltonetworks/pan-os-codegen/pkg/properties" + "github.com/paloaltonetworks/pan-os-codegen/pkg/translate" ) type Creator struct { @@ -18,7 +18,7 @@ type Creator struct { Spec *properties.Normalization } -func NewCreator(goOutputDir string, templatesDir string, spec *properties.Normalization) *Creator { +func NewCreator(goOutputDir, templatesDir string, spec *properties.Normalization) *Creator { return &Creator{ GoOutputDir: goOutputDir, TemplatesDir: templatesDir, @@ -27,87 +27,57 @@ func NewCreator(goOutputDir string, templatesDir string, spec *properties.Normal } func (c *Creator) RenderTemplate() error { - templates := make([]string, 0, 100) - templates, err := c.listOfTemplates(templates) + log.Println("Start rendering templates") + + templates, err := c.listOfTemplates() if err != nil { - return err + return fmt.Errorf("error listing templates: %w", err) } for _, templateName := range templates { - filePath := c.createFullFilePath(c.GoOutputDir, c.Spec, templateName) - fmt.Printf("Create file %s\n", filePath) + filePath := c.createFullFilePath(templateName) + log.Printf("Creating file: %s\n", filePath) - if err := c.makeAllDirs(filePath, err); err != nil { - return err + if err := c.makeAllDirs(filePath); err != nil { + return fmt.Errorf("error creating directories for %s: %w", filePath, err) } - outputFile, err := c.createFile(filePath) + outputFile, err := os.Create(filePath) if err != nil { - return err + return fmt.Errorf("error creating file %s: %w", filePath, err) } - defer func(outputFile *os.File) { - err := outputFile.Close() - if err != nil { - - } - }(outputFile) + defer outputFile.Close() tmpl, err := c.parseTemplate(templateName) if err != nil { - return err + return fmt.Errorf("error parsing template %s: %w", templateName, err) } - err = c.generateOutputFileFromTemplate(tmpl, outputFile, c.Spec) - if err != nil { - return err + if err := tmpl.Execute(outputFile, c.Spec); err != nil { + return fmt.Errorf("error executing template %s: %w", templateName, err) } } return nil } -func (c *Creator) generateOutputFileFromTemplate(tmpl *template.Template, output io.Writer, spec *properties.Normalization) error { - if err := tmpl.Execute(output, spec); err != nil { - return err - } - return nil -} - -func (c *Creator) parseTemplate(templateName string) (*template.Template, error) { - templatePath := fmt.Sprintf("%s/%s", c.TemplatesDir, templateName) - funcMap := template.FuncMap{ - "packageName": translate.PackageName, - "locationType": translate.LocationType, - "specParamType": translate.SpecParamType, - "omitEmpty": translate.OmitEmpty, - "contains": func(full, part string) bool { - return strings.Contains(full, part) - }, - "subtract": func(a, b int) int { - return a - b - }, - "asEntryXpath": translate.AsEntryXpath, - } - tmpl, err := template.New(templateName).Funcs(funcMap).ParseFiles(templatePath) - if err != nil { - return nil, err - } - return tmpl, nil -} -func (c *Creator) createFullFilePath(goOutputDir string, spec *properties.Normalization, templateName string) string { - return fmt.Sprintf("%s/%s/%s.go", goOutputDir, strings.Join(spec.GoSdkPath, "/"), strings.Split(templateName, ".")[0]) +func (c *Creator) createFullFilePath(templateName string) string { + fileBaseName := strings.TrimSuffix(templateName, filepath.Ext(templateName)) + return filepath.Join(c.GoOutputDir, filepath.Join(c.Spec.GoSdkPath...), fileBaseName+".go") } -func (c *Creator) listOfTemplates(files []string) ([]string, error) { - err := filepath.WalkDir(c.TemplatesDir, func(path string, entry fs.DirEntry, err error) error { +func (c *Creator) listOfTemplates() ([]string, error) { + var files []string + err := filepath.WalkDir(c.TemplatesDir, func(path string, entry os.DirEntry, err error) error { if err != nil { return err } - + if entry.IsDir() { + return nil + } if strings.HasSuffix(entry.Name(), ".tmpl") { - files = append(files, filepath.Base(path)) + files = append(files, entry.Name()) } - return nil }) if err != nil { @@ -116,6 +86,11 @@ func (c *Creator) listOfTemplates(files []string) ([]string, error) { return files, nil } +func (c *Creator) makeAllDirs(filePath string) error { + dirPath := filepath.Dir(filePath) + return os.MkdirAll(dirPath, os.ModePerm) +} + func (c *Creator) createFile(filePath string) (*os.File, error) { outputFile, err := os.Create(filePath) if err != nil { @@ -124,10 +99,21 @@ func (c *Creator) createFile(filePath string) (*os.File, error) { return outputFile, nil } -func (c *Creator) makeAllDirs(filePath string, err error) error { - dirPath := filepath.Dir(filePath) - if err = os.MkdirAll(dirPath, os.ModePerm); err != nil { - return err + +func (c *Creator) parseTemplate(templateName string) (*template.Template, error) { + templatePath := filepath.Join(c.TemplatesDir, templateName) + funcMap := template.FuncMap{ + "packageName": translate.PackageName, + "locationType": translate.LocationType, + "specParamType": translate.SpecParamType, + "omitEmpty": translate.OmitEmpty, + "contains": func(full, part string) bool { + return strings.Contains(full, part) + }, + "subtract": func(a, b int) int { + return a - b + }, + "asEntryXpath": translate.AsEntryXpath, } - return nil + return template.New(templateName).Funcs(funcMap).ParseFiles(templatePath) } diff --git a/pkg/generate/generator_test.go b/pkg/generate/generator_test.go index 51de2e59..3961c139 100644 --- a/pkg/generate/generator_test.go +++ b/pkg/generate/generator_test.go @@ -2,24 +2,29 @@ package generate import ( "bytes" + "os" + "path/filepath" + "strings" + "testing" + "github.com/paloaltonetworks/pan-os-codegen/pkg/properties" "github.com/stretchr/testify/assert" - "testing" + "github.com/stretchr/testify/require" ) func TestCreateFullFilePath(t *testing.T) { // given - spec := properties.Normalization{ - GoSdkPath: []string{"go"}, + spec := &properties.Normalization{ + GoSdkPath: []string{"path", "to", "go"}, } - generator := NewCreator("test", "../../templates/sdk", &spec) - + expected := filepath.Join("test_output", "path", "to", "go", "template.go") // when - fullFilePath := generator.createFullFilePath("output", &spec, "template.tmpl") + + generator := NewCreator("test_output", "templates", spec) + fullFilePath := generator.createFullFilePath("template.tmpl") // then - assert.NotNil(t, fullFilePath) - assert.Equal(t, "output/go/template.go", fullFilePath) + assert.Equal(t, expected, fullFilePath) } // NOTE - unit tests should only touch code inside package, do not reference external resources. @@ -31,37 +36,55 @@ func TestCreateFullFilePath(t *testing.T) { func TestListOfTemplates(t *testing.T) { // given - spec := properties.Normalization{ - GoSdkPath: []string{"go"}, + + tempDir := t.TempDir() + templateNames := []string{"test1.tmpl", "test2.tmpl"} + for _, name := range templateNames { + file, err := os.Create(filepath.Join(tempDir, name)) + assert.NoError(t, err) + err = file.Close() + if err != nil { + assert.NoError(t, err) + } } - generator := NewCreator("test", "../../templates/sdk", &spec) // when - var templates []string - templates, _ = generator.listOfTemplates(templates) + spec := &properties.Normalization{} + generator := NewCreator("", tempDir, spec) + templates, err := generator.listOfTemplates() + + require.NoError(t, err) + assert.Len(t, templates, len(templateNames)) // then - assert.Equal(t, 4, len(templates)) + for _, template := range templates { + assert.True(t, strings.Contains(strings.Join(templateNames, " "), template)) + } } func TestParseTemplateForInterfaces(t *testing.T) { // given - spec := properties.Normalization{ - GoSdkPath: []string{"object", "address"}, - } - generator := NewCreator("test", "../../templates/sdk", &spec) - expectedFileContent := `package address + tempDir := t.TempDir() + templateContent := `package {{.GoSdkPath}} -type Specifier func(Entry) (any, error) +type Entry struct {}` + templatePath := filepath.Join(tempDir, "test.tmpl") + err := os.WriteFile(templatePath, []byte(templateContent), 0644) + assert.NoError(t, err) -type Normalizer interface { - Normalize() ([]Entry, error) -}` + spec := &properties.Normalization{ + GoSdkPath: []string{"object", "address"}, + } + generator := NewCreator("", tempDir, spec) + template, err := generator.parseTemplate("test.tmpl") + assert.NoError(t, err) // when - template, _ := generator.parseTemplate("interfaces.tmpl") var output bytes.Buffer - _ = generator.generateOutputFileFromTemplate(template, &output, generator.Spec) + err = template.Execute(&output, spec) + assert.NoError(t, err) + + expectedFileContent := "package [object address]\n\ntype Entry struct {}" // then assert.Equal(t, expectedFileContent, output.String()) diff --git a/pkg/mktp/cmd.go b/pkg/mktp/cmd.go deleted file mode 100644 index 66d3960e..00000000 --- a/pkg/mktp/cmd.go +++ /dev/null @@ -1,132 +0,0 @@ -package mktp - -import ( - "context" - "fmt" - "github.com/paloaltonetworks/pan-os-codegen/pkg/generate" - "github.com/paloaltonetworks/pan-os-codegen/pkg/load" - "io" - "os" - _ "os/exec" - _ "path/filepath" - _ "sort" - _ "strings" - - "github.com/paloaltonetworks/pan-os-codegen/pkg/properties" -) - -type Cmd struct { - Stdin io.Reader - Stdout io.Writer - Stderr io.Writer - - ctx context.Context - args []string - specs []string - config string -} - -func Command(ctx context.Context, args ...string) *Cmd { - return &Cmd{ - ctx: ctx, - args: args, - } -} - -func (c *Cmd) Setup() error { - var err error - - if c.Stdin == nil { - c.Stdin = os.Stdin - } - - if c.Stdout == nil { - c.Stdout = os.Stdout - } - - if c.Stderr == nil { - c.Stderr = os.Stderr - } - - if c.specs == nil { - c.specs, err = properties.GetNormalizations() - } - - return err -} - -func (c *Cmd) Execute() error { - // TODO(shinmog): everything - fmt.Fprintf(c.Stdout, "Making pango / panos Terraform provider\n") - - //providerDataSources := make([]string, 0, 200) - //providerResources := make([]string, 0, 100) - - // Check if path to configuration file is passed as argument - if len(c.args) == 0 { - return fmt.Errorf("path to configuration file is required") - } - configPath := c.args[0] - - // Load configuration file - content, err := load.File(configPath) - if err != nil { - return fmt.Errorf("error loading %s - %s", configPath, err) - } - - // Parse configuration file - config, err := properties.ParseConfig(content) - if err != nil { - return fmt.Errorf("error parsing %s - %s", configPath, err) - } - - for _, specPath := range c.specs { - fmt.Fprintf(c.Stdout, "Parsing %s...\n", specPath) - - // Load YAML file - content, err := load.File(specPath) - if err != nil { - return fmt.Errorf("error loading %s - %s", specPath, err) - } - - // Parse content - spec, err := properties.ParseSpec(content) - if err != nil { - return fmt.Errorf("error parsing %s - %s", specPath, err) - } - - // Sanity check. - if err = spec.Sanity(); err != nil { - return fmt.Errorf("%s sanity failed: %s", specPath, err) - } - - // Output normalization as pango code. - generator := generate.NewCreator(config.Output.GoSdk, "templates/sdk", spec) - if err = generator.RenderTemplate(); err != nil { - return fmt.Errorf("error rendering %s - %s", specPath, err) - } - - // Output as Terraform code. - } - - // Copy assets (static files) - if err = generate.CopyAssets(config); err != nil { - return fmt.Errorf("error copying assets %s", err) - } - - // Finalize pango code: - // * make fmt - - // Finalize Terraform code. - // * output provider.go - // * write any static files - // * make fmt - // * output examples to ./examples - // * make docs - // * docs modifications (e.g. - subcategories) - - // Done. - fmt.Fprintf(c.Stdout, "Done\n") - - return nil -} diff --git a/pkg/naming/names.go b/pkg/naming/names.go index 5ab3925a..b5287225 100644 --- a/pkg/naming/names.go +++ b/pkg/naming/names.go @@ -115,7 +115,7 @@ func CamelCase(prefix, value, suffix string, capitalizeFirstRune bool) string { return b.String() } -// AlphaNumeric returns an alpha numeric version of the given string. +// AlphaNumeric returns an alphanumeric version of the given string. func AlphaNumeric(value string) string { var b strings.Builder b.Grow(len(value)) diff --git a/specs/README.md b/specs/README.md index c4630206..1adc805e 100644 --- a/specs/README.md +++ b/specs/README.md @@ -1,4 +1,5 @@ Specs ----- -The specs to be normalized are in this directory. These specs are then turned into pango code, which is then used in the panos Terraform provider. +The specs to be normalized are in this directory. These specs are then turned into pango code, which is then used in the +panos Terraform provider.