-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Parse normalised specifications (#17)
- Loading branch information
1 parent
f19e57b
commit 813a4d9
Showing
23 changed files
with
1,022 additions
and
481 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output: | ||
go_sdk: "../generated/pango" | ||
terraform_provider: "../generated/terraform-provider-panos" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/paloaltonetworks/pan-os-codegen/pkg/mktp" | ||
"github.com/paloaltonetworks/pan-os-codegen/pkg/mktp" | ||
) | ||
|
||
func main() { | ||
var err error | ||
ctx := context.Background() | ||
var err error | ||
ctx := context.Background() | ||
|
||
cmd := mktp.Command(ctx, os.Args[1:]...) | ||
err = cmd.Setup() | ||
if err == nil { | ||
err = cmd.Execute() | ||
} | ||
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) | ||
} | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, err.Error()+"\n") | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
module github.com/paloaltonetworks/pan-os-codegen | ||
|
||
require gopkg.in/yaml.v3 v3.0.1 | ||
require ( | ||
github.com/stretchr/testify v1.8.4 | ||
gopkg.in/yaml.v3 v3.0.1 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
) | ||
|
||
go 1.21.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
package load | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
|
||
"gopkg.in/yaml.v3" | ||
"encoding/json" | ||
"fmt" | ||
"gopkg.in/yaml.v3" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func Unmarshal(v []byte, o interface{}) error { | ||
var err error | ||
|
||
func File(v []byte, o interface{}) error { | ||
var err error | ||
runes := []byte(strings.TrimSpace(string(v))) | ||
if len(runes) == 0 { | ||
return fmt.Errorf("no data in file") | ||
} | ||
|
||
runes := []byte(strings.TrimSpace(string(v))) | ||
if len(runes) == 0 { | ||
return fmt.Errorf("no data in file") | ||
} | ||
if runes[0] == '{' && runes[len(runes)-1] == '}' { | ||
err = json.Unmarshal(v, o) | ||
} else { | ||
err = yaml.Unmarshal(v, o) | ||
} | ||
|
||
if runes[0] == '{' && runes[len(runes)-1] == '}' { | ||
err = json.Unmarshal(v, o) | ||
} else { | ||
err = yaml.Unmarshal(v, o) | ||
} | ||
return err | ||
} | ||
|
||
return err | ||
func File(path string) ([]byte, error) { | ||
content, err := os.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return content, err | ||
} |
Oops, something went wrong.