fix json output

This commit is contained in:
d1slike committed 2020-06-03 13:27:40 +03:00
1 parent b65cda4099
commit 3eeb933231
28 files changed
+180 -595

No files matched your search

+1 -1
View File
@@ -1 +1 @@
2.1.2
2.2.0
+4
View File
@@ -1,3 +1,7 @@
## v2.2.0
* fix json output
* migrate to go mod
* update libs
## v2.1.2
* fix output '\u0026' instead '&'
## v2.1.0
Generated
-353
View File
@@ -1,353 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
digest = "1:320e7ead93de9fd2b0e59b50fd92a4d50c1f8ab455d96bc2eb083267453a9709"
name = "github.com/asaskevich/govalidator"
packages = ["."]
pruneopts = "UT"
revision = "ccb8e960c48f04d6935e72476ae4a51028f9e22f"
version = "v9"
[[projects]]
digest = "1:1d3ef3dd057d2eb1819e945f88cc83835296c9b7fb13ad3194c937c4e2891fee"
name = "github.com/codegangsta/cli"
packages = ["."]
pruneopts = "UT"
revision = "bfe2e925cfb6d44b40ad3a779165ea7e8aff9212"
version = "v1.22.0"
[[projects]]
digest = "1:7cb4fdca4c251b3ef8027c90ea35f70c7b661a593b9eeae34753c65499098bb1"
name = "github.com/cpuguy83/go-md2man"
packages = ["md2man"]
pruneopts = "UT"
revision = "7762f7e404f8416dfa1d9bb6a8c192aa9acb4d19"
version = "v1.0.10"
[[projects]]
digest = "1:07f4fafe81587b642166199f41c3edcca12929fcfcc0261b00be5dea2f968f44"
name = "github.com/golang/protobuf"
packages = [
"proto",
"ptypes",
"ptypes/any",
"ptypes/duration",
"ptypes/struct",
"ptypes/timestamp",
]
pruneopts = "UT"
revision = "6c65a5562fc06764971b7c5d05c76c75e84bdbf7"
version = "v1.3.2"
[[projects]]
branch = "master"
digest = "1:2cf4ff28b309c93a52b3329c7a22d5375b137249d4ed63c9d40707a1b253f7df"
name = "github.com/integration-system/bellows"
packages = ["."]
pruneopts = "UT"
revision = "244325e8836c364c86f308e3aef7e979cb007114"
[[projects]]
branch = "master"
digest = "1:c4f3970d1f30f5e9bc1751b62b7ea6127256e59fd63a3d36e166fe1121250c57"
name = "github.com/integration-system/go-cmp"
packages = [
"cmp",
"cmp/internal/diff",
"cmp/internal/function",
"cmp/internal/value",
]
pruneopts = "UT"
revision = "ac5582987a2f25e8743e0ebb7259312adda05c23"
[[projects]]
branch = "master"
digest = "1:9381e2bf1cde0f062353d86dc2503d62729376180938ca3b34b8d02826884db9"
name = "github.com/integration-system/isp-lib"
packages = [
"backend",
"config/schema",
"proto/stubs",
"streaming",
"structure",
"utils",
]
pruneopts = "UT"
revision = "abfa9a9776d64e6d04d495bfe00db8ca4dcbe7fc"
[[projects]]
branch = "master"
digest = "1:1789fb6e57949a6e4cacb74023cd30efb04b09dc6111d6ef3718241ebb23ebe9"
name = "github.com/integration-system/isp-log"
packages = [
".",
"stdcodes",
]
pruneopts = "UT"
revision = "a22bf2e0b56a9ef47db4a98756e39f700a99b688"
[[projects]]
branch = "master"
digest = "1:48f3a739fabefebf152d0196277ee89136c1fa6d88fc67fa486fc765a05b1caa"
name = "github.com/integration-system/jsonschema"
packages = ["."]
pruneopts = "UT"
revision = "5475a8b08e62e41fa886641861ac225e7f91e4e5"
[[projects]]
digest = "1:d78015a9da26d37166a2119592019e8bfe9b24bec60aff4a46db6110070fb1b2"
name = "github.com/json-iterator/go"
packages = [
".",
"extra",
]
pruneopts = "UT"
revision = "03217c3e97663914aec3faafde50d081f197a0a2"
version = "1.1.8"
[[projects]]
digest = "1:31e761d97c76151dde79e9d28964a812c46efc5baee4085b86f68f0c654450de"
name = "github.com/konsorten/go-windows-terminal-sequences"
packages = ["."]
pruneopts = "UT"
revision = "f55edac94c9bbba5d6182a4be46d86a2c9b5b50e"
version = "v1.0.2"
[[projects]]
digest = "1:cd0ca4e3bd8a8b2d11f65fdeca5a4a2f74111d8f80db9664d549c48ada7c5662"
name = "github.com/mattn/go-runewidth"
packages = ["."]
pruneopts = "UT"
revision = "9d4e0701ab53d89eeb2f46b282d1cd71f458f0bf"
version = "v0.0.5"
[[projects]]
digest = "1:33422d238f147d247752996a26574ac48dcf472976eda7f5134015f06bf16563"
name = "github.com/modern-go/concurrent"
packages = ["."]
pruneopts = "UT"
revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94"
version = "1.0.3"
[[projects]]
digest = "1:e32bdbdb7c377a07a9a46378290059822efdce5c8d96fe71940d87cb4f918855"
name = "github.com/modern-go/reflect2"
packages = ["."]
pruneopts = "UT"
revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd"
version = "1.0.1"
[[projects]]
branch = "master"
digest = "1:84bd7f8a2e0bcd53ddc33c3b47c34c1fe340c8632cbe928f7f8ae10ec6ecdd62"
name = "github.com/mohae/deepcopy"
packages = ["."]
pruneopts = "UT"
revision = "c48cc78d482608239f6c4c92a4abd87eb8761c90"
[[projects]]
digest = "1:abcdbf03ca6ca13d3697e2186edc1f33863bbdac2b3a44dfa39015e8903f7409"
name = "github.com/olekukonko/tablewriter"
packages = ["."]
pruneopts = "UT"
revision = "e6d60cf7ba1f42d86d54cdf5508611c4aafb3970"
version = "v0.0.1"
[[projects]]
digest = "1:cf31692c14422fa27c83a05292eb5cbe0fb2775972e8f1f8446a71549bd8980b"
name = "github.com/pkg/errors"
packages = ["."]
pruneopts = "UT"
revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4"
version = "v0.8.1"
[[projects]]
digest = "1:b36a0ede02c4c2aef7df7f91cbbb7bb88a98b5d253509d4f997dda526e50c88c"
name = "github.com/russross/blackfriday"
packages = ["."]
pruneopts = "UT"
revision = "05f3235734ad95d0016f6a23902f06461fcf567a"
version = "v1.5.2"
[[projects]]
digest = "1:04457f9f6f3ffc5fea48e71d62f2ca256637dee0a04d710288e27e05c8b41976"
name = "github.com/sirupsen/logrus"
packages = ["."]
pruneopts = "UT"
revision = "839c75faf7f98a33d445d181f3018b5c3409a45e"
version = "v1.4.2"
[[projects]]
digest = "1:46aea6ffe39c3d95c13640c2515236ed3c5cdffc3c78c6c0ed4edec2caf7a0dc"
name = "github.com/tidwall/gjson"
packages = ["."]
pruneopts = "UT"
revision = "c5e72cdf74dff23857243dd662c465b810891c21"
version = "v1.3.2"
[[projects]]
digest = "1:8453ddbed197809ee8ca28b06bd04e127bec9912deb4ba451fea7a1eca578328"
name = "github.com/tidwall/match"
packages = ["."]
pruneopts = "UT"
revision = "33827db735fff6510490d69a8622612558a557ed"
version = "v1.0.1"
[[projects]]
digest = "1:ddfe0a54e5f9b29536a6d7b2defa376f2cb2b6e4234d676d7ff214d5b097cb50"
name = "github.com/tidwall/pretty"
packages = ["."]
pruneopts = "UT"
revision = "1166b9ac2b65e46a43d8618d30d1554f4652d49b"
version = "v1.0.0"
[[projects]]
digest = "1:b70c951ba6fdeecfbd50dabe95aa5e1b973866ae9abbece46ad60348112214f2"
name = "github.com/tidwall/sjson"
packages = ["."]
pruneopts = "UT"
revision = "25fb082a20e29e83fb7b7ef5f5919166aad1f084"
version = "v1.0.4"
[[projects]]
digest = "1:1d3ef3dd057d2eb1819e945f88cc83835296c9b7fb13ad3194c937c4e2891fee"
name = "github.com/urfave/cli"
packages = ["."]
pruneopts = "UT"
revision = "bfe2e925cfb6d44b40ad3a779165ea7e8aff9212"
version = "v1.22.0"
[[projects]]
branch = "master"
digest = "1:c124e945335a9c62ede3a565f3198c5ae9a5ecc39fddd85871138362d128fb74"
name = "golang.org/x/net"
packages = [
"context",
"http/httpguts",
"http2",
"http2/hpack",
"idna",
"internal/timeseries",
"trace",
]
pruneopts = "UT"
revision = "fe3aa8a4527195a6057b3fad46619d7d090e99b5"
[[projects]]
branch = "master"
digest = "1:89c4223950671f7afdc98761c6a601b83594865490c71b434194b6cacf208e6a"
name = "golang.org/x/sys"
packages = ["unix"]
pruneopts = "UT"
revision = "f8518d3b3627146e88bd43ca73045e1b8d8eb6c6"
[[projects]]
digest = "1:8d8faad6b12a3a4c819a3f9618cb6ee1fa1cfc33253abeeea8b55336721e3405"
name = "golang.org/x/text"
packages = [
"collate",
"collate/build",
"internal/colltab",
"internal/gen",
"internal/language",
"internal/language/compact",
"internal/tag",
"internal/triegen",
"internal/ucd",
"language",
"secure/bidirule",
"transform",
"unicode/bidi",
"unicode/cldr",
"unicode/norm",
"unicode/rangetable",
]
pruneopts = "UT"
revision = "342b2e1fbaa52c93f31447ad2c6abc048c63e475"
version = "v0.3.2"
[[projects]]
branch = "master"
digest = "1:a910255c3b706b4d8f2b185ed6b40c8f31b805111be240def2bdf2c62b87591b"
name = "google.golang.org/genproto"
packages = [
"googleapis/rpc/errdetails",
"googleapis/rpc/status",
]
pruneopts = "UT"
revision = "548a555dbc03994223efbaba0090152849259498"
[[projects]]
digest = "1:6cd77d0b616d2dcebd363dfecba593f27b0151fc82cdb5fbfb96c5a7cfbc95b5"
name = "google.golang.org/grpc"
packages = [
".",
"balancer",
"balancer/base",
"balancer/roundrobin",
"binarylog/grpc_binarylog_v1",
"codes",
"connectivity",
"credentials",
"credentials/internal",
"encoding",
"encoding/proto",
"grpclog",
"internal",
"internal/backoff",
"internal/balancerload",
"internal/binarylog",
"internal/channelz",
"internal/envconfig",
"internal/grpcrand",
"internal/grpcsync",
"internal/syscall",
"internal/transport",
"keepalive",
"metadata",
"naming",
"peer",
"resolver",
"resolver/dns",
"resolver/passthrough",
"serviceconfig",
"stats",
"status",
"tap",
]
pruneopts = "UT"
revision = "f6d0f9ee430895e87ef1ceb5ac8f39725bafceef"
version = "v1.24.0"
[[projects]]
digest = "1:59f10c1537d2199d9115d946927fe31165959a95190849c82ff11e05803528b0"
name = "gopkg.in/yaml.v2"
packages = ["."]
pruneopts = "UT"
revision = "f221b8435cfb71e54062f6c6e99e9ade30b124d5"
version = "v2.2.4"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
input-imports = [
"github.com/codegangsta/cli",
"github.com/integration-system/bellows",
"github.com/integration-system/isp-lib/backend",
"github.com/integration-system/isp-lib/config/schema",
"github.com/integration-system/isp-lib/structure",
"github.com/olekukonko/tablewriter",
"github.com/pkg/errors",
"github.com/tidwall/gjson",
"github.com/tidwall/pretty",
"github.com/tidwall/sjson",
"google.golang.org/genproto/googleapis/rpc/errdetails",
"google.golang.org/grpc",
"google.golang.org/grpc/codes",
"google.golang.org/grpc/metadata",
"google.golang.org/grpc/status",
"gopkg.in/yaml.v2",
]
solver-name = "gps-cdcl"
solver-version = 1
-42
View File
@@ -1,42 +0,0 @@
# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true
[prune]
go-tests = true
unused-packages = true
[[override]]
name = "github.com/valyala/fasthttp"
branch = "master"
[[override]]
name = "github.com/integration-system/isp-lib"
branch = "master"
[[override]]
name = "github.com/russross/blackfriday"
version = "v1.5.2"
+1 -1
View File
@@ -2,8 +2,8 @@ package bash
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/integration-system/bellows"
"github.com/urfave/cli/v2"
"isp-ctl/flag"
"isp-ctl/service"
)
+2 -2
View File
@@ -1,8 +1,8 @@
package cfg
import (
"github.com/integration-system/isp-lib/config/schema"
"github.com/integration-system/isp-lib/structure"
"github.com/integration-system/isp-lib/v2/config/schema"
"github.com/integration-system/isp-lib/v2/structure"
"time"
)
+7 -5
View File
@@ -1,12 +1,14 @@
package cfg
import (
"github.com/integration-system/isp-lib/backend"
"github.com/integration-system/isp-lib/v2/backend"
"github.com/integration-system/isp-lib/v2/structure"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"net"
)
const (
@@ -16,13 +18,13 @@ const (
func NewConfigClient() *configClient {
return &configClient{
cli: &backend.InternalGrpcClient{},
cli: backend.NewRxGrpcClient(backend.WithDialOptions(grpc.WithInsecure())),
headers: make(map[string][]string),
}
}
type configClient struct {
cli *backend.InternalGrpcClient
cli *backend.RxGrpcClient
headers metadata.MD
address string
@@ -30,11 +32,11 @@ type configClient struct {
}
func (c *configClient) ReceiveConfig(address, instanceUuid string) error {
var err error
c.cli, err = backend.NewGrpcClient(address, grpc.WithInsecure())
host, port, err := net.SplitHostPort(address)
if err != nil {
return err
}
c.cli.ReceiveAddressList([]structure.AddressConfiguration{{IP: host, Port: port}})
c.address = address
c.instanceUuid = instanceUuid
+6 -5
View File
@@ -2,17 +2,17 @@ package command
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/urfave/cli/v2"
"isp-ctl/command/common_config"
)
func CommonConfig() cli.Command {
return cli.Command{
func CommonConfig() *cli.Command {
return &cli.Command{
Name: "common",
Usage: "access to common configs commands",
Action: cc.action,
BashComplete: cc.bachComplete,
Subcommands: []cli.Command{
Subcommands: []*cli.Command{
common_config.Get(),
common_config.Set(),
common_config.Delete(),
@@ -28,7 +28,7 @@ var cc commonConfigCommand
type commonConfigCommand struct{}
func (g commonConfigCommand) action(ctx *cli.Context) {
func (g commonConfigCommand) action(ctx *cli.Context) error {
if ctx.Args().First() == "" {
fmt.Print("need use command: ")
for _, comm := range CommonConfig().Subcommands {
@@ -36,6 +36,7 @@ func (g commonConfigCommand) action(ctx *cli.Context) {
}
fmt.Printf("\n")
}
return nil
}
func (g commonConfigCommand) bachComplete(ctx *cli.Context) {
+9 -12
View File
@@ -2,16 +2,15 @@ package common_config
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func Contain() cli.Command {
return cli.Command{
func Contain() *cli.Command {
return &cli.Command{
Name: "contain",
Usage: "availability common configuration in module",
Action: contain.action,
@@ -23,28 +22,25 @@ var contain containCommand
type containCommand struct{}
func (g containCommand) action(ctx *cli.Context) {
func (g containCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
configName := ctx.Args().First()
if configName == "" {
utils.PrintError(errors.New("empty common config name"))
return
return errors.New("empty common config name")
}
config, err := service.Config.GetCommonConfigByName(configName)
if err != nil {
utils.PrintError(err)
return
return err
}
links, err := service.Config.GetLinksCommonConfig(config.Id)
if err != nil {
utils.PrintError(err)
return err
} else {
fmt.Printf("config [%s] linked with next modules:\n", configName)
for _, link := range links {
@@ -52,4 +48,5 @@ func (g containCommand) action(ctx *cli.Context) {
}
fmt.Printf("\n")
}
return nil
}
+12 -17
View File
@@ -2,17 +2,17 @@ package common_config
import (
"encoding/json"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func Delete() cli.Command {
return cli.Command{
func Delete() *cli.Command {
return &cli.Command{
Name: "delete",
Usage: "set common configurations",
Action: deleteComm.action,
@@ -24,44 +24,39 @@ var deleteComm deleteCommand
type deleteCommand struct{}
func (g deleteCommand) action(ctx *cli.Context) {
func (g deleteCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
configName := ctx.Args().First()
pathObject := ctx.Args().Get(1)
if configName == "" {
utils.PrintError(errors.New("empty config name"))
return
return errors.New("empty config name")
}
pathObject, err := utils.CheckPath(pathObject)
if err != nil {
utils.PrintError(err)
return
return err
}
config, err := service.Config.GetCommonConfigByName(configName)
if err != nil {
utils.PrintError(err)
return
return err
}
if pathObject == "" {
utils.CreateUpdateCommonConfig("", config)
return utils.CreateUpdateCommonConfig("", config)
} else {
jsonObject, err := json.Marshal(config.Data)
if err != nil {
utils.PrintError(err)
return
return err
}
if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil {
utils.PrintError(err)
return err
} else {
utils.CreateUpdateCommonConfig(stringToChange, config)
return utils.CreateUpdateCommonConfig(stringToChange, config)
}
}
}
+11 -14
View File
@@ -3,16 +3,16 @@ package common_config
import (
"encoding/json"
"fmt"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func Get() cli.Command {
return cli.Command{
func Get() *cli.Command {
return &cli.Command{
Name: "get",
Usage: "get common configurations",
Action: get.action,
@@ -24,10 +24,9 @@ var get getCommand
type getCommand struct{}
func (g getCommand) action(ctx *cli.Context) {
func (g getCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
configName := ctx.Args().First()
@@ -35,8 +34,7 @@ func (g getCommand) action(ctx *cli.Context) {
commonConfigs, err := service.Config.GetMapNameCommonConfig()
if err != nil {
utils.PrintError(err)
return
return err
}
if configName == "" {
@@ -45,26 +43,25 @@ func (g getCommand) action(ctx *cli.Context) {
fmt.Printf("[%s] ", name)
}
fmt.Println()
return
return nil
}
pathObject, err = utils.CheckPath(pathObject)
if err != nil {
utils.PrintError(err)
return
return err
}
config, ok := commonConfigs[configName]
if !ok {
utils.PrintError(errors.Errorf("common config [%s] not found", configName))
return
return errors.Errorf("common config [%s] not found", configName)
}
if pathObject == "" {
utils.PrintAnswer(config.Data)
} else if jsonObject, err := json.Marshal(config.Data); err != nil {
utils.PrintError(err)
return err
} else {
utils.CheckObject(jsonObject, pathObject)
}
return nil
}
+7 -8
View File
@@ -1,15 +1,14 @@
package common_config
import (
"github.com/codegangsta/cli"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func Link() cli.Command {
return cli.Command{
func Link() *cli.Command {
return &cli.Command{
Name: "link",
Usage: "link common configurations to module configuration",
Action: link.action,
@@ -21,16 +20,16 @@ var link linkCommand
type linkCommand struct{}
func (g linkCommand) action(ctx *cli.Context) {
func (g linkCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
configName := ctx.Args().First()
moduleName := ctx.Args().Get(1)
if err := service.Config.LinkCommonConfigToModule(configName, moduleName); err != nil {
utils.PrintError(err)
return err
}
return nil
}
+9 -13
View File
@@ -2,16 +2,15 @@ package common_config
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func Remove() cli.Command {
return cli.Command{
func Remove() *cli.Command {
return &cli.Command{
Name: "remove",
Usage: "remove common configurations",
Action: remove.action,
@@ -23,29 +22,25 @@ var remove removeCommand
type removeCommand struct{}
func (g removeCommand) action(ctx *cli.Context) {
func (g removeCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
configName := ctx.Args().First()
if configName == "" {
utils.PrintError(errors.New("empty common config name"))
return
return errors.New("empty common config name")
}
config, err := service.Config.GetCommonConfigByName(configName)
if err != nil {
utils.PrintError(err)
return
return err
}
links, deleted, err := service.Config.DeleteCommonConfig(config.Id)
if err != nil {
utils.PrintError(err)
return
return err
}
if deleted {
@@ -53,4 +48,5 @@ func (g removeCommand) action(ctx *cli.Context) {
} else {
fmt.Printf("config [%s] not deleted, need unlink in next modules:\n%v\n", config.Name, links)
}
return nil
}
+13 -19
View File
@@ -2,9 +2,9 @@ package common_config
import (
"encoding/json"
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/cfg"
"isp-ctl/command/utils"
@@ -12,8 +12,8 @@ import (
"isp-ctl/service"
)
func Set() cli.Command {
return cli.Command{
func Set() *cli.Command {
return &cli.Command{
Name: "set",
Usage: "set common configurations",
Action: set.action,
@@ -25,10 +25,9 @@ var set setCommand
type setCommand struct{}
func (g setCommand) action(ctx *cli.Context) {
func (g setCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
configName := ctx.Args().First()
@@ -36,14 +35,12 @@ func (g setCommand) action(ctx *cli.Context) {
changeObject := ctx.Args().Get(2)
if configName == "" {
utils.PrintError(errors.New("empty config name"))
return
return errors.New("empty config name")
}
mapConfigByName, err := service.Config.GetMapNameCommonConfig()
if err != nil {
utils.PrintError(err)
return
return err
}
config, ok := mapConfigByName[configName]
@@ -55,29 +52,26 @@ func (g setCommand) action(ctx *cli.Context) {
pathObject, err = utils.CheckPath(pathObject)
if err != nil {
utils.PrintError(err)
return
return err
}
changeObject, err = utils.CheckChangeObject(changeObject)
if err != nil {
utils.PrintError(err)
return
return err
}
if pathObject == "" {
utils.CreateUpdateCommonConfig(changeObject, config)
return utils.CreateUpdateCommonConfig(changeObject, config)
} else {
jsonObject, err := json.Marshal(config.Data)
if err != nil {
utils.PrintError(err)
return
return err
}
changeArgument := utils.ParseSetObject(changeObject)
if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil {
utils.PrintError(err)
return err
} else {
utils.CreateUpdateCommonConfig(stringToChange, config)
return utils.CreateUpdateCommonConfig(stringToChange, config)
}
}
}
+7 -8
View File
@@ -1,15 +1,14 @@
package common_config
import (
"github.com/codegangsta/cli"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func UnLink() cli.Command {
return cli.Command{
func UnLink() *cli.Command {
return &cli.Command{
Name: "unlink",
Usage: "unlink common configurations from module configuration",
Action: unlink.action,
@@ -21,16 +20,16 @@ var unlink unlinkCommand
type unlinkCommand struct{}
func (g unlinkCommand) action(ctx *cli.Context) {
func (g unlinkCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
configName := ctx.Args().First()
moduleName := ctx.Args().Get(1)
if err := service.Config.UnlinkCommonConfigFromModule(configName, moduleName); err != nil {
utils.PrintError(err)
return err
}
return nil
}
+11 -15
View File
@@ -2,16 +2,16 @@ package command
import (
"encoding/json"
"github.com/codegangsta/cli"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func Delete() cli.Command {
return cli.Command{
func Delete() *cli.Command {
return &cli.Command{
Name: "delete",
Usage: "delete configuration by module_name",
Action: deleteComm.action,
@@ -23,39 +23,35 @@ var deleteComm deleteCommand
type deleteCommand struct{}
func (d deleteCommand) action(ctx *cli.Context) {
func (d deleteCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
moduleName := ctx.Args().First()
pathObject := ctx.Args().Get(1)
moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil {
utils.PrintError(err)
return
return err
}
pathObject, err = utils.CheckPath(pathObject)
if err != nil {
utils.PrintError(err)
return
return err
}
if pathObject == "" {
utils.CreateUpdateConfig("", moduleConfiguration)
return utils.CreateUpdateConfig("", moduleConfiguration)
} else {
jsonObject, err := json.Marshal(moduleConfiguration.Data)
if err != nil {
utils.PrintError(err)
return
return err
}
if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil {
utils.PrintError(err)
return err
} else {
utils.CreateUpdateConfig(stringToChange, moduleConfiguration)
return utils.CreateUpdateConfig(stringToChange, moduleConfiguration)
}
}
}
+10 -14
View File
@@ -2,15 +2,15 @@ package command
import (
"encoding/json"
"github.com/codegangsta/cli"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func Get() cli.Command {
return cli.Command{
func Get() *cli.Command {
return &cli.Command{
Name: "get",
Usage: "get configuration by module_name",
Action: get.action,
@@ -25,32 +25,28 @@ var get getCommand
type getCommand struct{}
func (g getCommand) action(ctx *cli.Context) {
func (g getCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
moduleName := ctx.Args().First()
pathObject := ctx.Args().Get(1)
config, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil {
utils.PrintError(err)
return
return err
}
data := config.Data
if ctx.Bool(flag.WithCommonConfig.Name) {
if data, err = service.Config.CompileDataWithCommonConfigs(data, config.CommonConfigs); err != nil {
utils.PrintError(err)
return
return err
}
}
pathObject, err = utils.CheckPath(pathObject)
if err != nil {
utils.PrintError(err)
return
return err
}
if pathObject == "" {
@@ -58,9 +54,9 @@ func (g getCommand) action(ctx *cli.Context) {
} else {
jsonObject, err := json.Marshal(data)
if err != nil {
utils.PrintError(err)
return
return err
}
utils.CheckObject(jsonObject, pathObject)
}
return nil
}
+7 -8
View File
@@ -1,8 +1,8 @@
package command
import (
"github.com/codegangsta/cli"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"html/template"
"isp-ctl/bash"
"isp-ctl/command/utils"
@@ -12,8 +12,8 @@ import (
"os"
)
func Schema() cli.Command {
return cli.Command{
func Schema() *cli.Command {
return &cli.Command{
Name: "schema",
Usage: "get schema configuration by module_name",
Action: schema.action,
@@ -28,10 +28,9 @@ var schema schemaCommand
type schemaCommand struct{}
func (s schemaCommand) action(ctx *cli.Context) {
func (s schemaCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
moduleName := ctx.Args().First()
@@ -45,10 +44,10 @@ func (s schemaCommand) action(ctx *cli.Context) {
case flag.OutPrintHtmlValue:
s.printHtml(schema)
default:
utils.PrintError(errors.Errorf(
"invalid flag value, expected [%s] or [%s]", flag.OutPrintJsonValue, flag.OutPrintHtmlValue))
return errors.Errorf("invalid flag value, expected [%s] or [%s]", flag.OutPrintJsonValue, flag.OutPrintHtmlValue)
}
}
return nil
}
func (s schemaCommand) getSchemaConfig(moduleName string) interface{} {
+12 -17
View File
@@ -2,16 +2,16 @@ package command
import (
"encoding/json"
"github.com/codegangsta/cli"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func Set() cli.Command {
return cli.Command{
func Set() *cli.Command {
return &cli.Command{
Name: "set",
Usage: "set configuration by module_name",
Action: set.action,
@@ -23,10 +23,9 @@ var set setCommand
type setCommand struct{}
func (s setCommand) action(ctx *cli.Context) {
func (s setCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
moduleName := ctx.Args().First()
@@ -35,36 +34,32 @@ func (s setCommand) action(ctx *cli.Context) {
config, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil {
utils.PrintError(err)
return
return err
}
pathObject, err = utils.CheckPath(pathObject)
if err != nil {
utils.PrintError(err)
return
return err
}
changeObject, err = utils.CheckChangeObject(changeObject)
if err != nil {
utils.PrintError(err)
return
return err
}
if pathObject == "" {
utils.CreateUpdateConfig(changeObject, config)
return utils.CreateUpdateConfig(changeObject, config)
} else {
jsonObject, err := json.Marshal(config.Data)
if err != nil {
utils.PrintError(err)
return
return err
}
changeArgument := utils.ParseSetObject(changeObject)
if stringToChange, err := sjson.Set(string(jsonObject), pathObject, changeArgument); err != nil {
utils.PrintError(err)
return err
} else {
utils.CreateUpdateConfig(stringToChange, config)
return utils.CreateUpdateConfig(stringToChange, config)
}
}
}
+7 -7
View File
@@ -2,8 +2,8 @@ package command
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
@@ -20,8 +20,8 @@ const (
tableConnectedStatus = "CONNECTED"
)
func Status() cli.Command {
return cli.Command{
func Status() *cli.Command {
return &cli.Command{
Name: "status",
Usage: "get available configs",
Action: status.action,
@@ -35,13 +35,12 @@ var status statusCommand
type statusCommand struct{}
func (statusCommand) action(ctx *cli.Context) {
func (statusCommand) action(ctx *cli.Context) error {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
return err
}
if arrayOfModules, err := service.Config.GetAvailableConfigs(); err != nil {
utils.PrintError(err)
return err
} else {
switch ctx.String(flag.OutPrintStatus.Name) {
case flag.OutPrintJsonValue:
@@ -66,4 +65,5 @@ func (statusCommand) action(ctx *cli.Context) {
table.Render()
}
}
return nil
}
+1 -1
View File
@@ -47,7 +47,7 @@ func CheckChangeObject(changeObject string) (string, error) {
}
func PrintAnswer(data interface{}) {
buffer := bytes.NewBuffer(make([]byte, 1024))
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
encoder := json.NewEncoder(buffer)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")
+3 -2
View File
@@ -5,10 +5,11 @@ import (
"isp-ctl/service"
)
func CreateUpdateCommonConfig(stringToChange string, configuration cfg.CommonConfig) {
func CreateUpdateCommonConfig(stringToChange string, configuration cfg.CommonConfig) error {
if answer, err := service.Config.CreateUpdateCommonConfig(stringToChange, configuration); err != nil {
PrintError(err)
return err
} else if answer != nil {
PrintAnswer(answer)
}
return nil
}
+3 -2
View File
@@ -5,10 +5,11 @@ import (
"isp-ctl/service"
)
func CreateUpdateConfig(stringToChange string, configuration *cfg.Config) {
func CreateUpdateConfig(stringToChange string, configuration *cfg.Config) error {
if answer, err := service.Config.CreateUpdateConfig(stringToChange, configuration); err != nil {
PrintError(err)
return err
} else if answer != nil {
PrintAnswer(answer)
}
return nil
}
+3 -3
View File
@@ -3,13 +3,13 @@ package flag
import "fmt"
const (
hostName = "gateHost, g"
hostName = "gateHost"
hostUsage = "overrides gateHost"
uuidName = "instanceUuid, u"
uuidName = "instanceUuid"
uuidUsage = "overrides instanceUuid"
colorName = "color, c"
colorName = "color"
colorUsage = "colorize the json for outputing to screen"
unsafeName = "unsafe"
+14 -23
View File
@@ -1,21 +1,21 @@
package flag
import (
"github.com/codegangsta/cli"
"github.com/urfave/cli/v2"
"isp-ctl/service"
"strings"
)
var (
//---global---
Host = cli.StringFlag{Name: hostName, Usage: hostUsage}
Uuid = cli.StringFlag{Name: uuidName, Usage: uuidUsage}
Color = cli.BoolFlag{Name: colorName, Usage: colorUsage}
Unsafe = cli.BoolFlag{Name: unsafeName, Usage: unsafeUsage}
Host = &cli.StringFlag{Name: hostName, Usage: hostUsage, Aliases: []string{"g"}}
Uuid = &cli.StringFlag{Name: uuidName, Usage: uuidUsage, Aliases: []string{"u"}}
Color = &cli.BoolFlag{Name: colorName, Usage: colorUsage, Aliases: []string{"c"}}
Unsafe = &cli.BoolFlag{Name: unsafeName, Usage: unsafeUsage}
//---local---
OutPrintStatus = cli.StringFlag{Name: outPrintName, Usage: outPrintStatusUsage}
OutPrintSchema = cli.StringFlag{Name: outPrintName, Usage: outPrintSchemaUsage, Value: OutPrintJsonValue}
WithCommonConfig = cli.BoolFlag{Name: withCommonConfigName, Usage: withCommonConfigUsage}
OutPrintStatus = &cli.StringFlag{Name: outPrintName, Usage: outPrintStatusUsage}
OutPrintSchema = &cli.StringFlag{Name: outPrintName, Usage: outPrintSchemaUsage, Value: OutPrintJsonValue}
WithCommonConfig = &cli.BoolFlag{Name: withCommonConfigName, Usage: withCommonConfigUsage}
)
func CheckGlobal(c *cli.Context) error {
@@ -23,27 +23,18 @@ func CheckGlobal(c *cli.Context) error {
uuid, host string
color bool
)
colorFlag := strings.Split(Color.Name, ", ")
if c.GlobalBool(colorFlag[0]) != false {
if c.Bool(Color.Name) != false {
color = true
} else {
color = c.GlobalBool(colorFlag[1])
}
service.ColorService.Enable = color
service.Config.UnsafeEnable = c.GlobalBool(Unsafe.Name)
service.Config.UnsafeEnable = c.Bool(Unsafe.Name)
hostFlag := strings.Split(Host.Name, ", ")
if c.GlobalString(hostFlag[0]) != "" {
host = c.GlobalString(hostFlag[0])
} else {
host = c.GlobalString(hostFlag[1])
if c.String(Host.Name) != "" {
host = c.String(Host.Name)
}
uuidFlag := strings.Split(Uuid.Name, ", ")
if c.GlobalString(uuidFlag[0]) != "" {
uuid = c.GlobalString(uuidFlag[0])
} else {
uuid = c.GlobalString(uuidFlag[1])
if c.String(Uuid.Name) != "" {
uuid = c.String(Uuid.Name)
}
uuid = strings.Replace(uuid, "'", "", -1)
+17
View File
@@ -0,0 +1,17 @@
module isp-ctl
go 1.14
require (
github.com/integration-system/bellows v1.0.1
github.com/integration-system/isp-lib/v2 v2.4.0
github.com/olekukonko/tablewriter v0.0.4
github.com/pkg/errors v0.9.1
github.com/tidwall/gjson v1.6.0
github.com/tidwall/pretty v1.0.1
github.com/tidwall/sjson v1.1.1
github.com/urfave/cli/v2 v2.2.0
google.golang.org/genproto v0.0.0-20200211111953-2dc5924e3898
google.golang.org/grpc v1.29.1
gopkg.in/yaml.v2 v2.2.4
)
+2 -2
View File
@@ -2,7 +2,7 @@ package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/urfave/cli/v2"
"isp-ctl/command"
"isp-ctl/flag"
"isp-ctl/service"
@@ -36,7 +36,7 @@ func initCommands() {
flag.Unsafe,
}
app.EnableBashCompletion = true
app.Commands = []cli.Command{
app.Commands = []*cli.Command{
command.Status(),
command.Get(),
command.Set(),
+1 -1
View File
@@ -3,7 +3,7 @@ package service
import (
"encoding/json"
"fmt"
"github.com/integration-system/isp-lib/config/schema"
"github.com/integration-system/isp-lib/v2/config/schema"
"github.com/pkg/errors"
epb "google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/codes"