feat: also accept hujson files

This commit is contained in:
Johan Siebens
2024-01-20 10:44:20 +01:00
parent 7fa31bdf1f
commit 3fccde2932
5 changed files with 34 additions and 5 deletions
+12 -2
View File
@@ -9,7 +9,7 @@ import (
"github.com/jsiebens/go-edit/editor"
api "github.com/jsiebens/ionscale/pkg/gen/ionscale/v1"
"github.com/spf13/cobra"
"io/ioutil"
"github.com/tailscale/hujson"
"os"
)
@@ -104,6 +104,11 @@ func editACLConfigCommand() *cobra.Command {
defer os.Remove(s)
next, err = hujson.Standardize(next)
if err != nil {
return err
}
var policy = &api.ACLPolicy{}
if err := json.Unmarshal(next, policy); err != nil {
return err
@@ -141,7 +146,12 @@ func setACLConfigCommand() *cobra.Command {
command.PreRunE = checkRequiredTailnetAndTailnetIdFlags
command.RunE = func(cmd *cobra.Command, args []string) error {
rawJson, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
return err
}
rawJson, err := hujson.Standardize(content)
if err != nil {
return err
}
+7 -1
View File
@@ -7,6 +7,7 @@ import (
"github.com/bufbuild/connect-go"
api "github.com/jsiebens/ionscale/pkg/gen/ionscale/v1"
"github.com/spf13/cobra"
"github.com/tailscale/hujson"
"gopkg.in/yaml.v2"
"os"
"tailscale.com/tailcfg"
@@ -98,7 +99,12 @@ func setDefaultDERPMap() *cobra.Command {
return err
}
rawJson, err := os.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
return err
}
rawJson, err := hujson.Standardize(content)
if err != nil {
return err
}
+12 -2
View File
@@ -9,7 +9,7 @@ import (
"github.com/jsiebens/go-edit/editor"
api "github.com/jsiebens/ionscale/pkg/gen/ionscale/v1"
"github.com/spf13/cobra"
"io/ioutil"
"github.com/tailscale/hujson"
"os"
)
@@ -102,6 +102,11 @@ func editIAMPolicyCommand() *cobra.Command {
return err
}
next, err = hujson.Standardize(next)
if err != nil {
return err
}
defer os.Remove(s)
var policy = &api.IAMPolicy{}
@@ -141,7 +146,12 @@ func setIAMPolicyCommand() *cobra.Command {
command.PreRunE = checkRequiredTailnetAndTailnetIdFlags
command.RunE = func(cmd *cobra.Command, args []string) error {
rawJson, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
return err
}
rawJson, err := hujson.Standardize(content)
if err != nil {
return err
}