mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-04 05:00:25 +08:00
将api.yaml修改为api_admin.yaml
This commit is contained in:
1
build/configs/.gitignore
vendored
1
build/configs/.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
api.yaml
|
api.yaml
|
||||||
|
api_admin.yaml
|
||||||
server.yaml
|
server.yaml
|
||||||
api_db.yaml
|
api_db.yaml
|
||||||
*.pem
|
*.pem
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
rpc:
|
|
||||||
endpoints: [ "http://127.0.0.1:8003" ]
|
|
||||||
nodeId: ""
|
|
||||||
secret: ""
|
|
||||||
3
build/configs/api_admin.template.yaml
Normal file
3
build/configs/api_admin.template.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
rpc.endpoints: [ "http://127.0.0.1:8003" ]
|
||||||
|
nodeId: ""
|
||||||
|
secret: ""
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package configs
|
package configs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@@ -8,12 +9,19 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const ConfigFileName = "api_admin.yaml"
|
||||||
|
const oldConfigFileName = "api.yaml"
|
||||||
|
|
||||||
// APIConfig API配置
|
// APIConfig API配置
|
||||||
type APIConfig struct {
|
type APIConfig struct {
|
||||||
RPC struct {
|
OldRPC struct {
|
||||||
Endpoints []string `yaml:"endpoints"`
|
Endpoints []string `yaml:"endpoints"`
|
||||||
DisableUpdate bool `yaml:"disableUpdate"`
|
DisableUpdate bool `yaml:"disableUpdate"`
|
||||||
} `yaml:"rpc"`
|
} `yaml:"rpc"`
|
||||||
|
|
||||||
|
RPCEndpoints []string `yaml:"rpc.endpoints" json:"rpc.endpoints"`
|
||||||
|
RPCDisableUpdate bool `yaml:"rpc.disableUpdate" json:"rpc.disableUpdate"`
|
||||||
|
|
||||||
NodeId string `yaml:"nodeId"`
|
NodeId string `yaml:"nodeId"`
|
||||||
Secret string `yaml:"secret"`
|
Secret string `yaml:"secret"`
|
||||||
}
|
}
|
||||||
@@ -21,21 +29,22 @@ type APIConfig struct {
|
|||||||
// LoadAPIConfig 加载API配置
|
// LoadAPIConfig 加载API配置
|
||||||
func LoadAPIConfig() (*APIConfig, error) {
|
func LoadAPIConfig() (*APIConfig, error) {
|
||||||
// 候选文件
|
// 候选文件
|
||||||
var localFile = Tea.ConfigFile("api.yaml")
|
var realFile = Tea.ConfigFile(ConfigFileName)
|
||||||
|
var oldRealFile = Tea.ConfigFile(oldConfigFileName)
|
||||||
var isFromLocal = false
|
var isFromLocal = false
|
||||||
var paths = []string{localFile}
|
var paths = []string{realFile, oldRealFile}
|
||||||
homeDir, homeErr := os.UserHomeDir()
|
homeDir, homeErr := os.UserHomeDir()
|
||||||
if homeErr == nil {
|
if homeErr == nil {
|
||||||
paths = append(paths, homeDir+"/."+teaconst.ProcessName+"/api.yaml")
|
paths = append(paths, homeDir+"/."+teaconst.ProcessName+"/"+ConfigFileName)
|
||||||
}
|
}
|
||||||
paths = append(paths, "/etc/"+teaconst.ProcessName+"/api.yaml")
|
paths = append(paths, "/etc/"+teaconst.ProcessName+"/"+ConfigFileName)
|
||||||
|
|
||||||
var data []byte
|
var data []byte
|
||||||
var err error
|
var err error
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
data, err = os.ReadFile(path)
|
data, err = os.ReadFile(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if path == localFile {
|
if path == realFile || path == oldRealFile {
|
||||||
isFromLocal = true
|
isFromLocal = true
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -51,9 +60,14 @@ func LoadAPIConfig() (*APIConfig, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = config.Init()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("init error: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
if !isFromLocal {
|
if !isFromLocal {
|
||||||
// 恢复文件
|
// 恢复文件
|
||||||
_ = os.WriteFile(localFile, data, 0666)
|
_ = os.WriteFile(realFile, data, 0666)
|
||||||
}
|
}
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
@@ -61,9 +75,9 @@ func LoadAPIConfig() (*APIConfig, error) {
|
|||||||
|
|
||||||
// ResetAPIConfig 重置配置
|
// ResetAPIConfig 重置配置
|
||||||
func ResetAPIConfig() error {
|
func ResetAPIConfig() error {
|
||||||
var filename = "api.yaml"
|
var filename = ConfigFileName
|
||||||
|
|
||||||
// 重置 configs/api.yaml
|
// 重置 configs/api_admin.yaml
|
||||||
{
|
{
|
||||||
var configFile = Tea.ConfigFile(filename)
|
var configFile = Tea.ConfigFile(filename)
|
||||||
stat, err := os.Stat(configFile)
|
stat, err := os.Stat(configFile)
|
||||||
@@ -75,7 +89,7 @@ func ResetAPIConfig() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重置 ~/.edge-admin/api.yaml
|
// 重置 ~/.edge-admin/api_admin.yaml
|
||||||
homeDir, homeErr := os.UserHomeDir()
|
homeDir, homeErr := os.UserHomeDir()
|
||||||
if homeErr == nil {
|
if homeErr == nil {
|
||||||
var configFile = homeDir + "/." + teaconst.ProcessName + "/" + filename
|
var configFile = homeDir + "/." + teaconst.ProcessName + "/" + filename
|
||||||
@@ -88,7 +102,7 @@ func ResetAPIConfig() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重置 /etc/edge-admin/api.yaml
|
// 重置 /etc/edge-admin/api_admin.yaml
|
||||||
{
|
{
|
||||||
var configFile = "/etc/" + teaconst.ProcessName + "/" + filename
|
var configFile = "/etc/" + teaconst.ProcessName + "/" + filename
|
||||||
stat, err := os.Stat(configFile)
|
stat, err := os.Stat(configFile)
|
||||||
@@ -103,6 +117,22 @@ func ResetAPIConfig() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsNewInstalled() bool {
|
||||||
|
homeDir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, filename := range []string{ConfigFileName, oldConfigFileName} {
|
||||||
|
_, err = os.Stat(homeDir + "/." + teaconst.ProcessName + "/" + filename)
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// WriteFile 写入API配置
|
// WriteFile 写入API配置
|
||||||
func (this *APIConfig) WriteFile(path string) error {
|
func (this *APIConfig) WriteFile(path string) error {
|
||||||
data, err := yaml.Marshal(this)
|
data, err := yaml.Marshal(this)
|
||||||
@@ -159,11 +189,27 @@ func (this *APIConfig) WriteFile(path string) error {
|
|||||||
// Clone 克隆当前配置
|
// Clone 克隆当前配置
|
||||||
func (this *APIConfig) Clone() *APIConfig {
|
func (this *APIConfig) Clone() *APIConfig {
|
||||||
return &APIConfig{
|
return &APIConfig{
|
||||||
RPC: struct {
|
|
||||||
Endpoints []string `yaml:"endpoints"`
|
|
||||||
DisableUpdate bool `yaml:"disableUpdate"`
|
|
||||||
}{},
|
|
||||||
NodeId: this.NodeId,
|
NodeId: this.NodeId,
|
||||||
Secret: this.Secret,
|
Secret: this.Secret,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *APIConfig) Init() error {
|
||||||
|
// compatible with old
|
||||||
|
if len(this.RPCEndpoints) == 0 && len(this.OldRPC.Endpoints) > 0 {
|
||||||
|
this.RPCEndpoints = this.OldRPC.Endpoints
|
||||||
|
this.RPCDisableUpdate = this.OldRPC.DisableUpdate
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(this.RPCEndpoints) == 0 {
|
||||||
|
return errors.New("no valid 'rpc.endpoints'")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(this.NodeId) == 0 {
|
||||||
|
return errors.New("'nodeId' required")
|
||||||
|
}
|
||||||
|
if len(this.Secret) == 0 {
|
||||||
|
return errors.New("'secret' required")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ func (this *AdminNode) addPortsToFirewall() {
|
|||||||
|
|
||||||
// 启动API节点
|
// 启动API节点
|
||||||
func (this *AdminNode) startAPINode() {
|
func (this *AdminNode) startAPINode() {
|
||||||
configPath := Tea.Root + "/edge-api/configs/api.yaml"
|
var configPath = Tea.Root + "/edge-api/configs/api.yaml"
|
||||||
_, err := os.Stat(configPath)
|
_, err := os.Stat(configPath)
|
||||||
canStart := false
|
canStart := false
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -523,7 +523,7 @@ func (this *RPCClient) init() error {
|
|||||||
|
|
||||||
// 重新连接
|
// 重新连接
|
||||||
var conns = []*grpc.ClientConn{}
|
var conns = []*grpc.ClientConn{}
|
||||||
for _, endpoint := range this.apiConfig.RPC.Endpoints {
|
for _, endpoint := range this.apiConfig.RPCEndpoints {
|
||||||
u, err := url.Parse(endpoint)
|
u, err := url.Parse(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("parse endpoint failed: %w", err)
|
return fmt.Errorf("parse endpoint failed: %w", err)
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package setup
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
"github.com/TeaOSLab/EdgeAdmin/internal/configs"
|
||||||
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
|
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var isConfigured bool
|
var isConfigured bool
|
||||||
@@ -21,10 +19,5 @@ func IsConfigured() bool {
|
|||||||
|
|
||||||
// IsNewInstalled IsNew 检查是否新安装
|
// IsNewInstalled IsNew 检查是否新安装
|
||||||
func IsNewInstalled() bool {
|
func IsNewInstalled() bool {
|
||||||
homeDir, err := os.UserHomeDir()
|
return configs.IsNewInstalled()
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
_, err = os.Stat(homeDir + "/." + teaconst.ProcessName + "/api.yaml")
|
|
||||||
return err != nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func (this *SyncAPINodesTask) Loop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 是否禁止自动升级
|
// 是否禁止自动升级
|
||||||
if config.RPC.DisableUpdate {
|
if config.RPCDisableUpdate {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ func (this *SyncAPINodesTask) Loop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 和现有的对比
|
// 和现有的对比
|
||||||
if this.isSame(newEndpoints, config.RPC.Endpoints) {
|
if this.isSame(newEndpoints, config.RPCEndpoints) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,14 +99,14 @@ func (this *SyncAPINodesTask) Loop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 修改RPC对象配置
|
// 修改RPC对象配置
|
||||||
config.RPC.Endpoints = newEndpoints
|
config.RPCEndpoints = newEndpoints
|
||||||
err = rpcClient.UpdateConfig(config)
|
err = rpcClient.UpdateConfig(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存到文件
|
// 保存到文件
|
||||||
err = config.WriteFile(Tea.ConfigFile("api.yaml"))
|
err = config.WriteFile(Tea.ConfigFile(configs.ConfigFileName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func (this *Upgrader) Upgrade() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var newAPIConfig = apiConfig.Clone()
|
var newAPIConfig = apiConfig.Clone()
|
||||||
newAPIConfig.RPC.Endpoints = apiNode.AccessAddrs
|
newAPIConfig.RPCEndpoints = apiNode.AccessAddrs
|
||||||
|
|
||||||
rpcClient, err := rpc.NewRPCClient(newAPIConfig, false)
|
rpcClient, err := rpc.NewRPCClient(newAPIConfig, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -155,11 +155,11 @@ func parseAPIErr(action actions.ActionWrapper, err error) (apiNodeIsStarting boo
|
|||||||
var apiEndpoints = []string{}
|
var apiEndpoints = []string{}
|
||||||
apiConfig, apiConfigErr := configs.LoadAPIConfig()
|
apiConfig, apiConfigErr := configs.LoadAPIConfig()
|
||||||
if apiConfigErr == nil && apiConfig != nil {
|
if apiConfigErr == nil && apiConfig != nil {
|
||||||
apiEndpoints = append(apiEndpoints, apiConfig.RPC.Endpoints...)
|
apiEndpoints = append(apiEndpoints, apiConfig.RPCEndpoints...)
|
||||||
}
|
}
|
||||||
|
|
||||||
var isRPCConnError bool
|
var isRPCConnError bool
|
||||||
_, isRPCConnError = rpcerrors.HumanError(err, apiEndpoints, Tea.ConfigFile("api.yaml"))
|
_, isRPCConnError = rpcerrors.HumanError(err, apiEndpoints, Tea.ConfigFile(configs.ConfigFileName))
|
||||||
if isRPCConnError {
|
if isRPCConnError {
|
||||||
// API节点是否正在启动
|
// API节点是否正在启动
|
||||||
var sock = gosock.NewTmpSock("edge-api")
|
var sock = gosock.NewTmpSock("edge-api")
|
||||||
|
|||||||
@@ -101,14 +101,9 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
|||||||
apiNode := apiNodeResp.ApiNode
|
apiNode := apiNodeResp.ApiNode
|
||||||
|
|
||||||
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPCEndpoints: apiNode.AccessAddrs,
|
||||||
Endpoints []string `yaml:"endpoints"`
|
NodeId: apiNode.UniqueId,
|
||||||
DisableUpdate bool `yaml:"disableUpdate"`
|
Secret: apiNode.Secret,
|
||||||
}{
|
|
||||||
Endpoints: apiNode.AccessAddrs,
|
|
||||||
},
|
|
||||||
NodeId: apiNode.UniqueId,
|
|
||||||
Secret: apiNode.Secret,
|
|
||||||
}, false)
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
@@ -282,14 +277,9 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
|||||||
apiNode := apiNodeResp.ApiNode
|
apiNode := apiNodeResp.ApiNode
|
||||||
|
|
||||||
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPCEndpoints: apiNode.AccessAddrs,
|
||||||
Endpoints []string `yaml:"endpoints"`
|
NodeId: apiNode.UniqueId,
|
||||||
DisableUpdate bool `yaml:"disableUpdate"`
|
Secret: apiNode.Secret,
|
||||||
}{
|
|
||||||
Endpoints: apiNode.AccessAddrs,
|
|
||||||
},
|
|
||||||
NodeId: apiNode.UniqueId,
|
|
||||||
Secret: apiNode.Secret,
|
|
||||||
}, false)
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
locker.Lock()
|
locker.Lock()
|
||||||
|
|||||||
@@ -35,14 +35,9 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client, err := rpc.NewRPCClient(&configs.APIConfig{
|
client, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPCEndpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
|
||||||
Endpoints []string `yaml:"endpoints"`
|
NodeId: params.NodeId,
|
||||||
DisableUpdate bool `yaml:"disableUpdate"`
|
Secret: params.NodeSecret,
|
||||||
}{
|
|
||||||
Endpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
|
|
||||||
},
|
|
||||||
NodeId: params.NodeId,
|
|
||||||
Secret: params.NodeSecret,
|
|
||||||
}, false)
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||||
@@ -165,23 +160,18 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改api.yaml
|
// 修改api_admin.yaml
|
||||||
var apiConfig = &configs.APIConfig{
|
var apiConfig = &configs.APIConfig{
|
||||||
RPC: struct {
|
RPCEndpoints: endpoints,
|
||||||
Endpoints []string `yaml:"endpoints"`
|
NodeId: adminAPIToken.NodeId,
|
||||||
DisableUpdate bool `yaml:"disableUpdate"`
|
Secret: adminAPIToken.Secret,
|
||||||
}{
|
|
||||||
Endpoints: endpoints,
|
|
||||||
},
|
|
||||||
NodeId: adminAPIToken.NodeId,
|
|
||||||
Secret: adminAPIToken.Secret,
|
|
||||||
}
|
}
|
||||||
err = apiConfig.WriteFile(Tea.Root + "/configs/api.yaml")
|
err = apiConfig.WriteFile(Tea.Root + "/configs/" + configs.ConfigFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("保存configs/api.yaml失败:" + err.Error())
|
this.Fail("保存configs/" + configs.ConfigFileName + "失败:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载api.yaml
|
// 加载api_admin.yaml
|
||||||
rpcClient, err := rpc.SharedRPC()
|
rpcClient, err := rpc.SharedRPC()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("初始化RPC失败:" + err.Error())
|
this.Fail("初始化RPC失败:" + err.Error())
|
||||||
|
|||||||
@@ -42,14 +42,9 @@ func (this *ValidateApiAction) RunPost(params struct {
|
|||||||
Field("nodeSecret", params.NodeSecret).
|
Field("nodeSecret", params.NodeSecret).
|
||||||
Require("请输入节点secret")
|
Require("请输入节点secret")
|
||||||
client, err := rpc.NewRPCClient(&configs.APIConfig{
|
client, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPCEndpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
|
||||||
Endpoints []string `yaml:"endpoints"`
|
NodeId: params.NodeId,
|
||||||
DisableUpdate bool `yaml:"disableUpdate"`
|
Secret: params.NodeSecret,
|
||||||
}{
|
|
||||||
Endpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
|
|
||||||
},
|
|
||||||
NodeId: params.NodeId,
|
|
||||||
Secret: params.NodeSecret,
|
|
||||||
}, false)
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func (this *UpgradeCheckAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var newAPIConfig = apiConfig.Clone()
|
var newAPIConfig = apiConfig.Clone()
|
||||||
newAPIConfig.RPC.Endpoints = node.AccessAddrs
|
newAPIConfig.RPCEndpoints = node.AccessAddrs
|
||||||
rpcClient, err := rpc.NewRPCClient(newAPIConfig, false)
|
rpcClient, err := rpc.NewRPCClient(newAPIConfig, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Success()
|
this.Success()
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
|||||||
this.Fail("加载当前平台的API配置失败:" + err.Error())
|
this.Fail("加载当前平台的API配置失败:" + err.Error())
|
||||||
}
|
}
|
||||||
var apiURL = params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port
|
var apiURL = params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port
|
||||||
config.RPC.Endpoints = []string{apiURL}
|
config.RPCEndpoints = []string{apiURL}
|
||||||
client, err := rpc.NewRPCClient(config, false)
|
client, err := rpc.NewRPCClient(config, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("检查API节点地址出错:" + err.Error())
|
this.Fail("检查API节点地址出错:" + err.Error())
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func (this *ValidateAPIAction) RunPost(params struct {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("加载当前平台的API配置失败:" + err.Error())
|
this.Fail("加载当前平台的API配置失败:" + err.Error())
|
||||||
}
|
}
|
||||||
config.RPC.Endpoints = []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port}
|
config.RPCEndpoints = []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port}
|
||||||
client, err := rpc.NewRPCClient(config, false)
|
client, err := rpc.NewRPCClient(config, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("检查API节点地址出错:" + err.Error())
|
this.Fail("检查API节点地址出错:" + err.Error())
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func (this *IndexAction) RunGet(params struct{}) {
|
|||||||
|
|
||||||
config, err := configs.LoadAPIConfig()
|
config, err := configs.LoadAPIConfig()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
endpoints = config.RPC.Endpoints
|
endpoints = config.RPCEndpoints
|
||||||
this.Data["nodeId"] = config.NodeId
|
this.Data["nodeId"] = config.NodeId
|
||||||
this.Data["secret"] = config.Secret
|
this.Data["secret"] = config.Secret
|
||||||
this.Data["canInstall"] = false
|
this.Data["canInstall"] = false
|
||||||
@@ -78,7 +78,7 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
var config = &configs.APIConfig{}
|
var config = &configs.APIConfig{}
|
||||||
config.NodeId = params.NodeId
|
config.NodeId = params.NodeId
|
||||||
config.Secret = params.Secret
|
config.Secret = params.Secret
|
||||||
config.RPC.Endpoints = []string{endpoint}
|
config.RPCEndpoints = []string{endpoint}
|
||||||
client, err := rpc.NewRPCClient(config, false)
|
client, err := rpc.NewRPCClient(config, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("尝试配置RPC发生错误:" + err.Error())
|
this.Fail("尝试配置RPC发生错误:" + err.Error())
|
||||||
@@ -124,9 +124,9 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
config.NodeId = params.NodeId
|
config.NodeId = params.NodeId
|
||||||
config.Secret = params.Secret
|
config.Secret = params.Secret
|
||||||
config.RPC.Endpoints = endpoints
|
config.RPCEndpoints = endpoints
|
||||||
config.RPC.DisableUpdate = true
|
config.RPCDisableUpdate = true
|
||||||
err = config.WriteFile(Tea.ConfigFile("api.yaml"))
|
err = config.WriteFile(Tea.ConfigFile(configs.ConfigFileName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("配置保存失败:" + err.Error())
|
this.Fail("配置保存失败:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,14 +231,9 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
|
|
||||||
// 写入API节点配置,完成安装
|
// 写入API节点配置,完成安装
|
||||||
var apiConfig = &configs.APIConfig{
|
var apiConfig = &configs.APIConfig{
|
||||||
RPC: struct {
|
RPCEndpoints: []string{"http://" + configutils.QuoteIP(apiNodeMap.GetString("newHost")) + ":" + apiNodeMap.GetString("newPort")},
|
||||||
Endpoints []string `yaml:"endpoints"`
|
NodeId: resultMap.GetString("adminNodeId"),
|
||||||
DisableUpdate bool `yaml:"disableUpdate"`
|
Secret: resultMap.GetString("adminNodeSecret"),
|
||||||
}{
|
|
||||||
Endpoints: []string{"http://" + configutils.QuoteIP(apiNodeMap.GetString("newHost")) + ":" + apiNodeMap.GetString("newPort")},
|
|
||||||
},
|
|
||||||
NodeId: resultMap.GetString("adminNodeId"),
|
|
||||||
Secret: resultMap.GetString("adminNodeSecret"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置管理员
|
// 设置管理员
|
||||||
@@ -285,7 +280,7 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = apiConfig.WriteFile(Tea.ConfigFile("api.yaml"))
|
err = apiConfig.WriteFile(Tea.ConfigFile(configs.ConfigFileName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("保存配置失败,原因:" + err.Error())
|
this.Fail("保存配置失败,原因:" + err.Error())
|
||||||
}
|
}
|
||||||
@@ -294,14 +289,9 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
} else if mode == "old" {
|
} else if mode == "old" {
|
||||||
// 构造RPC
|
// 构造RPC
|
||||||
var apiConfig = &configs.APIConfig{
|
var apiConfig = &configs.APIConfig{
|
||||||
RPC: struct {
|
RPCEndpoints: []string{apiNodeMap.GetString("oldProtocol") + "://" + configutils.QuoteIP(apiNodeMap.GetString("oldHost")) + ":" + apiNodeMap.GetString("oldPort")},
|
||||||
Endpoints []string `yaml:"endpoints"`
|
NodeId: apiNodeMap.GetString("oldNodeId"),
|
||||||
DisableUpdate bool `yaml:"disableUpdate"`
|
Secret: apiNodeMap.GetString("oldNodeSecret"),
|
||||||
}{
|
|
||||||
Endpoints: []string{apiNodeMap.GetString("oldProtocol") + "://" + configutils.QuoteIP(apiNodeMap.GetString("oldHost")) + ":" + apiNodeMap.GetString("oldPort")},
|
|
||||||
},
|
|
||||||
NodeId: apiNodeMap.GetString("oldNodeId"),
|
|
||||||
Secret: apiNodeMap.GetString("oldNodeSecret"),
|
|
||||||
}
|
}
|
||||||
client, err := rpc.NewRPCClient(apiConfig, false)
|
client, err := rpc.NewRPCClient(apiConfig, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -343,7 +333,7 @@ func (this *InstallAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 写入API节点配置,完成安装
|
// 写入API节点配置,完成安装
|
||||||
err = apiConfig.WriteFile(Tea.ConfigFile("api.yaml"))
|
err = apiConfig.WriteFile(Tea.ConfigFile(configs.ConfigFileName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.Fail("保存配置失败,原因:" + err.Error())
|
this.Fail("保存配置失败,原因:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,14 +102,9 @@ func (this *ValidateApiAction) RunPost(params struct {
|
|||||||
Field("oldNodeSecret", params.OldNodeSecret).
|
Field("oldNodeSecret", params.OldNodeSecret).
|
||||||
Require("请输入节点secret")
|
Require("请输入节点secret")
|
||||||
client, err := rpc.NewRPCClient(&configs.APIConfig{
|
client, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||||
RPC: struct {
|
RPCEndpoints: []string{params.OldProtocol + "://" + configutils.QuoteIP(params.OldHost) + ":" + params.OldPort},
|
||||||
Endpoints []string `yaml:"endpoints"`
|
NodeId: params.OldNodeId,
|
||||||
DisableUpdate bool `yaml:"disableUpdate"`
|
Secret: params.OldNodeSecret,
|
||||||
}{
|
|
||||||
Endpoints: []string{params.OldProtocol + "://" + configutils.QuoteIP(params.OldHost) + ":" + params.OldPort},
|
|
||||||
},
|
|
||||||
NodeId: params.OldNodeId,
|
|
||||||
Secret: params.OldNodeSecret,
|
|
||||||
}, false)
|
}, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.FailField("oldHost", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
this.FailField("oldHost", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||||
|
|||||||
Reference in New Issue
Block a user