Skip to content

Commit

Permalink
Generate exclusive file feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel Imielowski committed Mar 29, 2024
1 parent 5071a16 commit e7e3648
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 10 deletions.
23 changes: 14 additions & 9 deletions pkg/commands/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,20 @@ func (c *Command) validateSpec(spec *properties.Normalization, specPath string)

// generateOutput generate the output with the spec and config
func (c *Command) generateOutput(config *properties.Config, spec *properties.Normalization, specPath string) error {
outputPath := config.Output
log.Printf("[DEBUG] print List of outputList -> %s \n", outputPath)

for _, output := range outputPath.PathList() {
log.Printf("[DEBUG] print List of output -> %s \n", output)
generator := generate.NewCreator(output, c.templatePath, spec)
if err := generator.RenderTemplate(string(c.commandType)); err != nil {
return fmt.Errorf("error rendering %s - %s", specPath, err)
}
var output string

switch c.commandType {
case CommandTypeSDK:
output = config.Output.GoSdk
case CommandTypeTerraform:
output = config.Output.TerraformProvider
}

log.Printf("[DEBUG] print output -> %s \n", output)

generator := generate.NewCreator(output, c.templatePath, spec)
if err := generator.RenderTemplate(string(c.commandType)); err != nil {
return fmt.Errorf("error rendering %s - %s", specPath, err)
}

return nil
Expand Down
6 changes: 5 additions & 1 deletion pkg/properties/normalized.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (

type Normalization struct {
Name string `json:"name" yaml:"name"`
Exclusive string `json:"exclusive" yaml:"exclusive"`
TerraformProviderSuffix string `json:"terraform_provider_suffix" yaml:"terraform_provider_suffix"`
GoSdkPath []string `json:"go_sdk_path" yaml:"go_sdk_path"`
TerraformProviderPath []string `json:"terraform_provider_path" yaml:"terraform_provider_path"`
GoSdkPath []string `json:"go_sdk_path" yaml:"go_sdk_path"`
XpathSuffix []string `json:"xpath_suffix" yaml:"xpath_suffix"`
Locations map[string]*Location `json:"locations" yaml:"locations"`
Entry *Entry `json:"entry" yaml:"entry"`
Expand Down Expand Up @@ -267,6 +268,9 @@ func (spec *Normalization) AddDefaultTypesForParams() error {

// Sanity basic checks for specification (normalization) e.g. check if at least 1 location is defined.
func (spec *Normalization) Sanity(commandType string) error {
if spec.Exclusive == "terraform" || spec.Exclusive == "sdk" {
return nil // we exclusively pass sanity test if the spec file is exclusive for one
}
switch commandType {
case "sdk":
if spec.Name == "" {
Expand Down
3 changes: 3 additions & 0 deletions specs/device/dns.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'DNS'
terraform_provider_suffix: 'dns'
terraform_provider_path:
- 'internal'
- 'provider'
go_sdk_path:
- 'device'
- 'services'
Expand Down
3 changes: 3 additions & 0 deletions specs/device/ntp.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'NTP'
terraform_provider_suffix: 'ntp'
terraform_provider_path:
- 'internal'
- 'provider'
go_sdk_path:
- 'device'
- 'services'
Expand Down
1 change: 1 addition & 0 deletions specs/internal/provider.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: 'Provider'
terraform_provider_suffix: ''
exclusive: 'terraform'
terraform_provider_path:
- 'internal'
- 'provider'
Expand Down
3 changes: 3 additions & 0 deletions specs/objects/address-group.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Address group'
terraform_provider_suffix: 'address_group'
terraform_provider_path:
- 'internal'
- 'provider'
go_sdk_path:
- 'objects'
- 'address'
Expand Down
3 changes: 3 additions & 0 deletions specs/objects/address.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Address'
terraform_provider_suffix: 'address'
terraform_provider_path:
- 'internal'
- 'provider'
go_sdk_path:
- 'objects'
- 'address'
Expand Down
3 changes: 3 additions & 0 deletions specs/objects/service-group.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Service group'
terraform_provider_suffix: 'service_group'
terraform_provider_path:
- 'internal'
- 'provider'
go_sdk_path:
- 'objects'
- 'service'
Expand Down
3 changes: 3 additions & 0 deletions specs/objects/service.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Service'
terraform_provider_suffix: 'service'
terraform_provider_path:
- 'internal'
- 'provider'
go_sdk_path:
- 'objects'
- 'service'
Expand Down
3 changes: 3 additions & 0 deletions specs/objects/tag.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Tag'
terraform_provider_suffix: 'tag'
terraform_provider_path:
- 'internal'
- 'provider'
go_sdk_path:
- 'objects'
- 'tag'
Expand Down
3 changes: 3 additions & 0 deletions specs/panorama/device-group.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Device group'
terraform_provider_suffix: 'device_group'
terraform_provider_path:
- 'internal'
- 'provider'
go_sdk_path:
- 'panorama'
- 'device_group'
Expand Down
3 changes: 3 additions & 0 deletions specs/panorama/template-stack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Template stack'
terraform_provider_suffix: 'template_stack'
terraform_provider_path:
- 'internal'
- 'provider'
go_sdk_path:
- 'panorama'
- 'template_stack'
Expand Down
3 changes: 3 additions & 0 deletions specs/panorama/template.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Template'
terraform_provider_suffix: 'template'
terraform_provider_path:
- 'internal'
- 'provider'
go_sdk_path:
- 'panorama'
- 'template'
Expand Down
3 changes: 3 additions & 0 deletions specs/policies/security-policy-rule.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 'Security policy rule'
terraform_provider_suffix: 'security_policy_rule'
terraform_provider_path:
- 'internal'
- 'provider'
go_sdk_path:
- 'policies'
- 'rules'
Expand Down

0 comments on commit e7e3648

Please sign in to comment.