Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
134 lines
2.8 KiB
Go
134 lines
2.8 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/cortezaproject/corteza/server/pkg/cli"
|
|
"github.com/cortezaproject/corteza/server/pkg/envoyx"
|
|
)
|
|
|
|
func Import(ctx context.Context, storeInit storeInitFnc, dalInit dalInitFnc, envoyInit envoyInitFnc) *cobra.Command {
|
|
var (
|
|
replaceOnConflict bool
|
|
skipOnConflict bool
|
|
panicOnConflict bool
|
|
)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "import",
|
|
Short: "Import data from yaml sources.",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
// Init all of the sub services
|
|
s, err := storeInit(ctx)
|
|
cli.HandleError(err)
|
|
|
|
dalSvc, err := dalInit(ctx)
|
|
cli.HandleError(err)
|
|
|
|
envoySvc, err := envoyInit(ctx)
|
|
cli.HandleError(err)
|
|
|
|
var (
|
|
nodes envoyx.NodeSet
|
|
providers []envoyx.Provider
|
|
|
|
auxNodes envoyx.NodeSet
|
|
auxProviders []envoyx.Provider
|
|
)
|
|
|
|
if len(args) > 0 {
|
|
for _, a := range args {
|
|
auxNodes, auxProviders, err = envoySvc.Decode(ctx, envoyx.DecodeParams{
|
|
Type: envoyx.DecodeTypeURI,
|
|
Params: map[string]any{
|
|
"uri": "file://" + a,
|
|
},
|
|
})
|
|
cli.HandleError(err)
|
|
|
|
nodes = append(nodes, auxNodes...)
|
|
providers = append(providers, auxProviders...)
|
|
}
|
|
} else {
|
|
auxNodes, auxProviders, err = envoySvc.Decode(ctx, envoyx.DecodeParams{
|
|
Type: envoyx.DecodeTypeIO,
|
|
Params: map[string]any{
|
|
"reader": os.Stdin,
|
|
"mime": "text/yaml",
|
|
},
|
|
})
|
|
cli.HandleError(err)
|
|
|
|
// @todo consider changing this up
|
|
if len(auxProviders) > 0 {
|
|
cli.HandleError(errors.New("cannot define providers when importing from stdin"))
|
|
}
|
|
|
|
nodes = append(nodes, auxNodes...)
|
|
// providers = append(providers, auxProviders...)
|
|
}
|
|
|
|
ep := envoyx.EncodeParams{
|
|
Type: envoyx.EncodeTypeStore,
|
|
Params: map[string]any{
|
|
"storer": s,
|
|
"dal": dalSvc,
|
|
},
|
|
}
|
|
|
|
if replaceOnConflict {
|
|
ep.Envoy.MergeAlg = envoyx.OnConflictReplace
|
|
}
|
|
if skipOnConflict {
|
|
ep.Envoy.MergeAlg = envoyx.OnConflictSkip
|
|
}
|
|
if panicOnConflict {
|
|
ep.Envoy.MergeAlg = envoyx.OnConflictPanic
|
|
}
|
|
|
|
gg, err := envoySvc.Bake(ctx, ep,
|
|
providers,
|
|
nodes...,
|
|
)
|
|
cli.HandleError(err)
|
|
|
|
err = envoySvc.Encode(ctx, envoyx.EncodeParams{
|
|
Type: envoyx.EncodeTypeStore,
|
|
Params: map[string]any{
|
|
"storer": s,
|
|
"dal": dalSvc,
|
|
},
|
|
}, gg)
|
|
cli.HandleError(err)
|
|
},
|
|
}
|
|
|
|
cmd.Flags().BoolVar(
|
|
&replaceOnConflict,
|
|
"replace-existing",
|
|
false,
|
|
"replace on conflict existing resources. Default skips",
|
|
)
|
|
|
|
cmd.Flags().BoolVar(
|
|
&skipOnConflict,
|
|
"skip-existing",
|
|
false,
|
|
"skip on conflict existing resources. Default skips",
|
|
)
|
|
|
|
cmd.Flags().BoolVar(
|
|
&panicOnConflict,
|
|
"panic-existing",
|
|
false,
|
|
"panic on conflict existing resources. Default skips",
|
|
)
|
|
|
|
return cmd
|
|
}
|