mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-02-16 04:25:37 +08:00
将api.yaml修改为api_admin.yaml
This commit is contained in:
@@ -155,11 +155,11 @@ func parseAPIErr(action actions.ActionWrapper, err error) (apiNodeIsStarting boo
|
||||
var apiEndpoints = []string{}
|
||||
apiConfig, apiConfigErr := configs.LoadAPIConfig()
|
||||
if apiConfigErr == nil && apiConfig != nil {
|
||||
apiEndpoints = append(apiEndpoints, apiConfig.RPC.Endpoints...)
|
||||
apiEndpoints = append(apiEndpoints, apiConfig.RPCEndpoints...)
|
||||
}
|
||||
|
||||
var isRPCConnError bool
|
||||
_, isRPCConnError = rpcerrors.HumanError(err, apiEndpoints, Tea.ConfigFile("api.yaml"))
|
||||
_, isRPCConnError = rpcerrors.HumanError(err, apiEndpoints, Tea.ConfigFile(configs.ConfigFileName))
|
||||
if isRPCConnError {
|
||||
// API节点是否正在启动
|
||||
var sock = gosock.NewTmpSock("edge-api")
|
||||
|
||||
@@ -101,14 +101,9 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
|
||||
apiNode := apiNodeResp.ApiNode
|
||||
|
||||
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||
RPC: struct {
|
||||
Endpoints []string `yaml:"endpoints"`
|
||||
DisableUpdate bool `yaml:"disableUpdate"`
|
||||
}{
|
||||
Endpoints: apiNode.AccessAddrs,
|
||||
},
|
||||
NodeId: apiNode.UniqueId,
|
||||
Secret: apiNode.Secret,
|
||||
RPCEndpoints: apiNode.AccessAddrs,
|
||||
NodeId: apiNode.UniqueId,
|
||||
Secret: apiNode.Secret,
|
||||
}, false)
|
||||
if err != nil {
|
||||
locker.Lock()
|
||||
@@ -282,14 +277,9 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
|
||||
apiNode := apiNodeResp.ApiNode
|
||||
|
||||
apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||
RPC: struct {
|
||||
Endpoints []string `yaml:"endpoints"`
|
||||
DisableUpdate bool `yaml:"disableUpdate"`
|
||||
}{
|
||||
Endpoints: apiNode.AccessAddrs,
|
||||
},
|
||||
NodeId: apiNode.UniqueId,
|
||||
Secret: apiNode.Secret,
|
||||
RPCEndpoints: apiNode.AccessAddrs,
|
||||
NodeId: apiNode.UniqueId,
|
||||
Secret: apiNode.Secret,
|
||||
}, false)
|
||||
if err != nil {
|
||||
locker.Lock()
|
||||
|
||||
@@ -35,14 +35,9 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
||||
}
|
||||
|
||||
client, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||
RPC: struct {
|
||||
Endpoints []string `yaml:"endpoints"`
|
||||
DisableUpdate bool `yaml:"disableUpdate"`
|
||||
}{
|
||||
Endpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
|
||||
},
|
||||
NodeId: params.NodeId,
|
||||
Secret: params.NodeSecret,
|
||||
RPCEndpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
|
||||
NodeId: params.NodeId,
|
||||
Secret: params.NodeSecret,
|
||||
}, false)
|
||||
if err != nil {
|
||||
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{
|
||||
RPC: struct {
|
||||
Endpoints []string `yaml:"endpoints"`
|
||||
DisableUpdate bool `yaml:"disableUpdate"`
|
||||
}{
|
||||
Endpoints: endpoints,
|
||||
},
|
||||
NodeId: adminAPIToken.NodeId,
|
||||
Secret: adminAPIToken.Secret,
|
||||
RPCEndpoints: 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 {
|
||||
this.Fail("保存configs/api.yaml失败:" + err.Error())
|
||||
this.Fail("保存configs/" + configs.ConfigFileName + "失败:" + err.Error())
|
||||
}
|
||||
|
||||
// 加载api.yaml
|
||||
// 加载api_admin.yaml
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
if err != nil {
|
||||
this.Fail("初始化RPC失败:" + err.Error())
|
||||
|
||||
@@ -42,14 +42,9 @@ func (this *ValidateApiAction) RunPost(params struct {
|
||||
Field("nodeSecret", params.NodeSecret).
|
||||
Require("请输入节点secret")
|
||||
client, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||
RPC: struct {
|
||||
Endpoints []string `yaml:"endpoints"`
|
||||
DisableUpdate bool `yaml:"disableUpdate"`
|
||||
}{
|
||||
Endpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
|
||||
},
|
||||
NodeId: params.NodeId,
|
||||
Secret: params.NodeSecret,
|
||||
RPCEndpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
|
||||
NodeId: params.NodeId,
|
||||
Secret: params.NodeSecret,
|
||||
}, false)
|
||||
if err != nil {
|
||||
this.FailField("host", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||
|
||||
@@ -43,7 +43,7 @@ func (this *UpgradeCheckAction) RunPost(params struct {
|
||||
}
|
||||
|
||||
var newAPIConfig = apiConfig.Clone()
|
||||
newAPIConfig.RPC.Endpoints = node.AccessAddrs
|
||||
newAPIConfig.RPCEndpoints = node.AccessAddrs
|
||||
rpcClient, err := rpc.NewRPCClient(newAPIConfig, false)
|
||||
if err != nil {
|
||||
this.Success()
|
||||
|
||||
@@ -36,7 +36,7 @@ func (this *UpdateHostsAction) RunPost(params struct {
|
||||
this.Fail("加载当前平台的API配置失败:" + err.Error())
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
this.Fail("检查API节点地址出错:" + err.Error())
|
||||
|
||||
@@ -43,7 +43,7 @@ func (this *ValidateAPIAction) RunPost(params struct {
|
||||
if err != nil {
|
||||
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)
|
||||
if err != nil {
|
||||
this.Fail("检查API节点地址出错:" + err.Error())
|
||||
|
||||
@@ -26,7 +26,7 @@ func (this *IndexAction) RunGet(params struct{}) {
|
||||
|
||||
config, err := configs.LoadAPIConfig()
|
||||
if err == nil {
|
||||
endpoints = config.RPC.Endpoints
|
||||
endpoints = config.RPCEndpoints
|
||||
this.Data["nodeId"] = config.NodeId
|
||||
this.Data["secret"] = config.Secret
|
||||
this.Data["canInstall"] = false
|
||||
@@ -78,7 +78,7 @@ func (this *IndexAction) RunPost(params struct {
|
||||
var config = &configs.APIConfig{}
|
||||
config.NodeId = params.NodeId
|
||||
config.Secret = params.Secret
|
||||
config.RPC.Endpoints = []string{endpoint}
|
||||
config.RPCEndpoints = []string{endpoint}
|
||||
client, err := rpc.NewRPCClient(config, false)
|
||||
if err != nil {
|
||||
this.Fail("尝试配置RPC发生错误:" + err.Error())
|
||||
@@ -124,9 +124,9 @@ func (this *IndexAction) RunPost(params struct {
|
||||
}
|
||||
config.NodeId = params.NodeId
|
||||
config.Secret = params.Secret
|
||||
config.RPC.Endpoints = endpoints
|
||||
config.RPC.DisableUpdate = true
|
||||
err = config.WriteFile(Tea.ConfigFile("api.yaml"))
|
||||
config.RPCEndpoints = endpoints
|
||||
config.RPCDisableUpdate = true
|
||||
err = config.WriteFile(Tea.ConfigFile(configs.ConfigFileName))
|
||||
if err != nil {
|
||||
this.Fail("配置保存失败:" + err.Error())
|
||||
}
|
||||
|
||||
@@ -231,14 +231,9 @@ func (this *InstallAction) RunPost(params struct {
|
||||
|
||||
// 写入API节点配置,完成安装
|
||||
var apiConfig = &configs.APIConfig{
|
||||
RPC: struct {
|
||||
Endpoints []string `yaml:"endpoints"`
|
||||
DisableUpdate bool `yaml:"disableUpdate"`
|
||||
}{
|
||||
Endpoints: []string{"http://" + configutils.QuoteIP(apiNodeMap.GetString("newHost")) + ":" + apiNodeMap.GetString("newPort")},
|
||||
},
|
||||
NodeId: resultMap.GetString("adminNodeId"),
|
||||
Secret: resultMap.GetString("adminNodeSecret"),
|
||||
RPCEndpoints: []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 {
|
||||
this.Fail("保存配置失败,原因:" + err.Error())
|
||||
}
|
||||
@@ -294,14 +289,9 @@ func (this *InstallAction) RunPost(params struct {
|
||||
} else if mode == "old" {
|
||||
// 构造RPC
|
||||
var apiConfig = &configs.APIConfig{
|
||||
RPC: struct {
|
||||
Endpoints []string `yaml:"endpoints"`
|
||||
DisableUpdate bool `yaml:"disableUpdate"`
|
||||
}{
|
||||
Endpoints: []string{apiNodeMap.GetString("oldProtocol") + "://" + configutils.QuoteIP(apiNodeMap.GetString("oldHost")) + ":" + apiNodeMap.GetString("oldPort")},
|
||||
},
|
||||
NodeId: apiNodeMap.GetString("oldNodeId"),
|
||||
Secret: apiNodeMap.GetString("oldNodeSecret"),
|
||||
RPCEndpoints: []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)
|
||||
if err != nil {
|
||||
@@ -343,7 +333,7 @@ func (this *InstallAction) RunPost(params struct {
|
||||
}
|
||||
|
||||
// 写入API节点配置,完成安装
|
||||
err = apiConfig.WriteFile(Tea.ConfigFile("api.yaml"))
|
||||
err = apiConfig.WriteFile(Tea.ConfigFile(configs.ConfigFileName))
|
||||
if err != nil {
|
||||
this.Fail("保存配置失败,原因:" + err.Error())
|
||||
}
|
||||
|
||||
@@ -102,14 +102,9 @@ func (this *ValidateApiAction) RunPost(params struct {
|
||||
Field("oldNodeSecret", params.OldNodeSecret).
|
||||
Require("请输入节点secret")
|
||||
client, err := rpc.NewRPCClient(&configs.APIConfig{
|
||||
RPC: struct {
|
||||
Endpoints []string `yaml:"endpoints"`
|
||||
DisableUpdate bool `yaml:"disableUpdate"`
|
||||
}{
|
||||
Endpoints: []string{params.OldProtocol + "://" + configutils.QuoteIP(params.OldHost) + ":" + params.OldPort},
|
||||
},
|
||||
NodeId: params.OldNodeId,
|
||||
Secret: params.OldNodeSecret,
|
||||
RPCEndpoints: []string{params.OldProtocol + "://" + configutils.QuoteIP(params.OldHost) + ":" + params.OldPort},
|
||||
NodeId: params.OldNodeId,
|
||||
Secret: params.OldNodeSecret,
|
||||
}, false)
|
||||
if err != nil {
|
||||
this.FailField("oldHost", "测试API节点时出错,请检查配置,错误信息:"+err.Error())
|
||||
|
||||
Reference in New Issue
Block a user