Reimplement

This commit is contained in:
d1slike committed 2023-06-09 17:25:12 +03:00
1 parent d4d7c679aa
commit df259e3f78
36 files changed
+559 -1135

No files matched your search

+1 -1
View File
@@ -1 +1 @@
2.2.3
3.0.0
+1 -1
View File
@@ -460,7 +460,7 @@ ispctl common unlink test module_example
Запрос
```bash
isp-ctl common contain second_common_config
ispctl common contain second_common_config
```
Ответ
Ответ
+4 -4
View File
@@ -1,9 +1,9 @@
#!/bin/bash
mkdir -p configs
if [ -n "$*" ]; then
statusResponse=$(isp-ctl $* status)
statusResponse=$(ispctl $* status)
else
statusResponse=$(isp-ctl status)
statusResponse=$(ispctl status)
fi
i=0
@@ -16,9 +16,9 @@ for status in $statusResponse; do
read -ra ADDR <<<"$status"
for module_name in "${ADDR[0]}"; do
if [ -n "$*" ]; then
isp-ctl $* get $module_name . > configs/$module_name.json
ispctl $* get $module_name . > configs/$module_name.json
else
isp-ctl get $module_name . > configs/$module_name.json
ispctl get $module_name . > configs/$module_name.json
fi
break
done
+4 -4
View File
@@ -1,9 +1,9 @@
#!/bin/bash
mkdir -p schemas
if [ -n "$*" ]; then
statusResponse=$(isp-ctl $* status)
statusResponse=$(ispctl $* status)
else
statusResponse=$(isp-ctl status)
statusResponse=$(ispctl status)
fi
i=0
@@ -16,9 +16,9 @@ for status in $statusResponse; do
read -ra ADDR <<<"$status"
for module_name in "${ADDR[0]}"; do
if [ -n "$*" ]; then
isp-ctl $* schema $module_name -o html > schemas/$module_name.html
ispctl $* schema $module_name -o html > schemas/$module_name.html
else
isp-ctl schema $module_name -o html > schemas/$module_name.html
ispctl schema $module_name -o html > schemas/$module_name.html
fi
break
done
+3 -2
View File
@@ -2,10 +2,11 @@ package bash
import (
"fmt"
"github.com/integration-system/bellows"
"github.com/urfave/cli/v2"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/flag"
"ispctl/service"
)
const (
+5 -6
View File
@@ -1,9 +1,10 @@
package cfg
import (
"github.com/integration-system/isp-lib/v2/config/schema"
"github.com/integration-system/isp-lib/v2/structure"
"time"
"github.com/integration-system/isp-kit/cluster"
"github.com/integration-system/isp-kit/rc/schema"
)
type getModuleByUuidAndNameRequest struct {
@@ -23,8 +24,6 @@ type Config struct {
ModuleId string
Version int32
Active bool
CreatedAt time.Time
UpdatedAt time.Time
Data map[string]interface{}
Unsafe bool
}
@@ -41,8 +40,8 @@ type CommonConfig struct {
type Connection struct {
LibVersion string
Version string
Address structure.AddressConfiguration
Endpoints []structure.EndpointConfig `json:",omitempty"`
Address cluster.AddressConfiguration
Endpoints []cluster.EndpointDescriptor `json:",omitempty"`
EstablishedAt time.Time
}
+97 -86
View File
@@ -1,152 +1,163 @@
package cfg
import (
"github.com/integration-system/isp-lib/v2/backend"
"github.com/integration-system/isp-lib/v2/structure"
"context"
"time"
"github.com/integration-system/isp-kit/grpc/client"
"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 (
instanceIdHeader = "x-instance-identity"
callerId = 1
)
func NewConfigClient() *configClient {
return &configClient{
cli: backend.NewRxGrpcClient(backend.WithDialOptions(grpc.WithInsecure())),
headers: make(map[string][]string),
}
type ConfigClient struct {
cli *client.Client
address string
}
type configClient struct {
cli *backend.RxGrpcClient
headers metadata.MD
address string
instanceUuid string
func NewConfigClient() *ConfigClient {
return &ConfigClient{}
}
func (c *configClient) ReceiveConfig(address, instanceUuid string) error {
host, port, err := net.SplitHostPort(address)
func (c *ConfigClient) ReceiveConfig(address string) error {
cli, err := client.Default()
if err != nil {
return err
}
c.cli.ReceiveAddressList([]structure.AddressConfiguration{{IP: host, Port: port}})
c.cli = cli
cli.Upgrade([]string{address})
c.address = address
c.instanceUuid = instanceUuid
c.headers[instanceIdHeader] = []string{instanceUuid}
return nil
}
func (c *configClient) GetAvailableConfigs() ([]ModuleInfo, error) {
func (c *ConfigClient) GetAvailableConfigs() ([]ModuleInfo, error) {
response := make([]ModuleInfo, 0)
err := c.cli.Invoke(getAvailableConfigs, callerId, nil, &response, backend.WithMetadata(c.headers))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := c.cli.Invoke(getAvailableConfigs).
ReadJsonResponse(&response).
Do(ctx)
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
return nil, errors.WithMessagef(err, "call %s", getAvailableConfigs)
}
return response, nil
}
func (c *configClient) GetConfigByModuleName(name string) (*Config, error) {
request := &getModuleByUuidAndNameRequest{ModuleName: name, Uuid: c.instanceUuid}
func (c *ConfigClient) GetConfigByModuleName(name string) (*Config, error) {
request := &getModuleByUuidAndNameRequest{ModuleName: name}
response := new(Config)
err := c.cli.Invoke(getConfigByModuleName, callerId, request, response, backend.WithMetadata(c.headers))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := c.cli.Invoke(getConfigByModuleName).
JsonRequestBody(request).
ReadJsonResponse(&response).
Do(ctx)
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
return nil, errors.WithMessagef(err, "call %s", getConfigByModuleName)
}
return response, nil
}
func (c *configClient) CreateUpdateConfig(request Config) (*Config, error) {
func (c *ConfigClient) CreateUpdateConfig(request Config) (*Config, error) {
response := new(Config)
err := c.cli.Invoke(createUpdateConfig, callerId, &request, response, backend.WithMetadata(c.headers))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := c.cli.Invoke(createUpdateConfig).
JsonRequestBody(request).
ReadJsonResponse(&response).
Do(ctx)
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
return nil, errors.WithMessagef(err, "call %s", createUpdateConfig)
}
return response, nil
}
func (c *configClient) GetSchemaByModuleId(moduleId string) (*ConfigSchema, error) {
request := &getSchemaByModuleIdRequest{ModuleId: moduleId}
func (c *ConfigClient) GetSchemaByModuleId(moduleId string) (*ConfigSchema, error) {
request := getSchemaByModuleIdRequest{ModuleId: moduleId}
response := new(ConfigSchema)
err := c.cli.Invoke(getSchemaByModuleId, callerId, &request, response, backend.WithMetadata(c.headers))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := c.cli.Invoke(getSchemaByModuleId).
JsonRequestBody(request).
ReadJsonResponse(&response).
Do(ctx)
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
return nil, errors.WithMessagef(err, "call %s", getSchemaByModuleId)
}
return response, nil
}
func (c *configClient) GetCommonConfigs(req []string) ([]CommonConfig, error) {
func (c *ConfigClient) GetCommonConfigs(req []string) ([]CommonConfig, error) {
response := make([]CommonConfig, 0)
err := c.cli.Invoke(getCommonConfigs, callerId, req, &response, backend.WithMetadata(c.headers))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := c.cli.Invoke(getCommonConfigs).
JsonRequestBody(req).
ReadJsonResponse(&response).
Do(ctx)
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
return nil, errors.WithMessagef(err, "call %s", getCommonConfigs)
}
return response, nil
}
func (c *configClient) CreateUpdateCommonConfig(req CommonConfig) (*CommonConfig, error) {
func (c *ConfigClient) CreateUpdateCommonConfig(req CommonConfig) (*CommonConfig, error) {
response := new(CommonConfig)
err := c.cli.Invoke(createUpdateCommonConfig, callerId, req, response, backend.WithMetadata(c.headers))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := c.cli.Invoke(createUpdateCommonConfig).
JsonRequestBody(req).
ReadJsonResponse(&response).
Do(ctx)
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
return nil, errors.WithMessagef(err, "call %s", createUpdateCommonConfig)
}
return response, nil
}
func (c *configClient) DeleteCommonConfig(id string) (*Deleted, error) {
func (c *ConfigClient) DeleteCommonConfig(id string) (*Deleted, error) {
request := identityRequest{Id: id}
response := new(Deleted)
err := c.cli.Invoke(deleteCommonConfig, callerId, request, response, backend.WithMetadata(c.headers))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := c.cli.Invoke(deleteCommonConfig).
JsonRequestBody(request).
ReadJsonResponse(&response).
Do(ctx)
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
return nil, errors.WithMessagef(err, "call %s", deleteCommonConfig)
}
return response, nil
}
func (c *configClient) GetLinksCommonConfig(id string) (*Links, error) {
func (c *ConfigClient) GetLinksCommonConfig(id string) (*Links, error) {
request := identityRequest{Id: id}
response := new(Links)
err := c.cli.Invoke(getLinksCommonConfig, callerId, request, response, backend.WithMetadata(c.headers))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := c.cli.Invoke(getLinksCommonConfig).
JsonRequestBody(request).
ReadJsonResponse(&response).
Do(ctx)
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
return nil, errors.WithMessagef(err, "call %s", getLinksCommonConfig)
}
return response, nil
}
func (c *configClient) CompileCommonConfigs(request CompileConfigs) (map[string]interface{}, error) {
func (c *ConfigClient) CompileCommonConfigs(request CompileConfigs) (map[string]interface{}, error) {
response := make(map[string]interface{})
err := c.cli.Invoke(compileCommonConfigs, callerId, request, &response, backend.WithMetadata(c.headers))
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
err := c.cli.Invoke(compileCommonConfigs).
JsonRequestBody(request).
ReadJsonResponse(response).
Do(ctx)
if err != nil {
return nil, c.errorHandler(err)
} else {
return response, nil
return nil, errors.WithMessagef(err, "call %s", compileCommonConfigs)
}
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
}
func (c *ConfigClient) errorHandler(err error) error {
return errors.WithMessagef(err, "isp-config-service: %s", c.address)
}
+2 -1
View File
@@ -2,8 +2,9 @@ package command
import (
"fmt"
"github.com/urfave/cli/v2"
"isp-ctl/command/common_config"
"ispctl/command/common_config"
)
func CommonConfig() *cli.Command {
+4 -3
View File
@@ -2,11 +2,12 @@ package common_config
import (
"fmt"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/flag"
"ispctl/service"
)
func Contain() *cli.Command {
+5 -4
View File
@@ -2,13 +2,14 @@ package common_config
import (
"encoding/json"
"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"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Delete() *cli.Command {
+5 -4
View File
@@ -3,12 +3,13 @@ package common_config
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Get() *cli.Command {
+3 -3
View File
@@ -2,9 +2,9 @@ package common_config
import (
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/flag"
"ispctl/service"
)
func Link() *cli.Command {
+4 -3
View File
@@ -2,11 +2,12 @@ package common_config
import (
"fmt"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/flag"
"ispctl/service"
)
func Remove() *cli.Command {
+6 -5
View File
@@ -2,14 +2,15 @@ package common_config
import (
"encoding/json"
"github.com/pkg/errors"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/cfg"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/cfg"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Set() *cli.Command {
+3 -3
View File
@@ -2,9 +2,9 @@ package common_config
import (
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/flag"
"ispctl/service"
)
func UnLink() *cli.Command {
+5 -4
View File
@@ -2,12 +2,13 @@ package command
import (
"encoding/json"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Delete() *cli.Command {
+5 -4
View File
@@ -2,11 +2,12 @@ package command
import (
"encoding/json"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Get() *cli.Command {
+60
View File
@@ -0,0 +1,60 @@
package command
import (
"io"
"os"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)
func GitGet() *cli.Command {
return &cli.Command{
Name: "gitget",
Usage: "gitget [repository] [file] (commit)",
Description: "clone and print specified file from specified repository and specified commit hash",
Action: func(context *cli.Context) error {
storage := memory.NewStorage()
repo := context.Args().Get(0)
file := context.Args().Get(1)
commit := context.Args().Get(2)
repository, err := git.Clone(storage, memfs.New(), &git.CloneOptions{
URL: repo,
})
if err != nil {
return errors.WithMessagef(err, "clone %s", repo)
}
tree, err := repository.Worktree()
if err != nil {
return errors.WithMessage(err, "get worktree")
}
if commit != "" {
err = tree.Checkout(&git.CheckoutOptions{
Hash: plumbing.NewHash(commit),
})
if err != nil {
return errors.WithMessagef(err, "checkout: %s", commit)
}
}
f, err := tree.Filesystem.Open(file)
if err != nil {
return errors.WithMessagef(err, "open %s", file)
}
_, err = io.Copy(os.Stdout, f)
if err != nil {
return err
}
return nil
},
}
}
+49
View File
@@ -0,0 +1,49 @@
package command
import (
"encoding/json"
"os"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Merge() *cli.Command {
return &cli.Command{
Name: "merge",
Usage: "merge actual config with config from stdin",
BashComplete: bash.Get(bash.CommonConfigName, bash.Empty).Complete,
Action: func(context *cli.Context) error {
err := flag.CheckGlobal(context)
if err != nil {
return err
}
moduleName := context.Args().First()
config, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil {
return errors.WithMessagef(err, "get module config '%s'", moduleName)
}
inputConfig := make(map[string]any)
err = json.NewDecoder(os.Stdin).Decode(&inputConfig)
if err != nil {
return errors.WithMessage(err, "json unmarshal input config")
}
for key, value := range inputConfig {
config.Data[key] = value
}
result, err := service.Config.CreateUpdateConfigV2(config)
if err != nil {
return errors.WithMessagef(err, "update module config '%s'", moduleName)
}
utils.PrintAnswer(result)
return nil
},
}
}
+8 -7
View File
@@ -1,15 +1,16 @@
package command
import (
"html/template"
"os"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"html/template"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"isp-ctl/tmpl"
"os"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
"ispctl/tmpl"
)
func Schema() *cli.Command {
+5 -4
View File
@@ -2,12 +2,13 @@ package command
import (
"encoding/json"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Set() *cli.Command {
+7 -6
View File
@@ -2,13 +2,14 @@ package command
import (
"fmt"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"os"
"strings"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
const (
@@ -54,7 +55,7 @@ func (statusCommand) action(ctx *cli.Context) error {
connection := tableNotConnectedStatus
instanceList := make([]string, 0, len(module.Status))
for _, value := range module.Status {
instanceList = append(instanceList, fmt.Sprintf("%s %s", value.Address.GetAddress(), value.Version))
instanceList = append(instanceList, fmt.Sprintf("%s:%s %s", value.Address.IP, value.Address.Port, value.Version))
}
addresses = strings.Join(instanceList, "\n")
if addresses != "" {
+5 -9
View File
@@ -1,15 +1,14 @@
package utils
import (
"bytes"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/tidwall/gjson"
"io/ioutil"
"isp-ctl/service"
"os"
"strings"
"github.com/integration-system/isp-kit/json"
"github.com/pkg/errors"
"github.com/tidwall/gjson"
)
func CheckPath(pathObject string) (string, error) {
@@ -47,14 +46,11 @@ func CheckChangeObject(changeObject string) (string, error) {
}
func PrintAnswer(data interface{}) {
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
encoder := json.NewEncoder(buffer)
encoder := json.NewEncoder(os.Stdout)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")
if err := encoder.Encode(data); err != nil {
PrintError(err)
} else {
service.ColorService.Print(buffer.Bytes())
}
}
+2 -2
View File
@@ -1,8 +1,8 @@
package utils
import (
"isp-ctl/cfg"
"isp-ctl/service"
"ispctl/cfg"
"ispctl/service"
)
func CreateUpdateCommonConfig(stringToChange string, configuration cfg.CommonConfig) error {
+2 -2
View File
@@ -1,8 +1,8 @@
package utils
import (
"isp-ctl/cfg"
"isp-ctl/service"
"ispctl/cfg"
"ispctl/service"
)
func CreateUpdateConfig(stringToChange string, configuration *cfg.Config) error {
-2
View File
@@ -1,2 +0,0 @@
gateHost: 127.0.0.1:9002
instanceUuid:
-6
View File
@@ -1,6 +0,0 @@
package conf
type Configuration struct {
GateHost string `yaml:"gateHost"`
InstanceUuid string `yaml:"instanceUuid"`
}
+1 -7
View File
@@ -4,13 +4,7 @@ import "fmt"
const (
hostName = "gateHost"
hostUsage = "overrides gateHost; config-service address, default '127.0.0.1:9002'"
uuidName = "instanceUuid"
uuidUsage = "overrides instanceUuid"
colorName = "color"
colorUsage = "colorize the json for outputing to screen"
hostUsage = "isp-config-service address"
unsafeName = "unsafe"
unsafeUsage = "disable checking schema for set configuration"
+12 -32
View File
@@ -4,14 +4,18 @@ import (
"strings"
"github.com/urfave/cli/v2"
"isp-ctl/service"
"ispctl/service"
)
var (
//---global---
Host = &cli.StringFlag{Name: hostName, Usage: hostUsage, Aliases: []string{"g", "configAddr"}}
Uuid = &cli.StringFlag{Name: uuidName, Usage: uuidUsage, Aliases: []string{"u"}}
Color = &cli.BoolFlag{Name: colorName, Usage: colorUsage, Aliases: []string{"c"}}
Host = &cli.StringFlag{
Name: hostName,
Usage: hostUsage,
Value: "127.0.0.1:9002",
Required: false,
Aliases: []string{"g", "configAddr"},
}
Unsafe = &cli.BoolFlag{Name: unsafeName, Usage: unsafeUsage}
//---local---
OutPrintStatus = &cli.StringFlag{Name: outPrintName, Usage: outPrintStatusUsage}
@@ -21,36 +25,12 @@ var (
func CheckGlobal(c *cli.Context) error {
var (
uuid, host string
color bool
host string
)
if c.Bool(Color.Name) != false {
color = true
}
service.ColorService.Enable = color
service.Config.UnsafeEnable = c.Bool(Unsafe.Name)
if c.String(Host.Name) != "" {
host = c.String(Host.Name)
}
if c.String(Uuid.Name) != "" {
uuid = c.String(Uuid.Name)
}
uuid = strings.Replace(uuid, "'", "", -1)
host = c.String(Host.Name)
host = strings.Replace(host, "'", "", -1)
if uuid == "" || host == "" {
if configuration, err := service.YamlService.Parse(); err != nil {
return err
} else {
if uuid == "" {
uuid = configuration.InstanceUuid
}
if host == "" {
host = configuration.GateHost
}
}
}
return service.Config.ReceiveConfiguration(host, uuid)
return service.Config.ReceiveConfiguration(host)
}
+60 -8
View File
@@ -1,17 +1,69 @@
module isp-ctl
module ispctl
go 1.14
go 1.19
require (
github.com/go-git/go-billy/v5 v5.4.1
github.com/go-git/go-git/v5 v5.7.0
github.com/integration-system/bellows v1.0.1
github.com/integration-system/isp-lib/v2 v2.8.5
github.com/integration-system/isp-kit v1.20.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.3.0
google.golang.org/genproto v0.0.0-20210510173355-fb37daa5cd7a
google.golang.org/grpc v1.37.1
gopkg.in/yaml.v2 v2.4.0
github.com/urfave/cli/v2 v2.25.5
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1
google.golang.org/grpc v1.55.0
)
require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230528122434-6f98819771a1 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/integration-system/isp-etp-go/v2 v2.1.3 // indirect
github.com/integration-system/jsonschema v1.0.1 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/mattn/go-runewidth v0.0.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/prometheus/client_golang v1.15.1 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.43.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.1.1 // indirect
github.com/tidwall/match v1.0.1 // indirect
github.com/tidwall/pretty v1.0.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.9.3 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
nhooyr.io/websocket v1.8.7 // indirect
)
+160 -826
View File
File diff suppressed because it is too large. Load diff
+6 -22
View File
@@ -2,37 +2,27 @@ package main
import (
"fmt"
"github.com/urfave/cli/v2"
"isp-ctl/command"
"isp-ctl/flag"
"isp-ctl/service"
"log"
"os"
"github.com/urfave/cli/v2"
"ispctl/command"
"ispctl/flag"
)
var version = "1.1.0"
func main() {
defineConfigurationPath()
initCommands()
}
func initCommands() {
app := cli.NewApp()
app.Usage = "isp configurations updater"
app.UsageText =
` ispctl [flag...] status
ispctl [flag...] get module_name property_path
ispctl [flag...] set module_name property_path [new_object]
ispctl [flag...] delete module_name property_path
ispctl [flag...] schema module_name [local_flag]
ispctl [flag...] common `
app.Version = version
app.Flags = []cli.Flag{
flag.Host,
flag.Uuid,
flag.Color,
flag.Unsafe,
}
app.EnableBashCompletion = true
@@ -43,6 +33,8 @@ func initCommands() {
command.Delete(),
command.Schema(),
command.CommonConfig(),
command.Merge(),
command.GitGet(),
}
app.BashComplete = func(context *cli.Context) {
for _, appCommand := range app.Commands {
@@ -55,11 +47,3 @@ func initCommands() {
log.Fatal(err)
}
}
func defineConfigurationPath() {
if os.Getenv("APP_MODE") == "dev" {
service.SetConfigurationPath("./conf/config.yml")
} else {
service.SetConfigurationPath("/etc/ispctl/config.yml")
}
}
-21
View File
@@ -1,21 +0,0 @@
package service
import (
"fmt"
"github.com/tidwall/pretty"
)
var ColorService colorService
type colorService struct {
Enable bool
}
func (c colorService) Print(json []byte) {
if c.Enable {
result := pretty.Color(json, nil)
fmt.Println(string(result))
} else {
fmt.Println(string(json))
}
}
+2 -7
View File
@@ -1,12 +1,7 @@
package service
import "isp-ctl/cfg"
import "ispctl/cfg"
var (
configClient = cfg.NewConfigClient()
configPath string
ConfigClient = cfg.NewConfigClient()
)
func SetConfigurationPath(path string) {
configPath = path
}
+23 -14
View File
@@ -3,12 +3,14 @@ package service
import (
"encoding/json"
"fmt"
"github.com/integration-system/isp-lib/v2/config/schema"
"os"
"github.com/integration-system/isp-kit/rc/schema"
"github.com/pkg/errors"
epb "google.golang.org/genproto/googleapis/rpc/errdetails"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"isp-ctl/cfg"
"ispctl/cfg"
)
var Config configService
@@ -17,12 +19,12 @@ type configService struct {
UnsafeEnable bool
}
func (c configService) ReceiveConfiguration(host, uuid string) error {
return configClient.ReceiveConfig(host, uuid)
func (c configService) ReceiveConfiguration(host string) error {
return ConfigClient.ReceiveConfig(host)
}
func (c configService) GetAvailableConfigs() ([]cfg.ModuleInfo, error) {
return configClient.GetAvailableConfigs()
return ConfigClient.GetAvailableConfigs()
}
func (c configService) GetConfigurationByModuleName(moduleName string) (*cfg.Config, error) {
@@ -30,7 +32,7 @@ func (c configService) GetConfigurationByModuleName(moduleName string) (*cfg.Con
return nil, errors.New("need module name")
}
if moduleConfiguration, err := configClient.GetConfigByModuleName(moduleName); err != nil {
if moduleConfiguration, err := ConfigClient.GetConfigByModuleName(moduleName); err != nil {
if errorStatus, ok := status.FromError(err); ok {
switch errorStatus.Code() {
case codes.NotFound:
@@ -44,7 +46,7 @@ func (c configService) GetConfigurationByModuleName(moduleName string) (*cfg.Con
}
func (c configService) GetSchemaByModuleId(moduleId string) (schema.Schema, error) {
if configSchema, err := configClient.GetSchemaByModuleId(moduleId); err != nil {
if configSchema, err := ConfigClient.GetSchemaByModuleId(moduleId); err != nil {
return nil, err
} else {
dereferenceSchema := schema.DereferenceSchema(configSchema.Schema)
@@ -62,11 +64,18 @@ func (c configService) CreateUpdateConfig(stringToChange string, configuration *
configuration.Unsafe = c.UnsafeEnable
configuration.Data = newData
if resp, err := configClient.CreateUpdateConfig(*configuration); err != nil {
return c.CreateUpdateConfigV2(configuration)
}
func (c configService) CreateUpdateConfigV2(configuration *cfg.Config) (map[string]interface{}, error) {
if resp, err := ConfigClient.CreateUpdateConfig(*configuration); err != nil {
if errorStatus, ok := status.FromError(err); ok {
switch errorStatus.Code() {
case codes.InvalidArgument:
fmt.Print("doesn't match with schema:\n")
defer func() {
os.Exit(1)
}()
for _, value := range errorStatus.Details() {
if a, ok := value.(*epb.BadRequest); ok {
for _, value := range a.FieldViolations {
@@ -86,7 +95,7 @@ func (c configService) CreateUpdateConfig(stringToChange string, configuration *
}
func (c configService) UpdateConfigAndGetLinkCommon(configuration cfg.Config) ([]string, error) {
if resp, err := configClient.CreateUpdateConfig(configuration); err != nil {
if resp, err := ConfigClient.CreateUpdateConfig(configuration); err != nil {
return nil, err
} else {
return resp.CommonConfigs, nil
@@ -104,7 +113,7 @@ func (c configService) GetCommonConfigByName(configName string) (cfg.CommonConfi
}
func (c configService) GetMapNameCommonConfig() (map[string]cfg.CommonConfig, error) {
collection, err := configClient.GetCommonConfigs([]string{})
collection, err := ConfigClient.GetCommonConfigs([]string{})
if err != nil {
return nil, err
}
@@ -124,7 +133,7 @@ func (c configService) CreateUpdateCommonConfig(stringToChange string, config cf
}
config.Data = newData
if resp, err := configClient.CreateUpdateCommonConfig(config); err != nil {
if resp, err := ConfigClient.CreateUpdateCommonConfig(config); err != nil {
return nil, err
} else {
return resp.Data, nil
@@ -132,7 +141,7 @@ func (c configService) CreateUpdateCommonConfig(stringToChange string, config cf
}
func (c configService) DeleteCommonConfig(configId string) ([]string, bool, error) {
deletedInfo, err := configClient.DeleteCommonConfig(configId)
deletedInfo, err := ConfigClient.DeleteCommonConfig(configId)
if err != nil {
return nil, false, err
}
@@ -144,7 +153,7 @@ func (c configService) DeleteCommonConfig(configId string) ([]string, bool, erro
}
func (c configService) GetLinksCommonConfig(configId string) ([]string, error) {
link, err := configClient.GetLinksCommonConfig(configId)
link, err := ConfigClient.GetLinksCommonConfig(configId)
if err != nil {
return nil, err
}
@@ -163,7 +172,7 @@ func (c configService) CompileDataWithCommonConfigs(
CommonConfigsIdList: commonConfigs,
}
var err error
data, err = configClient.CompileCommonConfigs(req)
data, err = ConfigClient.CompileCommonConfigs(req)
if err != nil {
return nil, err
} else {
-22
View File
@@ -1,22 +0,0 @@
package service
import (
"gopkg.in/yaml.v2"
"io/ioutil"
"isp-ctl/conf"
)
var YamlService yamlService
type yamlService struct{}
func (yamlService) Parse() (*conf.Configuration, error) {
resp := new(conf.Configuration)
reader, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, err
} else {
err := yaml.Unmarshal(reader, resp)
return resp, err
}
}