Merge pull request #1 from integration-system/common_configs
migrate invoke from convert to config
This commit is contained in:
12 files changed
+187
-101
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
|
## v1.2.4
|
||||||
|
* migrate invoke to config service
|
||||||
## v1.2.3
|
## v1.2.3
|
||||||
* read configuration from `stdin` till `EOF`
|
* read configuration from `stdin` till `EOF`
|
||||||
## v1.2.2
|
## v1.2.2
|
||||||
|
|||||||
Generated
+92
-46
@@ -50,19 +50,26 @@
|
|||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:abd0cd78d6d27a98080f2b2a7fd39bb2f3d3eef6aa20c720093129f04fb41d78"
|
digest = "1:c4f3970d1f30f5e9bc1751b62b7ea6127256e59fd63a3d36e166fe1121250c57"
|
||||||
name = "github.com/integration-system/gowsdl"
|
name = "github.com/integration-system/go-cmp"
|
||||||
packages = ["soap"]
|
packages = [
|
||||||
|
"cmp",
|
||||||
|
"cmp/internal/diff",
|
||||||
|
"cmp/internal/function",
|
||||||
|
"cmp/internal/value",
|
||||||
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "368713356c71961354e09ab9b734740ebdd94784"
|
revision = "ac5582987a2f25e8743e0ebb7259312adda05c23"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:95c2d64f7a0ec98156d5b970f7cef94d418025ec4b4324d81318743db2a158fc"
|
digest = "1:2c5074a55f97c23cd89581a5d66fa82c26ee1fa01bffad0d3f540e8d28b131e5"
|
||||||
name = "github.com/integration-system/isp-lib"
|
name = "github.com/integration-system/isp-lib"
|
||||||
packages = [
|
packages = [
|
||||||
|
"backend",
|
||||||
"config/schema",
|
"config/schema",
|
||||||
"http",
|
"proto/stubs",
|
||||||
|
"streaming",
|
||||||
"structure",
|
"structure",
|
||||||
"utils",
|
"utils",
|
||||||
]
|
]
|
||||||
@@ -99,18 +106,6 @@
|
|||||||
revision = "03217c3e97663914aec3faafde50d081f197a0a2"
|
revision = "03217c3e97663914aec3faafde50d081f197a0a2"
|
||||||
version = "1.1.8"
|
version = "1.1.8"
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:acfc228fb5fbfb82645c121e3224bd546ed68aef6dfc87f63e2d8de099a3822b"
|
|
||||||
name = "github.com/klauspost/compress"
|
|
||||||
packages = [
|
|
||||||
"flate",
|
|
||||||
"gzip",
|
|
||||||
"zlib",
|
|
||||||
]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "a41f1a10bd3b167958ff6df80b800fe2969dd3ca"
|
|
||||||
version = "v1.9.0"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:31e761d97c76151dde79e9d28964a812c46efc5baee4085b86f68f0c654450de"
|
digest = "1:31e761d97c76151dde79e9d28964a812c46efc5baee4085b86f68f0c654450de"
|
||||||
name = "github.com/konsorten/go-windows-terminal-sequences"
|
name = "github.com/konsorten/go-windows-terminal-sequences"
|
||||||
@@ -159,6 +154,14 @@
|
|||||||
revision = "e6d60cf7ba1f42d86d54cdf5508611c4aafb3970"
|
revision = "e6d60cf7ba1f42d86d54cdf5508611c4aafb3970"
|
||||||
version = "v0.0.1"
|
version = "v0.0.1"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
digest = "1:cf31692c14422fa27c83a05292eb5cbe0fb2775972e8f1f8446a71549bd8980b"
|
||||||
|
name = "github.com/pkg/errors"
|
||||||
|
packages = ["."]
|
||||||
|
pruneopts = "UT"
|
||||||
|
revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4"
|
||||||
|
version = "v0.8.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:b36a0ede02c4c2aef7df7f91cbbb7bb88a98b5d253509d4f997dda526e50c88c"
|
digest = "1:b36a0ede02c4c2aef7df7f91cbbb7bb88a98b5d253509d4f997dda526e50c88c"
|
||||||
name = "github.com/russross/blackfriday"
|
name = "github.com/russross/blackfriday"
|
||||||
@@ -215,26 +218,6 @@
|
|||||||
revision = "bfe2e925cfb6d44b40ad3a779165ea7e8aff9212"
|
revision = "bfe2e925cfb6d44b40ad3a779165ea7e8aff9212"
|
||||||
version = "v1.22.0"
|
version = "v1.22.0"
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
digest = "1:c468422f334a6b46a19448ad59aaffdfc0a36b08fdcc1c749a0b29b6453d7e59"
|
|
||||||
name = "github.com/valyala/bytebufferpool"
|
|
||||||
packages = ["."]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7"
|
|
||||||
version = "v1.0.0"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
digest = "1:77f7e2f75e4c44ede24f47aca6c514f24f06c6a0ee3c47c8d7ce2b77b49ac482"
|
|
||||||
name = "github.com/valyala/fasthttp"
|
|
||||||
packages = [
|
|
||||||
".",
|
|
||||||
"fasthttputil",
|
|
||||||
"stackless",
|
|
||||||
]
|
|
||||||
pruneopts = "UT"
|
|
||||||
revision = "9bc6da12192c610a272a9289b9574eb5d8cfdfe1"
|
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:87fe9bca786484cef53d52adeec7d1c52bc2bfbee75734eddeb75fc5c7023871"
|
digest = "1:87fe9bca786484cef53d52adeec7d1c52bc2bfbee75734eddeb75fc5c7023871"
|
||||||
@@ -261,19 +244,52 @@
|
|||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:76ee51c3f468493aff39dbacc401e8831fbb765104cbf613b89bef01cf4bad70"
|
digest = "1:c124e945335a9c62ede3a565f3198c5ae9a5ecc39fddd85871138362d128fb74"
|
||||||
name = "golang.org/x/net"
|
name = "golang.org/x/net"
|
||||||
packages = ["context"]
|
packages = [
|
||||||
|
"context",
|
||||||
|
"http/httpguts",
|
||||||
|
"http2",
|
||||||
|
"http2/hpack",
|
||||||
|
"idna",
|
||||||
|
"internal/timeseries",
|
||||||
|
"trace",
|
||||||
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "ec77196f6094c3492a8b61f2c11cf937f78992ae"
|
revision = "fe3aa8a4527195a6057b3fad46619d7d090e99b5"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:56068728488986584e5a2f3576cb84d52bad7ec7fbe63a14b0d3b26bfdb41b8b"
|
digest = "1:89c4223950671f7afdc98761c6a601b83594865490c71b434194b6cacf208e6a"
|
||||||
name = "golang.org/x/sys"
|
name = "golang.org/x/sys"
|
||||||
packages = ["unix"]
|
packages = ["unix"]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "6c3a3bfe00aeca2b8685f04a482824367e7d2135"
|
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]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@@ -287,16 +303,42 @@
|
|||||||
revision = "548a555dbc03994223efbaba0090152849259498"
|
revision = "548a555dbc03994223efbaba0090152849259498"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:42de3e9a8a8d7d0c7dc0e832f03786c3993c6d97b0e4a18268fb0142cd65e247"
|
digest = "1:6cd77d0b616d2dcebd363dfecba593f27b0151fc82cdb5fbfb96c5a7cfbc95b5"
|
||||||
name = "google.golang.org/grpc"
|
name = "google.golang.org/grpc"
|
||||||
packages = [
|
packages = [
|
||||||
|
".",
|
||||||
|
"balancer",
|
||||||
|
"balancer/base",
|
||||||
|
"balancer/roundrobin",
|
||||||
|
"binarylog/grpc_binarylog_v1",
|
||||||
"codes",
|
"codes",
|
||||||
"connectivity",
|
"connectivity",
|
||||||
|
"credentials",
|
||||||
|
"credentials/internal",
|
||||||
|
"encoding",
|
||||||
|
"encoding/proto",
|
||||||
"grpclog",
|
"grpclog",
|
||||||
"internal",
|
"internal",
|
||||||
|
"internal/backoff",
|
||||||
|
"internal/balancerload",
|
||||||
|
"internal/binarylog",
|
||||||
|
"internal/channelz",
|
||||||
|
"internal/envconfig",
|
||||||
|
"internal/grpcrand",
|
||||||
|
"internal/grpcsync",
|
||||||
|
"internal/syscall",
|
||||||
|
"internal/transport",
|
||||||
|
"keepalive",
|
||||||
"metadata",
|
"metadata",
|
||||||
|
"naming",
|
||||||
|
"peer",
|
||||||
|
"resolver",
|
||||||
|
"resolver/dns",
|
||||||
|
"resolver/passthrough",
|
||||||
|
"serviceconfig",
|
||||||
"stats",
|
"stats",
|
||||||
"status",
|
"status",
|
||||||
|
"tap",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "f6d0f9ee430895e87ef1ceb5ac8f39725bafceef"
|
revision = "f6d0f9ee430895e87ef1ceb5ac8f39725bafceef"
|
||||||
@@ -316,15 +358,19 @@
|
|||||||
input-imports = [
|
input-imports = [
|
||||||
"github.com/codegangsta/cli",
|
"github.com/codegangsta/cli",
|
||||||
"github.com/integration-system/bellows",
|
"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/config/schema",
|
||||||
"github.com/integration-system/isp-lib/http",
|
|
||||||
"github.com/integration-system/isp-lib/structure",
|
"github.com/integration-system/isp-lib/structure",
|
||||||
"github.com/olekukonko/tablewriter",
|
"github.com/olekukonko/tablewriter",
|
||||||
|
"github.com/pkg/errors",
|
||||||
"github.com/tidwall/gjson",
|
"github.com/tidwall/gjson",
|
||||||
"github.com/tidwall/pretty",
|
"github.com/tidwall/pretty",
|
||||||
"github.com/tidwall/sjson",
|
"github.com/tidwall/sjson",
|
||||||
"github.com/valyala/fasthttp",
|
|
||||||
"github.com/xeipuuv/gojsonschema",
|
"github.com/xeipuuv/gojsonschema",
|
||||||
|
"google.golang.org/grpc",
|
||||||
|
"google.golang.org/grpc/codes",
|
||||||
|
"google.golang.org/grpc/metadata",
|
||||||
|
"google.golang.org/grpc/status",
|
||||||
"gopkg.in/yaml.v2",
|
"gopkg.in/yaml.v2",
|
||||||
]
|
]
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ yum install ispctl
|
|||||||
gateHost: 127.0.0.1:0000
|
gateHost: 127.0.0.1:0000
|
||||||
instanceUuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
instanceUuid: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||||
```
|
```
|
||||||
* `gateHost` - адрес любого isp-convert-service в кластере
|
* `gateHost` - адрес любого isp-config-service в кластере
|
||||||
* `instanceUuid` - UUID - идентификатор экземпляра приложений
|
* `instanceUuid` - UUID - идентификатор экземпляра приложений
|
||||||
|
|
||||||
## Использование
|
## Использование
|
||||||
|
|||||||
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
package cfg
|
package cfg
|
||||||
|
|
||||||
const (
|
const (
|
||||||
getAvailableConfigs = "/api/config/module/get_modules_info"
|
getAvailableConfigs = "config/module/get_modules_info"
|
||||||
getConfigByModuleName = "/api/config/config/get_config_by_instance_uuid_and_module_name"
|
getConfigByModuleName = "config/config/get_config_by_instance_uuid_and_module_name"
|
||||||
createUpdateConfig = "/api/config/config/create_update_config"
|
createUpdateConfig = "config/config/create_update_config"
|
||||||
getSchemaByModuleId = "/api/config/schema/get_by_module_id"
|
getSchemaByModuleId = "config/schema/get_by_module_id"
|
||||||
)
|
)
|
||||||
+56
-23
@@ -1,65 +1,98 @@
|
|||||||
package cfg
|
package cfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/integration-system/isp-lib/http"
|
"github.com/integration-system/isp-lib/backend"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/metadata"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
instanceIdHeader = "x-instance-identity"
|
instanceIdHeader = "x-instance-identity"
|
||||||
scheme = "http://"
|
callerId = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewConfigClient(client http.RestClient) *configClient {
|
func NewConfigClient() *configClient {
|
||||||
return &configClient{
|
return &configClient{
|
||||||
client: client,
|
cli: &backend.InternalGrpcClient{},
|
||||||
headers: make(map[string]string),
|
headers: make(map[string][]string),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type configClient struct {
|
type configClient struct {
|
||||||
client http.RestClient
|
cli *backend.InternalGrpcClient
|
||||||
headers map[string]string
|
headers metadata.MD
|
||||||
|
|
||||||
gateHost string
|
address string
|
||||||
instanceUuid string
|
instanceUuid string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configClient) ReceiveConfig(gateHost, instanceUuid string) {
|
func (c *configClient) ReceiveConfig(address, instanceUuid string) error {
|
||||||
|
var err error
|
||||||
|
c.cli, err = backend.NewGrpcClient(address, grpc.WithInsecure())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.address = address
|
||||||
c.instanceUuid = instanceUuid
|
c.instanceUuid = instanceUuid
|
||||||
c.headers[instanceIdHeader] = instanceUuid
|
c.headers[instanceIdHeader] = []string{instanceUuid}
|
||||||
c.gateHost = scheme + gateHost
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configClient) GetAvailableConfigs() ([]ModuleInfo, error) {
|
func (c *configClient) GetAvailableConfigs() ([]ModuleInfo, error) {
|
||||||
response := make([]ModuleInfo, 0)
|
response := make([]ModuleInfo, 0)
|
||||||
if err := c.client.Invoke("POST", c.gateHost+getAvailableConfigs, c.headers, nil, &response); err != nil {
|
err := c.cli.Invoke(getAvailableConfigs, callerId, nil, &response, backend.WithMetadata(c.headers))
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
return nil, c.errorHandler(err)
|
||||||
|
} else {
|
||||||
|
return response, nil
|
||||||
}
|
}
|
||||||
return response, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configClient) GetConfigByModuleName(name string) (*Config, error) {
|
func (c *configClient) GetConfigByModuleName(name string) (*Config, error) {
|
||||||
request := &getModuleByUuidAndNameRequest{Name: name, Uuid: c.instanceUuid}
|
request := &getModuleByUuidAndNameRequest{Name: name, Uuid: c.instanceUuid}
|
||||||
response := new(Config)
|
response := new(Config)
|
||||||
if err := c.client.Invoke("POST", c.gateHost+getConfigByModuleName, c.headers, request, response); err != nil {
|
err := c.cli.Invoke(getConfigByModuleName, callerId, request, response, backend.WithMetadata(c.headers))
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
return nil, c.errorHandler(err)
|
||||||
|
} else {
|
||||||
|
return response, nil
|
||||||
}
|
}
|
||||||
return response, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configClient) CreateUpdateConfig(request Config) (*Config, error) {
|
func (c *configClient) CreateUpdateConfig(request Config) (*Config, error) {
|
||||||
response := new(Config)
|
response := new(Config)
|
||||||
if err := c.client.Invoke("POST", c.gateHost+createUpdateConfig, c.headers, &request, response); err != nil {
|
err := c.cli.Invoke(createUpdateConfig, callerId, &request, response, backend.WithMetadata(c.headers))
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
return nil, c.errorHandler(err)
|
||||||
|
} else {
|
||||||
|
return response, nil
|
||||||
}
|
}
|
||||||
return response, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configClient) GetSchemaByModuleId(moduleId int32) (*ConfigSchema, error) {
|
func (c *configClient) GetSchemaByModuleId(moduleId int32) (*ConfigSchema, error) {
|
||||||
request := &getSchemaByModuleIdRequest{ModuleId: moduleId}
|
request := &getSchemaByModuleIdRequest{ModuleId: moduleId}
|
||||||
response := new(ConfigSchema)
|
response := new(ConfigSchema)
|
||||||
if err := c.client.Invoke("POST", c.gateHost+getSchemaByModuleId, c.headers, &request, response); err != nil {
|
err := c.cli.Invoke(getSchemaByModuleId, callerId, &request, response, backend.WithMetadata(c.headers))
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
return nil, c.errorHandler(err)
|
||||||
|
} else {
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *configClient) errorHandler(err error) error {
|
||||||
|
errStatus, ok := status.FromError(err)
|
||||||
|
if !ok {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch errStatus.Code() {
|
||||||
|
case codes.Unavailable:
|
||||||
|
return errors.Errorf("config service didn't connection on %s", c.address)
|
||||||
|
default:
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return response, nil
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -2,8 +2,8 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"isp-ctl/cfg"
|
"isp-ctl/cfg"
|
||||||
"isp-ctl/service"
|
"isp-ctl/service"
|
||||||
"strings"
|
"strings"
|
||||||
|
|||||||
+2
-3
@@ -2,9 +2,8 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"isp-ctl/bash"
|
"isp-ctl/bash"
|
||||||
"isp-ctl/flag"
|
"isp-ctl/flag"
|
||||||
@@ -54,7 +53,7 @@ func (g getCommand) action(ctx *cli.Context) {
|
|||||||
func (g getCommand) checkObject(jsonObject []byte, depth string) {
|
func (g getCommand) checkObject(jsonObject []byte, depth string) {
|
||||||
jsonString := gjson.Get(string(jsonObject), depth)
|
jsonString := gjson.Get(string(jsonObject), depth)
|
||||||
if jsonString.Raw == "" {
|
if jsonString.Raw == "" {
|
||||||
printError(errors.New(fmt.Sprintf("Path '%s' not found\n", depth)))
|
printError(errors.Errorf("Path '%s' not found\n", depth))
|
||||||
} else {
|
} else {
|
||||||
var data interface{}
|
var data interface{}
|
||||||
if err := json.Unmarshal([]byte(jsonString.Raw), &data); err != nil {
|
if err := json.Unmarshal([]byte(jsonString.Raw), &data); err != nil {
|
||||||
|
|||||||
+3
-4
@@ -1,9 +1,8 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"html/template"
|
"html/template"
|
||||||
"isp-ctl/bash"
|
"isp-ctl/bash"
|
||||||
"isp-ctl/flag"
|
"isp-ctl/flag"
|
||||||
@@ -45,8 +44,8 @@ func (s schemaCommand) action(ctx *cli.Context) {
|
|||||||
case flag.OutPrintHtmlValue:
|
case flag.OutPrintHtmlValue:
|
||||||
s.printHtml(schema)
|
s.printHtml(schema)
|
||||||
default:
|
default:
|
||||||
printError(errors.New(fmt.Sprintf(
|
printError(errors.Errorf(
|
||||||
"invalid flag value, expected %s or %s", flag.OutPrintJsonValue, flag.OutPrintHtmlValue)))
|
"invalid flag value, expected %s or %s", flag.OutPrintJsonValue, flag.OutPrintHtmlValue))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2,8 +2,8 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/tidwall/sjson"
|
"github.com/tidwall/sjson"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"isp-ctl/bash"
|
"isp-ctl/bash"
|
||||||
|
|||||||
+1
-2
@@ -58,6 +58,5 @@ func CheckGlobal(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
service.Config.ReceiveConfiguration(host, uuid)
|
return service.Config.ReceiveConfiguration(host, uuid)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
+23
-15
@@ -2,39 +2,47 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/integration-system/isp-lib/config/schema"
|
"github.com/integration-system/isp-lib/config/schema"
|
||||||
"github.com/integration-system/isp-lib/http"
|
"github.com/pkg/errors"
|
||||||
"github.com/valyala/fasthttp"
|
|
||||||
"github.com/xeipuuv/gojsonschema"
|
"github.com/xeipuuv/gojsonschema"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
"isp-ctl/cfg"
|
"isp-ctl/cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
configClient = cfg.NewConfigClient(http.NewJsonRestClient())
|
configClient = cfg.NewConfigClient()
|
||||||
Config configService
|
Config = &configService{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type configService struct {
|
type configService struct {
|
||||||
UnsafeEnable bool
|
UnsafeEnable bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (configService) ReceiveConfiguration(host, uuid string) {
|
func (c *configService) ReceiveConfiguration(host, uuid string) error {
|
||||||
configClient.ReceiveConfig(host, uuid)
|
return configClient.ReceiveConfig(host, uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (configService) GetAvailableConfigs() ([]cfg.ModuleInfo, error) {
|
func (c *configService) GetAvailableConfigs() ([]cfg.ModuleInfo, error) {
|
||||||
return configClient.GetAvailableConfigs()
|
if moduleInfo, err := configClient.GetAvailableConfigs(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return moduleInfo, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (configService) GetConfigurationAndJsonByModuleName(moduleName string) (*cfg.Config, []byte, error) {
|
func (c *configService) GetConfigurationAndJsonByModuleName(moduleName string) (*cfg.Config, []byte, error) {
|
||||||
if moduleName == "" {
|
if moduleName == "" {
|
||||||
return nil, nil, errors.New("need module name")
|
return nil, nil, errors.New("need module name")
|
||||||
}
|
}
|
||||||
|
|
||||||
if moduleConfiguration, err := configClient.GetConfigByModuleName(moduleName); err != nil {
|
if moduleConfiguration, err := configClient.GetConfigByModuleName(moduleName); err != nil {
|
||||||
if errorResponse, ok := err.(http.ErrorResponse); ok && errorResponse.StatusCode == fasthttp.StatusNotFound {
|
if errorStatus, ok := status.FromError(err); ok {
|
||||||
return nil, nil, errors.New(fmt.Sprintf("module '%s' not found", moduleName))
|
switch errorStatus.Code() {
|
||||||
|
case codes.NotFound:
|
||||||
|
return nil, nil, errors.Errorf("module '%s' not found", moduleName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
} else if jsonObject, err := json.Marshal(moduleConfiguration.Data); err != nil {
|
} else if jsonObject, err := json.Marshal(moduleConfiguration.Data); err != nil {
|
||||||
@@ -44,7 +52,7 @@ func (configService) GetConfigurationAndJsonByModuleName(moduleName string) (*cf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (configService) GetSchemaByModuleId(moduleId int32) (schema.Schema, error) {
|
func (c *configService) GetSchemaByModuleId(moduleId int32) (schema.Schema, error) {
|
||||||
if configSchema, err := configClient.GetSchemaByModuleId(moduleId); err != nil {
|
if configSchema, err := configClient.GetSchemaByModuleId(moduleId); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
@@ -53,7 +61,7 @@ func (configService) GetSchemaByModuleId(moduleId int32) (schema.Schema, error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c configService) CreateUpdateConfig(stringToChange string, configuration *cfg.Config) (map[string]interface{}, error) {
|
func (c *configService) CreateUpdateConfig(stringToChange string, configuration *cfg.Config) (map[string]interface{}, error) {
|
||||||
newData := make(map[string]interface{})
|
newData := make(map[string]interface{})
|
||||||
if stringToChange != "" {
|
if stringToChange != "" {
|
||||||
if err := json.Unmarshal([]byte(stringToChange), &newData); err != nil {
|
if err := json.Unmarshal([]byte(stringToChange), &newData); err != nil {
|
||||||
@@ -75,7 +83,7 @@ func (c configService) CreateUpdateConfig(stringToChange string, configuration *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c configService) checkSchema(moduleId int32, object map[string]interface{}) (bool, error) {
|
func (c *configService) checkSchema(moduleId int32, object map[string]interface{}) (bool, error) {
|
||||||
if c.UnsafeEnable {
|
if c.UnsafeEnable {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user