3
0

Remove obsolete settings exporter

This commit is contained in:
Denis Arh
2021-03-11 21:08:52 +01:00
parent 261dd4f74e
commit a41af0699a
3 changed files with 0 additions and 182 deletions
-25
View File
@@ -1,25 +0,0 @@
package settings
import (
"encoding/json"
"github.com/cortezaproject/corteza-server/system/types"
"gopkg.in/yaml.v2"
)
// Export transforms a given ValueSet into a yaml exportable structure
func Export(ss types.SettingValueSet) (o yaml.MapSlice) {
o = yaml.MapSlice{}
for _, s := range ss {
var v interface{}
json.Unmarshal(s.Value, &v)
setting := yaml.MapItem{
Key: s.Name,
Value: v,
}
o = append(o, setting)
}
return o
}
-66
View File
@@ -1,66 +0,0 @@
package settings
import (
"github.com/cortezaproject/corteza-server/system/types"
sqlType "github.com/jmoiron/sqlx/types"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
"testing"
)
func TestExport(t *testing.T) {
req := require.New(t)
tests := []struct {
name, rawValue string
parsedValue interface{}
}{
{
name: "v_string",
rawValue: `"string"`,
parsedValue: yaml.MapItem{Key: "v_string", Value: "string"},
},
{
name: "v_int-as-float",
rawValue: "12.34",
parsedValue: yaml.MapItem{Key: "v_int-as-float", Value: 12.34},
},
{
name: "v_float",
rawValue: "123",
parsedValue: yaml.MapItem{Key: "v_float", Value: 123.0},
},
{
name: "v_bool_true",
rawValue: "true",
parsedValue: yaml.MapItem{Key: "v_bool_true", Value: true},
},
{
name: "v_bool_false",
rawValue: "false",
parsedValue: yaml.MapItem{Key: "v_bool_false", Value: false},
},
{
name: "v_slice",
rawValue: `[1, 1.23, "string", true, false]`,
parsedValue: yaml.MapItem{Key: "v_slice", Value: []interface{}{1.0, 1.23, "string", true, false}},
},
{
name: "v_map",
rawValue: `{"k1": "string","k2": 1,"k3":1.23,"k4":true,"k5":false}`,
parsedValue: yaml.MapItem{Key: "v_map", Value: map[string]interface{}{"k1": "string", "k2": 1.0, "k3": 1.23, "k4": true, "k5": false}},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tt := Export(types.SettingValueSet{
&types.SettingValue{
Name: test.name,
Value: sqlType.JSONText(test.rawValue),
},
})
req.Len(tt, 1)
req.Equal(test.parsedValue, tt[0])
})
}
}
-91
View File
@@ -1,91 +0,0 @@
package commands
import (
"context"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"github.com/cortezaproject/corteza-server/pkg/auth"
"github.com/cortezaproject/corteza-server/pkg/cli"
"github.com/cortezaproject/corteza-server/pkg/rbac"
"github.com/cortezaproject/corteza-server/pkg/settings"
sysExporter "github.com/cortezaproject/corteza-server/system/exporter"
"github.com/cortezaproject/corteza-server/system/service"
sysTypes "github.com/cortezaproject/corteza-server/system/types"
)
func Exporter() *cobra.Command {
cmd := &cobra.Command{
Use: "export",
Short: "Export",
Long: `Export system resources`,
Run: func(cmd *cobra.Command, args []string) {
var (
ctx = auth.SetSuperUserContext(cli.Context())
sFlag = cmd.Flags().Lookup("settings").Changed
pFlag = cmd.Flags().Lookup("permissions").Changed
out = &System{
Settings: yaml.MapSlice{},
}
)
if !sFlag && !pFlag {
cli.HandleError(errors.New("Specify setting or permissions flag"))
}
if pFlag {
permissionExporter(ctx, out)
}
if sFlag {
settingExporter(ctx, out)
}
y := yaml.NewEncoder(cmd.OutOrStdout())
cli.HandleError(y.Encode(out))
},
}
cmd.Flags().BoolP("settings", "s", false, "Export settings")
cmd.Flags().BoolP("permissions", "p", false, "Export system permissions")
return cmd
}
func permissionExporter(ctx context.Context, out *System) {
roles := sysTypes.RoleSet{
&sysTypes.Role{ID: rbac.EveryoneRoleID, Handle: "everyone"},
&sysTypes.Role{ID: rbac.AdminsRoleID, Handle: "admins"},
}
out.Allow = sysExporter.ExportableServicePermissions(roles, rbac.Global(), rbac.Allow)
out.Deny = sysExporter.ExportableServicePermissions(roles, rbac.Global(), rbac.Deny)
}
func settingExporter(ctx context.Context, out *System) {
var (
err error
)
ss, err := service.DefaultSettings.FindByPrefix(ctx)
cli.HandleError(err)
out.Settings = settings.Export(ss)
}
// This is PoC for exporting system resources
//
type (
System struct {
Settings yaml.MapSlice `yaml:",omitempty"`
Allow map[string]map[string][]string `yaml:",omitempty"`
Deny map[string]map[string][]string `yaml:",omitempty"`
}
)