strategyPlugin.go 3.2 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5
package strategy

import (
	"strings"

黄孟柱 已提交
6 7
	"github.com/eolinker/goku-api-gateway/server/dao"
	console_mysql "github.com/eolinker/goku-api-gateway/server/dao/console-mysql"
E
eoLinker API Management 已提交
8 9
)

Y
Your Name 已提交
10
//AddPluginToStrategy 新增策略组插件
E
eoLinker API Management 已提交
11 12 13 14 15 16 17 18 19 20
func AddPluginToStrategy(pluginName, config, strategyID string) (bool, interface{}, error) {
	tableName := "goku_conn_plugin_strategy"
	flag, result, err := console_mysql.AddPluginToStrategy(pluginName, config, strategyID)
	if flag {
		dao.UpdateTable(tableName)
		console_mysql.UpdateStrategyTagByPluginName(strategyID, pluginName)
	}
	return flag, result, err
}

Y
Your Name 已提交
21
//EditStrategyPluginConfig 新增策略组插件配置
E
eoLinker API Management 已提交
22 23 24 25 26 27 28 29 30 31
func EditStrategyPluginConfig(pluginName, config, strategyID string) (bool, string, error) {
	flag, result, err := console_mysql.EditStrategyPluginConfig(pluginName, config, strategyID)
	tableName := "goku_conn_plugin_strategy"
	if flag {
		dao.UpdateTable(tableName)
		console_mysql.UpdateStrategyTagByPluginName(strategyID, pluginName)
	}
	return flag, result, err
}

Y
Your Name 已提交
32
//BatchEditStrategyPluginStatus 批量修改策略组插件状态
E
eoLinker API Management 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
func BatchEditStrategyPluginStatus(connIDList, strategyID string, pluginStatus int) (bool, string, error) {
	plugins := []string{}
	flag, _ := console_mysql.CheckStrategyPluginIsExistByConnIDList(connIDList, "goku-rate_limiting")
	if flag {
		plugins = append(plugins, "goku-rate_limiting")
	}
	flag, _ = console_mysql.CheckStrategyPluginIsExistByConnIDList(connIDList, "goku-replay_attack_defender")
	if flag {
		plugins = append(plugins, "goku-replay_attack_defender")
	}

	tableName := "goku_conn_plugin_strategy"
	flag, result, err := console_mysql.BatchEditStrategyPluginStatus(connIDList, strategyID, pluginStatus)
	if flag {
		dao.UpdateTable(tableName)
		console_mysql.UpdateStrategyTagByPluginName(strategyID, strings.Join(plugins, ","))
	}
	return flag, result, err
}

Y
Your Name 已提交
53
//BatchDeleteStrategyPlugin 批量删除策略组插件
E
eoLinker API Management 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67
func BatchDeleteStrategyPlugin(connIDList, strategyID string) (bool, string, error) {
	tableName := "goku_conn_plugin_strategy"
	flag, result, err := console_mysql.BatchDeleteStrategyPlugin(connIDList, strategyID)
	if flag {
		dao.UpdateTable(tableName)
	}
	return flag, result, err
}

// GetStrategyPluginList 获取策略插件列表
func GetStrategyPluginList(strategyID, keyword string, condition int) (bool, []map[string]interface{}, error) {
	return console_mysql.GetStrategyPluginList(strategyID, keyword, condition)
}

Y
Your Name 已提交
68
//GetStrategyPluginConfig 通过策略组ID获取配置信息
E
eoLinker API Management 已提交
69 70 71 72
func GetStrategyPluginConfig(strategyID, pluginName string) (bool, string, error) {
	return console_mysql.GetStrategyPluginConfig(strategyID, pluginName)
}

Y
Your Name 已提交
73
//CheckPluginIsExistInStrategy 检查策略组是否绑定插件
E
eoLinker API Management 已提交
74 75 76 77
func CheckPluginIsExistInStrategy(strategyID, pluginName string) (bool, error) {
	return console_mysql.CheckPluginIsExistInStrategy(strategyID, pluginName)
}

Y
Your Name 已提交
78
//GetStrategyPluginStatus 检查策略组插件是否开启
E
eoLinker API Management 已提交
79 80 81 82
func GetStrategyPluginStatus(strategyID, pluginName string) (bool, error) {
	return console_mysql.GetStrategyPluginStatus(strategyID, pluginName)
}

Y
Your Name 已提交
83
//GetConnIDFromStrategyPlugin 获取Connid
E
eoLinker API Management 已提交
84 85 86
func GetConnIDFromStrategyPlugin(pluginName, strategyID string) (bool, int, error) {
	return console_mysql.GetConnIDFromStrategyPlugin(pluginName, strategyID)
}