mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 21:24:33 +08:00 
			
		
		
		
	API RPC配置增加disableUpdate,可以停用自动更新API节点
This commit is contained in:
		@@ -13,6 +13,7 @@ import (
 | 
				
			|||||||
type APIConfig struct {
 | 
					type APIConfig struct {
 | 
				
			||||||
	RPC struct {
 | 
						RPC struct {
 | 
				
			||||||
		Endpoints     []string `yaml:"endpoints"`
 | 
							Endpoints     []string `yaml:"endpoints"`
 | 
				
			||||||
 | 
							DisableUpdate bool     `yaml:"disableUpdate"`
 | 
				
			||||||
	} `yaml:"rpc"`
 | 
						} `yaml:"rpc"`
 | 
				
			||||||
	NodeId string `yaml:"nodeId"`
 | 
						NodeId string `yaml:"nodeId"`
 | 
				
			||||||
	Secret string `yaml:"secret"`
 | 
						Secret string `yaml:"secret"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -58,6 +58,16 @@ func (this *SyncAPINodesTask) Loop() error {
 | 
				
			|||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						config, err := configs.LoadAPIConfig()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 是否禁止自动升级
 | 
				
			||||||
 | 
						if config.RPC.DisableUpdate {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 获取所有可用的节点
 | 
						// 获取所有可用的节点
 | 
				
			||||||
	rpcClient, err := rpc.SharedRPC()
 | 
						rpcClient, err := rpc.SharedRPC()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -68,7 +78,7 @@ func (this *SyncAPINodesTask) Loop() error {
 | 
				
			|||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	newEndpoints := []string{}
 | 
						var newEndpoints = []string{}
 | 
				
			||||||
	for _, node := range resp.ApiNodes {
 | 
						for _, node := range resp.ApiNodes {
 | 
				
			||||||
		if !node.IsOn {
 | 
							if !node.IsOn {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
@@ -77,10 +87,6 @@ func (this *SyncAPINodesTask) Loop() error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 和现有的对比
 | 
						// 和现有的对比
 | 
				
			||||||
	config, err := configs.LoadAPIConfig()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if this.isSame(newEndpoints, config.RPC.Endpoints) {
 | 
						if this.isSame(newEndpoints, config.RPC.Endpoints) {
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -103,6 +103,7 @@ func SendMessageToCluster(ctx context.Context, clusterId int64, code string, msg
 | 
				
			|||||||
			apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
 | 
								apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
 | 
				
			||||||
				RPC: struct {
 | 
									RPC: struct {
 | 
				
			||||||
					Endpoints     []string `yaml:"endpoints"`
 | 
										Endpoints     []string `yaml:"endpoints"`
 | 
				
			||||||
 | 
										DisableUpdate bool     `yaml:"disableUpdate"`
 | 
				
			||||||
				}{
 | 
									}{
 | 
				
			||||||
					Endpoints: apiNode.AccessAddrs,
 | 
										Endpoints: apiNode.AccessAddrs,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -283,6 +284,7 @@ func SendMessageToNodeIds(ctx context.Context, nodeIds []int64, code string, msg
 | 
				
			|||||||
			apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
 | 
								apiRPCClient, err := rpc.NewRPCClient(&configs.APIConfig{
 | 
				
			||||||
				RPC: struct {
 | 
									RPC: struct {
 | 
				
			||||||
					Endpoints     []string `yaml:"endpoints"`
 | 
										Endpoints     []string `yaml:"endpoints"`
 | 
				
			||||||
 | 
										DisableUpdate bool     `yaml:"disableUpdate"`
 | 
				
			||||||
				}{
 | 
									}{
 | 
				
			||||||
					Endpoints: apiNode.AccessAddrs,
 | 
										Endpoints: apiNode.AccessAddrs,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,6 +37,7 @@ func (this *UpdateHostsAction) RunPost(params struct {
 | 
				
			|||||||
	client, err := rpc.NewRPCClient(&configs.APIConfig{
 | 
						client, err := rpc.NewRPCClient(&configs.APIConfig{
 | 
				
			||||||
		RPC: struct {
 | 
							RPC: struct {
 | 
				
			||||||
			Endpoints     []string `yaml:"endpoints"`
 | 
								Endpoints     []string `yaml:"endpoints"`
 | 
				
			||||||
 | 
								DisableUpdate bool     `yaml:"disableUpdate"`
 | 
				
			||||||
		}{
 | 
							}{
 | 
				
			||||||
			Endpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
 | 
								Endpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
@@ -168,6 +169,7 @@ func (this *UpdateHostsAction) RunPost(params struct {
 | 
				
			|||||||
	var apiConfig = &configs.APIConfig{
 | 
						var apiConfig = &configs.APIConfig{
 | 
				
			||||||
		RPC: struct {
 | 
							RPC: struct {
 | 
				
			||||||
			Endpoints     []string `yaml:"endpoints"`
 | 
								Endpoints     []string `yaml:"endpoints"`
 | 
				
			||||||
 | 
								DisableUpdate bool     `yaml:"disableUpdate"`
 | 
				
			||||||
		}{
 | 
							}{
 | 
				
			||||||
			Endpoints: endpoints,
 | 
								Endpoints: endpoints,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,6 +44,7 @@ func (this *ValidateApiAction) RunPost(params struct {
 | 
				
			|||||||
	client, err := rpc.NewRPCClient(&configs.APIConfig{
 | 
						client, err := rpc.NewRPCClient(&configs.APIConfig{
 | 
				
			||||||
		RPC: struct {
 | 
							RPC: struct {
 | 
				
			||||||
			Endpoints     []string `yaml:"endpoints"`
 | 
								Endpoints     []string `yaml:"endpoints"`
 | 
				
			||||||
 | 
								DisableUpdate bool     `yaml:"disableUpdate"`
 | 
				
			||||||
		}{
 | 
							}{
 | 
				
			||||||
			Endpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
 | 
								Endpoints: []string{params.Protocol + "://" + configutils.QuoteIP(params.Host) + ":" + params.Port},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -224,6 +224,7 @@ func (this *InstallAction) RunPost(params struct {
 | 
				
			|||||||
		apiConfig := &configs.APIConfig{
 | 
							apiConfig := &configs.APIConfig{
 | 
				
			||||||
			RPC: struct {
 | 
								RPC: struct {
 | 
				
			||||||
				Endpoints     []string `yaml:"endpoints"`
 | 
									Endpoints     []string `yaml:"endpoints"`
 | 
				
			||||||
 | 
									DisableUpdate bool     `yaml:"disableUpdate"`
 | 
				
			||||||
			}{
 | 
								}{
 | 
				
			||||||
				Endpoints: []string{"http://" + configutils.QuoteIP(apiNodeMap.GetString("newHost")) + ":" + apiNodeMap.GetString("newPort")},
 | 
									Endpoints: []string{"http://" + configutils.QuoteIP(apiNodeMap.GetString("newHost")) + ":" + apiNodeMap.GetString("newPort")},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
@@ -286,6 +287,7 @@ func (this *InstallAction) RunPost(params struct {
 | 
				
			|||||||
		apiConfig := &configs.APIConfig{
 | 
							apiConfig := &configs.APIConfig{
 | 
				
			||||||
			RPC: struct {
 | 
								RPC: struct {
 | 
				
			||||||
				Endpoints     []string `yaml:"endpoints"`
 | 
									Endpoints     []string `yaml:"endpoints"`
 | 
				
			||||||
 | 
									DisableUpdate bool     `yaml:"disableUpdate"`
 | 
				
			||||||
			}{
 | 
								}{
 | 
				
			||||||
				Endpoints: []string{apiNodeMap.GetString("oldProtocol") + "://" + configutils.QuoteIP(apiNodeMap.GetString("oldHost")) + ":" + apiNodeMap.GetString("oldPort")},
 | 
									Endpoints: []string{apiNodeMap.GetString("oldProtocol") + "://" + configutils.QuoteIP(apiNodeMap.GetString("oldHost")) + ":" + apiNodeMap.GetString("oldPort")},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,6 +86,7 @@ func (this *ValidateApiAction) RunPost(params struct {
 | 
				
			|||||||
	client, err := rpc.NewRPCClient(&configs.APIConfig{
 | 
						client, err := rpc.NewRPCClient(&configs.APIConfig{
 | 
				
			||||||
		RPC: struct {
 | 
							RPC: struct {
 | 
				
			||||||
			Endpoints     []string `yaml:"endpoints"`
 | 
								Endpoints     []string `yaml:"endpoints"`
 | 
				
			||||||
 | 
								DisableUpdate bool     `yaml:"disableUpdate"`
 | 
				
			||||||
		}{
 | 
							}{
 | 
				
			||||||
			Endpoints: []string{params.OldProtocol + "://" + configutils.QuoteIP(params.OldHost) + ":" + params.OldPort},
 | 
								Endpoints: []string{params.OldProtocol + "://" + configutils.QuoteIP(params.OldHost) + ":" + params.OldPort},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user