MSP-5014 remove common configs api
This commit is contained in:
1 parent
4bd6226cc5
commit
8889dce37c
19 files changed
+119
-836
No files matched your search
@@ -0,0 +1,87 @@
|
||||
package cfg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
cli *client.Client
|
||||
address string
|
||||
}
|
||||
|
||||
func NewConfigClient() *ConfigClient {
|
||||
return &ConfigClient{}
|
||||
}
|
||||
|
||||
func (c *ConfigClient) ReceiveConfig(address string) error {
|
||||
cli, err := client.Default()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.cli = cli
|
||||
cli.Upgrade([]string{address})
|
||||
|
||||
c.address = address
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetAvailableConfigs() ([]ModuleInfo, error) {
|
||||
response := make([]ModuleInfo, 0)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getAvailableConfigs).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getAvailableConfigs)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetConfigByModuleName(name string) (*Config, error) {
|
||||
request := &getModuleByUuidAndNameRequest{ModuleName: name}
|
||||
response := new(Config)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getConfigByModuleName).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getConfigByModuleName)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) CreateUpdateConfig(request Config) (*Config, error) {
|
||||
response := new(Config)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(createUpdateConfig).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", createUpdateConfig)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetSchemaByModuleId(moduleId string) (*ConfigSchema, error) {
|
||||
request := getSchemaByModuleIdRequest{ModuleId: moduleId}
|
||||
response := new(ConfigSchema)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getSchemaByModuleId).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getSchemaByModuleId)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
@@ -62,19 +62,3 @@ type ConfigSchema struct {
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type Deleted struct {
|
||||
Deleted bool
|
||||
Links Links
|
||||
}
|
||||
|
||||
type Links map[string][]string
|
||||
|
||||
type identityRequest struct {
|
||||
Id string
|
||||
}
|
||||
|
||||
type CompileConfigs struct {
|
||||
Data map[string]interface{}
|
||||
CommonConfigsIdList []string
|
||||
}
|
||||
+4
-9
@@ -1,13 +1,8 @@
|
||||
package cfg
|
||||
|
||||
const (
|
||||
getAvailableConfigs = "config/module/get_modules_info"
|
||||
getConfigByModuleName = "config/config/get_active_config_by_module_name"
|
||||
createUpdateConfig = "config/config/create_update_config"
|
||||
getSchemaByModuleId = "config/schema/get_by_module_id"
|
||||
getCommonConfigs = "config/common_config/get_configs"
|
||||
createUpdateCommonConfig = "config/common_config/create_update_config"
|
||||
deleteCommonConfig = "config/common_config/delete_config"
|
||||
getLinksCommonConfig = "config/common_config/get_links"
|
||||
compileCommonConfigs = "config/common_config/compile"
|
||||
getAvailableConfigs = "config/module/get_modules_info"
|
||||
getConfigByModuleName = "config/config/get_active_config_by_module_name"
|
||||
createUpdateConfig = "config/config/create_update_config"
|
||||
getSchemaByModuleId = "config/schema/get_by_module_id"
|
||||
)
|
||||
-163
@@ -1,163 +0,0 @@
|
||||
package cfg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/client"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
cli *client.Client
|
||||
address string
|
||||
}
|
||||
|
||||
func NewConfigClient() *ConfigClient {
|
||||
return &ConfigClient{}
|
||||
}
|
||||
|
||||
func (c *ConfigClient) ReceiveConfig(address string) error {
|
||||
cli, err := client.Default()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.cli = cli
|
||||
cli.Upgrade([]string{address})
|
||||
|
||||
c.address = address
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetAvailableConfigs() ([]ModuleInfo, error) {
|
||||
response := make([]ModuleInfo, 0)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getAvailableConfigs).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getAvailableConfigs)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetConfigByModuleName(name string) (*Config, error) {
|
||||
request := &getModuleByUuidAndNameRequest{ModuleName: name}
|
||||
response := new(Config)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getConfigByModuleName).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getConfigByModuleName)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) CreateUpdateConfig(request Config) (*Config, error) {
|
||||
response := new(Config)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(createUpdateConfig).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", createUpdateConfig)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetSchemaByModuleId(moduleId string) (*ConfigSchema, error) {
|
||||
request := getSchemaByModuleIdRequest{ModuleId: moduleId}
|
||||
response := new(ConfigSchema)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getSchemaByModuleId).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getSchemaByModuleId)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetCommonConfigs(req []string) ([]CommonConfig, error) {
|
||||
response := make([]CommonConfig, 0)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getCommonConfigs).
|
||||
JsonRequestBody(req).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getCommonConfigs)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) CreateUpdateCommonConfig(req CommonConfig) (*CommonConfig, error) {
|
||||
response := new(CommonConfig)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(createUpdateCommonConfig).
|
||||
JsonRequestBody(req).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", createUpdateCommonConfig)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) DeleteCommonConfig(id string) (*Deleted, error) {
|
||||
request := identityRequest{Id: id}
|
||||
response := new(Deleted)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(deleteCommonConfig).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", deleteCommonConfig)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) GetLinksCommonConfig(id string) (*Links, error) {
|
||||
request := identityRequest{Id: id}
|
||||
response := new(Links)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(getLinksCommonConfig).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(&response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", getLinksCommonConfig)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) CompileCommonConfigs(request CompileConfigs) (map[string]interface{}, error) {
|
||||
response := make(map[string]interface{})
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
defer cancel()
|
||||
err := c.cli.Invoke(compileCommonConfigs).
|
||||
JsonRequestBody(request).
|
||||
JsonResponseBody(response).
|
||||
Do(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "call %s", compileCommonConfigs)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (c *ConfigClient) errorHandler(err error) error {
|
||||
return errors.WithMessagef(err, "isp-config-service: %s", c.address)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package cfg
|
||||
|
||||
type Variable struct {
|
||||
Name string
|
||||
Description string
|
||||
Type string
|
||||
Value string
|
||||
ContainsInConfigs []LinkedConfig
|
||||
}
|
||||
|
||||
type LinkedConfig struct {
|
||||
Id string
|
||||
ModuleId string
|
||||
Name string
|
||||
}
|
||||
|
||||
type UpsertVariableRequest struct {
|
||||
Name string `validate:"required"`
|
||||
Description string `validate:"required"`
|
||||
Type string `validate:"required,oneof=SECRET TEXT"`
|
||||
Value string `validate:"required"`
|
||||
}
|
||||
|
||||
type VariableByNameRequest struct {
|
||||
Name string `validate:"required"`
|
||||
}
|
||||
Reference in new issue
Block a user