add(checking schema to set configuration and unsafe flag)
This commit is contained in:
1 parent
3543ded23e
commit
c8d028fcd4
14 files changed
+147
-36
No files matched your search
@@ -1,2 +1,7 @@
|
|||||||
|
## v1.1.0
|
||||||
|
* fix status response
|
||||||
|
* add checking schema to set configuration
|
||||||
|
* add unsafe flag
|
||||||
|
* update readme
|
||||||
## v1.0.1
|
## v1.0.1
|
||||||
* fix spaces in strings
|
* fix spaces in strings
|
||||||
Generated
+36
-11
@@ -41,7 +41,7 @@
|
|||||||
revision = "368713356c71961354e09ab9b734740ebdd94784"
|
revision = "368713356c71961354e09ab9b734740ebdd94784"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:78af343f98aa28c74adb925595e0fb32eecc1d9a6da5b639751a5afb4a99292b"
|
digest = "1:cd9785ed4d12c737f23ec65b08fffa4e235cbf8689290211dd95eeb0f1ae7e15"
|
||||||
name = "github.com/integration-system/isp-lib"
|
name = "github.com/integration-system/isp-lib"
|
||||||
packages = [
|
packages = [
|
||||||
"config/schema",
|
"config/schema",
|
||||||
@@ -51,8 +51,8 @@
|
|||||||
"utils",
|
"utils",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "9d583f86516f92e855d15de30ff0dd40bb2a2ab2"
|
revision = "d2cc77b8fb8648ae7f8efdf1d1b834e8e57b56d7"
|
||||||
version = "v1.5.1"
|
version = "v1.5.2"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@@ -63,15 +63,15 @@
|
|||||||
revision = "5475a8b08e62e41fa886641861ac225e7f91e4e5"
|
revision = "5475a8b08e62e41fa886641861ac225e7f91e4e5"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:e4f630893d2bbf8c268eba14e7cc92ef8844ee259a45e21ea77cf7656544cb7e"
|
digest = "1:ac7f1061abc812a5d0de6df7e3f477cef942aef503848f436da0f0eb2603bfbf"
|
||||||
name = "github.com/json-iterator/go"
|
name = "github.com/json-iterator/go"
|
||||||
packages = [
|
packages = [
|
||||||
".",
|
".",
|
||||||
"extra",
|
"extra",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "0ff49de124c6f76f8494e194af75bde0f1a49a29"
|
revision = "27518f6661eba504be5a7a9a9f6d9460d892ade3"
|
||||||
version = "v1.1.6"
|
version = "v1.1.7"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:823dc0f8e4cdad8d91e6aba4cdd985a035596a8aa02e9d2abf1bec347894c41f"
|
digest = "1:823dc0f8e4cdad8d91e6aba4cdd985a035596a8aa02e9d2abf1bec347894c41f"
|
||||||
@@ -225,6 +225,30 @@
|
|||||||
revision = "bb2702d423886830dee131692131d35648c382e2"
|
revision = "bb2702d423886830dee131692131d35648c382e2"
|
||||||
version = "v0.5.2"
|
version = "v0.5.2"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
digest = "1:f4e5276a3b356f4692107047fd2890f2fe534f4feeb6b1fd2f6dfbd87f1ccf54"
|
||||||
|
name = "github.com/xeipuuv/gojsonpointer"
|
||||||
|
packages = ["."]
|
||||||
|
pruneopts = "UT"
|
||||||
|
revision = "4e3ac2762d5f479393488629ee9370b50873b3a6"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
digest = "1:dc6a6c28ca45d38cfce9f7cb61681ee38c5b99ec1425339bfc1e1a7ba769c807"
|
||||||
|
name = "github.com/xeipuuv/gojsonreference"
|
||||||
|
packages = ["."]
|
||||||
|
pruneopts = "UT"
|
||||||
|
revision = "bd5ef7bd5415a7ac448318e64f11a24cd21e594b"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
digest = "1:1c898ea6c30c16e8d55fdb6fe44c4bee5f9b7d68aa260cfdfc3024491dcc7bea"
|
||||||
|
name = "github.com/xeipuuv/gojsonschema"
|
||||||
|
packages = ["."]
|
||||||
|
pruneopts = "UT"
|
||||||
|
revision = "f971f3cd73b2899de6923801c147f075263e0c50"
|
||||||
|
version = "v1.1.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:bbe51412d9915d64ffaa96b51d409e070665efc5194fcf145c4a27d4133107a4"
|
digest = "1:bbe51412d9915d64ffaa96b51d409e070665efc5194fcf145c4a27d4133107a4"
|
||||||
@@ -239,18 +263,18 @@
|
|||||||
name = "golang.org/x/net"
|
name = "golang.org/x/net"
|
||||||
packages = ["context"]
|
packages = ["context"]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "da137c7871d730100384dbcf36e6f8fa493aef5b"
|
revision = "ca1201d0de80cfde86cb01aea620983605dfe99b"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:31d44814b45607afa77c6e8ef20ea8bacc1d1053fe084440c874f311732e7ec3"
|
digest = "1:f99b0e9035cf86cdc14cb2848308e831193d5e19ab9a23a8493cd925bdc3952b"
|
||||||
name = "golang.org/x/sys"
|
name = "golang.org/x/sys"
|
||||||
packages = [
|
packages = [
|
||||||
"unix",
|
"unix",
|
||||||
"windows",
|
"windows",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "fae7ac547cb717d141c433a2a173315e216b64c4"
|
revision = "fc99dfbffb4e5ed5758a37e31dd861afe285406b"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@@ -276,8 +300,8 @@
|
|||||||
"status",
|
"status",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "1d89a3c832915b2314551c1d2a506874d62e53f7"
|
revision = "045159ad57f3781d409358e3ade910a018c16b30"
|
||||||
version = "v1.22.0"
|
version = "v1.22.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96"
|
digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96"
|
||||||
@@ -300,6 +324,7 @@
|
|||||||
"github.com/tidwall/pretty",
|
"github.com/tidwall/pretty",
|
||||||
"github.com/tidwall/sjson",
|
"github.com/tidwall/sjson",
|
||||||
"github.com/valyala/fasthttp",
|
"github.com/valyala/fasthttp",
|
||||||
|
"github.com/xeipuuv/gojsonschema",
|
||||||
"gopkg.in/yaml.v2",
|
"gopkg.in/yaml.v2",
|
||||||
]
|
]
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ instanceUuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|||||||
|
|
||||||
## Использование
|
## Использование
|
||||||
```bash
|
```bash
|
||||||
ispctl status [flag...]
|
ispctl [flag...] status
|
||||||
ispctl get [flag...] module_name property_path
|
ispctl [flag...] get module_name property_path
|
||||||
ispctl set [flag...] module_name property_path [new_object]
|
ispctl [flag...] set module_name property_path [new_object]
|
||||||
ispctl delete [flag...] module_name property_path
|
ispctl [flag...] delete module_name property_path
|
||||||
```
|
```
|
||||||
## Описание
|
## Описание
|
||||||
|
|
||||||
@@ -40,10 +40,11 @@ ispctl delete [flag...] module_name property_path
|
|||||||
| | |
|
| | |
|
||||||
|
|
||||||
| Флаги | Параметры | Описание |
|
| Флаги | Параметры | Описание |
|
||||||
|--------|-----------|-----------------------------------------------------|
|
|--------|-----------|------------------------------------------------------------------|
|
||||||
| `-g` | string | переопределяет gateHost из конфигурации утилиты |
|
| `-g` | string | переопределяет gateHost из конфигурации утилиты |
|
||||||
| `-u` | string | переопределяет instanceUuid из конфигурации утилиты |
|
| `-u` | string | переопределяет instanceUuid из конфигурации утилиты |
|
||||||
| `-c` | | раскрашивает json перед выводом на экран |
|
| `-c` | | раскрашивает json перед выводом на экран |
|
||||||
|
| `-s` | | отключает проверку схемы перед изменением конфигурации |
|
||||||
| | | |
|
| | | |
|
||||||
|
|
||||||
| Аргументы | Описание |
|
| Аргументы | Описание |
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ type getModuleByUuidAndNameRequest struct {
|
|||||||
Uuid string
|
Uuid string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type getSchemaByModuleIdRequest struct {
|
||||||
|
ModuleId int32
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Id int64
|
Id int64
|
||||||
Name string
|
Name string
|
||||||
@@ -42,3 +46,12 @@ type ModuleInfo struct {
|
|||||||
ConfigSchema *schema.Schema `json:",omitempty"`
|
ConfigSchema *schema.Schema `json:",omitempty"`
|
||||||
Status []Connection `json:",omitempty"`
|
Status []Connection `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ConfigSchema struct {
|
||||||
|
Id int32
|
||||||
|
Version string
|
||||||
|
ModuleId int32
|
||||||
|
Schema schema.Schema
|
||||||
|
CreatedAt time.Time
|
||||||
|
UpdatedAt time.Time
|
||||||
|
}
|
||||||
@@ -4,4 +4,5 @@ const (
|
|||||||
getAvailableConfigs = "/api/config/module/get_modules_info"
|
getAvailableConfigs = "/api/config/module/get_modules_info"
|
||||||
getConfigByModuleName = "/api/config/config/get_config_by_instance_uuid_and_module_name"
|
getConfigByModuleName = "/api/config/config/get_config_by_instance_uuid_and_module_name"
|
||||||
createUpdateConfig = "/api/config/config/create_update_config"
|
createUpdateConfig = "/api/config/config/create_update_config"
|
||||||
|
getSchemaByModuleId = "/api/config/schema/get_by_module_id"
|
||||||
)
|
)
|
||||||
@@ -54,3 +54,12 @@ func (c *configClient) CreateUpdateConfig(request Config) (*Config, error) {
|
|||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *configClient) GetSchemaByModuleId(moduleId int32) (*ConfigSchema, error) {
|
||||||
|
request := &getSchemaByModuleIdRequest{ModuleId: moduleId}
|
||||||
|
response := new(ConfigSchema)
|
||||||
|
if err := c.client.Invoke("POST", c.gateHost+getSchemaByModuleId, c.headers, &request, response); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
+18
-1
@@ -15,7 +15,7 @@ import (
|
|||||||
func checkFlags(c *cli.Context) error {
|
func checkFlags(c *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
uuid, host string
|
uuid, host string
|
||||||
color bool
|
color, unsafe bool
|
||||||
)
|
)
|
||||||
colorFlag := strings.Split(flag.ColorName, ", ")
|
colorFlag := strings.Split(flag.ColorName, ", ")
|
||||||
if c.GlobalBool(colorFlag[0]) != false {
|
if c.GlobalBool(colorFlag[0]) != false {
|
||||||
@@ -24,6 +24,15 @@ func checkFlags(c *cli.Context) error {
|
|||||||
color = c.GlobalBool(colorFlag[1])
|
color = c.GlobalBool(colorFlag[1])
|
||||||
}
|
}
|
||||||
service.ColorService.Enable = color
|
service.ColorService.Enable = color
|
||||||
|
|
||||||
|
unsafeFlag := strings.Split(flag.UnsafeName, ", ")
|
||||||
|
if c.GlobalBool(unsafeFlag[0]) != false {
|
||||||
|
unsafe = true
|
||||||
|
} else {
|
||||||
|
unsafe = c.GlobalBool(unsafeFlag[1])
|
||||||
|
}
|
||||||
|
service.UnsafeService.Enable = unsafe
|
||||||
|
|
||||||
hostFlag := strings.Split(flag.GateHostName, ", ")
|
hostFlag := strings.Split(flag.GateHostName, ", ")
|
||||||
if c.GlobalString(hostFlag[0]) != "" {
|
if c.GlobalString(hostFlag[0]) != "" {
|
||||||
host = c.GlobalString(hostFlag[0])
|
host = c.GlobalString(hostFlag[0])
|
||||||
@@ -118,6 +127,14 @@ func createUpdateConfig(stringToChange string, configuration *cfg.Config) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ok, err := service.UnsafeService.CheckConfigurationSchema(configuration.ModuleId, newData); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
} else if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
configuration.Data = newData
|
configuration.Data = newData
|
||||||
if resp, err := service.ConfigClient.CreateUpdateConfig(*configuration); err != nil {
|
if resp, err := service.ConfigClient.CreateUpdateConfig(*configuration); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|||||||
@@ -41,19 +41,22 @@ func (statusCommand) action(c *cli.Context) {
|
|||||||
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
|
table.SetBorders(tablewriter.Border{Left: false, Top: false, Right: false, Bottom: false})
|
||||||
table.SetHeader([]string{tableHeaderModuleName, tableHeaderStatus, tableHeaderAddresses})
|
table.SetHeader([]string{tableHeaderModuleName, tableHeaderStatus, tableHeaderAddresses})
|
||||||
for _, module := range arrayOfModules {
|
for _, module := range arrayOfModules {
|
||||||
arrayOfAddress := ""
|
addresses := ""
|
||||||
connection := tableNotConnectedStatus
|
connection := tableNotConnectedStatus
|
||||||
for _, value := range module.Status {
|
for _, value := range module.Status {
|
||||||
if arrayOfAddress == "" {
|
if value.Address.IP == "" && value.Address.Port == "" {
|
||||||
arrayOfAddress = fmt.Sprintf("%s", value.Address.IP)
|
continue
|
||||||
|
}
|
||||||
|
if addresses == "" {
|
||||||
|
addresses = fmt.Sprintf("%s:%s;", value.Address.IP, value.Address.Port)
|
||||||
} else {
|
} else {
|
||||||
arrayOfAddress = fmt.Sprintf("%s, %s", arrayOfAddress, value.Address)
|
addresses = fmt.Sprintf("%s\n%s:%s;", addresses, value.Address.IP, value.Address.Port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if arrayOfAddress != "" {
|
if addresses != "" {
|
||||||
connection = tableConnectedStatus
|
connection = tableConnectedStatus
|
||||||
}
|
}
|
||||||
table.Append([]string{module.Name, connection, arrayOfAddress})
|
table.Append([]string{module.Name, connection, addresses})
|
||||||
}
|
}
|
||||||
table.Render()
|
table.Render()
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,2 +1,2 @@
|
|||||||
gateHost: 127.0.0.1:0000
|
gateHost: 10.250.9.40:9003
|
||||||
instanceUuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
instanceUuid: ec183598-746a-425f-b5e5-27b7fa8bc6af
|
||||||
+4
-3
@@ -3,7 +3,8 @@ package flag
|
|||||||
import "github.com/codegangsta/cli"
|
import "github.com/codegangsta/cli"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Host = cli.StringFlag{Name: GateHostName}
|
Host = cli.StringFlag{Name: GateHostName, Usage: "overrides gateHost"}
|
||||||
Uuid = cli.StringFlag{Name: InstanceUuidName}
|
Uuid = cli.StringFlag{Name: InstanceUuidName, Usage: "overrides instanceUuid"}
|
||||||
Color = cli.BoolFlag{Name: ColorName}
|
Color = cli.BoolFlag{Name: ColorName, Usage: "colorize the json for outputing to screen"}
|
||||||
|
Unsafe = cli.BoolFlag{Name: UnsafeName, Usage: "disable checking schema for set configuration"}
|
||||||
)
|
)
|
||||||
@@ -4,4 +4,5 @@ const (
|
|||||||
GateHostName = "gateHost, g"
|
GateHostName = "gateHost, g"
|
||||||
InstanceUuidName = "instanceUuid, u"
|
InstanceUuidName = "instanceUuid, u"
|
||||||
ColorName = "color, c"
|
ColorName = "color, c"
|
||||||
|
UnsafeName = "unsafe, s"
|
||||||
)
|
)
|
||||||
@@ -9,9 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var version = "1.1.0"
|
||||||
version = "1.0.0"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
defineConfigurationPath()
|
defineConfigurationPath()
|
||||||
@@ -22,10 +20,10 @@ func initCommands() {
|
|||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Usage = "isp configurations updater"
|
app.Usage = "isp configurations updater"
|
||||||
app.UsageText =
|
app.UsageText =
|
||||||
` ispctl status [flag...]
|
` ispctl [flag...] status
|
||||||
ispctl get [flag...] module_name property_path
|
ispctl [flag...] get module_name property_path
|
||||||
ispctl set [flag...] module_name property_path [new_object]
|
ispctl [flag...] set module_name property_path [new_object]
|
||||||
ispctl delete [flag...] module_name property_path`
|
ispctl [flag...] delete module_name property_path`
|
||||||
|
|
||||||
app.Version = version
|
app.Version = version
|
||||||
|
|
||||||
@@ -33,6 +31,7 @@ func initCommands() {
|
|||||||
flag.Host,
|
flag.Host,
|
||||||
flag.Uuid,
|
flag.Uuid,
|
||||||
flag.Color,
|
flag.Color,
|
||||||
|
flag.Unsafe,
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/xeipuuv/gojsonschema"
|
||||||
|
)
|
||||||
|
|
||||||
|
var UnsafeService unsafeService
|
||||||
|
|
||||||
|
type unsafeService struct {
|
||||||
|
Enable bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s unsafeService) CheckConfigurationSchema(moduleId int32, object map[string]interface{}) (bool, error) {
|
||||||
|
if s.Enable {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp, err := ConfigClient.GetSchemaByModuleId(moduleId); err != nil {
|
||||||
|
return false, err
|
||||||
|
} else {
|
||||||
|
schemaLoader := gojsonschema.NewGoLoader(resp.Schema)
|
||||||
|
documentLoader := gojsonschema.NewGoLoader(object)
|
||||||
|
|
||||||
|
if result, err := gojsonschema.Validate(schemaLoader, documentLoader); err != nil {
|
||||||
|
return false, err
|
||||||
|
} else if result.Valid() {
|
||||||
|
return true, nil
|
||||||
|
} else {
|
||||||
|
for _, desc := range result.Errors() {
|
||||||
|
fmt.Printf("- %s\n", desc)
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user