diff --git a/bfe_config/bfe_conf/conf_basic.go b/bfe_config/bfe_conf/conf_basic.go index 6751342a..04bc39bc 100644 --- a/bfe_config/bfe_conf/conf_basic.go +++ b/bfe_config/bfe_conf/conf_basic.go @@ -72,9 +72,6 @@ type ConfigBasic struct { DebugBfeRoute bool // whether open bferoute debug log DebugBal bool // whether open bal debug log DebugHealthCheck bool // whether open health check debug log - - // wasm plugin path - BfeWasmPath string //root path of wasm plugins } func (cfg *ConfigBasic) SetDefaultConf() { @@ -102,8 +99,6 @@ func (cfg *ConfigBasic) SetDefaultConf() { cfg.NameConf = "server_data_conf/name_conf.data" cfg.MonitorInterval = 20 - - cfg.BfeWasmPath = "plugin" } func (cfg *ConfigBasic) Check(confRoot string) error { diff --git a/bfe_modules/bfe_modules.go b/bfe_modules/bfe_modules.go index 2b6717e3..56017ca5 100644 --- a/bfe_modules/bfe_modules.go +++ b/bfe_modules/bfe_modules.go @@ -44,7 +44,7 @@ import ( "github.com/bfenetworks/bfe/bfe_modules/mod_trust_clientip" "github.com/bfenetworks/bfe/bfe_modules/mod_userid" "github.com/bfenetworks/bfe/bfe_modules/mod_waf" - "github.com/bfenetworks/bfe/bfe_modules/mod_wasmplug" + "github.com/bfenetworks/bfe/bfe_modules/mod_wasmplugin" ) // list of all modules, the order is very important @@ -134,7 +134,7 @@ var moduleList = []bfe_module.BfeModule{ mod_access.NewModuleAccess(), // mod_wasm - mod_wasmplug.NewModuleWasm(), + mod_wasmplugin.NewModuleWasm(), } // init modules list diff --git a/bfe_modules/mod_wasmplug/conf_mod_wasmplug.go b/bfe_modules/mod_wasmplugin/conf_mod_wasmplugin.go similarity index 90% rename from bfe_modules/mod_wasmplug/conf_mod_wasmplug.go rename to bfe_modules/mod_wasmplugin/conf_mod_wasmplugin.go index a9e7a1ae..6cb0503c 100644 --- a/bfe_modules/mod_wasmplug/conf_mod_wasmplug.go +++ b/bfe_modules/mod_wasmplugin/conf_mod_wasmplugin.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package mod_wasmplug +package mod_wasmplugin import ( "fmt" @@ -24,7 +24,7 @@ import ( "github.com/bfenetworks/bfe/bfe_basic/condition" "github.com/bfenetworks/bfe/bfe_util" "github.com/bfenetworks/bfe/bfe_util/json" - "github.com/bfenetworks/bfe/bfe_wasmplug" + "github.com/bfenetworks/bfe/bfe_wasmplugin" gcfg "gopkg.in/gcfg.v1" ) @@ -78,7 +78,7 @@ func (cfg *ConfModWasm) Check(confRoot string) error { type PluginConfFile struct { Version *string // version of the config BeforeLocationRules *[]FilterRuleFile // rule list for BeforeLocation - ProductRules *map[string][]FilterRuleFile // product --> rule list + FoundProductRules *map[string][]FilterRuleFile // product --> rule list for FoundProduct PluginMap *map[string]PluginMeta } @@ -98,7 +98,7 @@ type PluginMeta struct { type FilterRule struct { Cond condition.Condition // condition for plugin - PluginList []bfe_wasmplug.WasmPlugin + PluginList []bfe_wasmplugin.WasmPlugin } type RuleList []FilterRule @@ -106,7 +106,7 @@ type ProductRules map[string]RuleList // product => list of filter rules func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) error { if conf.Version != nil && *conf.Version != t.GetVersion() { - pluginMapNew := make(map[string]bfe_wasmplug.WasmPlugin) + pluginMapNew := make(map[string]bfe_wasmplugin.WasmPlugin) var beforeLocationRulesNew RuleList productRulesNew := make(ProductRules) @@ -135,7 +135,7 @@ func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) er } } // if changed, construct a new plugin. - wasmconf := bfe_wasmplug.WasmPluginConfig { + wasmconf := bfe_wasmplugin.WasmPluginConfig { PluginName: pn, WasmVersion: p.WasmVersion, ConfigVersion: p.ConfVersion, @@ -143,7 +143,7 @@ func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) er Path: path.Join(pluginPath, pn), // Md5: p.Md5, } - plug, err := bfe_wasmplug.NewWasmPlugin(wasmconf) + plug, err := bfe_wasmplugin.NewWasmPlugin(wasmconf) if err != nil { // build plugin error return err @@ -175,8 +175,8 @@ func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) er } } - if conf.ProductRules != nil { - for product, rules := range *conf.ProductRules { + if conf.FoundProductRules != nil { + for product, rules := range *conf.FoundProductRules { var rulelist RuleList for _, r := range rules { rule := FilterRule{} @@ -218,17 +218,17 @@ type PluginTable struct { version string beforeLocationRules RuleList productRules ProductRules - pluginMap map[string]bfe_wasmplug.WasmPlugin + pluginMap map[string]bfe_wasmplugin.WasmPlugin } func NewPluginTable() *PluginTable { t := new(PluginTable) t.productRules = make(ProductRules) - t.pluginMap = make(map[string]bfe_wasmplug.WasmPlugin) + t.pluginMap = make(map[string]bfe_wasmplugin.WasmPlugin) return t } -func (t *PluginTable) Update(version string, beforeLocationRules RuleList, productRules ProductRules, pluginMap map[string]bfe_wasmplug.WasmPlugin) { +func (t *PluginTable) Update(version string, beforeLocationRules RuleList, productRules ProductRules, pluginMap map[string]bfe_wasmplugin.WasmPlugin) { t.lock.Lock() t.version = version @@ -245,7 +245,7 @@ func (t *PluginTable) GetVersion() string { return t.version } -func (t *PluginTable) GetPluginMap() map[string]bfe_wasmplug.WasmPlugin { +func (t *PluginTable) GetPluginMap() map[string]bfe_wasmplugin.WasmPlugin { defer t.lock.RUnlock() t.lock.RLock() return t.pluginMap diff --git a/bfe_modules/mod_wasmplug/mod_wasmplug.go b/bfe_modules/mod_wasmplugin/mod_wasmplugin.go similarity index 92% rename from bfe_modules/mod_wasmplug/mod_wasmplug.go rename to bfe_modules/mod_wasmplugin/mod_wasmplugin.go index a8948c0d..3f4bfba0 100644 --- a/bfe_modules/mod_wasmplug/mod_wasmplug.go +++ b/bfe_modules/mod_wasmplugin/mod_wasmplugin.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package mod_wasmplug +package mod_wasmplugin import ( "fmt" @@ -23,7 +23,7 @@ import ( "github.com/bfenetworks/bfe/bfe_basic" "github.com/bfenetworks/bfe/bfe_http" "github.com/bfenetworks/bfe/bfe_module" - "github.com/bfenetworks/bfe/bfe_wasmplug" + "github.com/bfenetworks/bfe/bfe_wasmplugin" ) const ( @@ -127,7 +127,7 @@ func (m *ModuleWasm) init(cfg *ConfModWasm, cbs *bfe_module.BfeCallbacks, // func (m *ModuleWasm) wasmBeforeLocationHandler(request *bfe_basic.Request) (int, *bfe_http.Response) { - var pl []bfe_wasmplug.WasmPlugin + var pl []bfe_wasmplugin.WasmPlugin rl := m.pluginTable.GetBeforeLocationRules() for _, rule := range rl { if rule.Cond.Match(request) { @@ -141,9 +141,9 @@ func (m *ModuleWasm) wasmBeforeLocationHandler(request *bfe_basic.Request) (int, if pl != nil { // do the pluginlist retCode := bfe_module.BfeHandlerGoOn - var fl []*bfe_wasmplug.Filter + var fl []*bfe_wasmplugin.Filter for _, plug := range pl { - filter := bfe_wasmplug.NewFilter(plug, request) + filter := bfe_wasmplugin.NewFilter(plug, request) var ret int ret, resp = filter.RequestHandler(request) fl = append(fl, filter) @@ -162,7 +162,7 @@ func (m *ModuleWasm) wasmBeforeLocationHandler(request *bfe_basic.Request) (int, // func (m *ModuleWasm) wasmRequestHandler(request *bfe_basic.Request) (int, *bfe_http.Response) { - var pl []bfe_wasmplug.WasmPlugin + var pl []bfe_wasmplugin.WasmPlugin rl, _ := m.pluginTable.Search(request.Route.Product) for _, rule := range rl { if rule.Cond.Match(request) { @@ -176,9 +176,9 @@ func (m *ModuleWasm) wasmRequestHandler(request *bfe_basic.Request) (int, *bfe_h if pl != nil { // do the pluginlist retCode := bfe_module.BfeHandlerGoOn - var fl []*bfe_wasmplug.Filter + var fl []*bfe_wasmplugin.Filter for _, plug := range pl { - filter := bfe_wasmplug.NewFilter(plug, request) + filter := bfe_wasmplugin.NewFilter(plug, request) var ret int ret, resp = filter.RequestHandler(request) fl = append(fl, filter) @@ -188,10 +188,10 @@ func (m *ModuleWasm) wasmRequestHandler(request *bfe_basic.Request) (int, *bfe_h } } - var fl0 []*bfe_wasmplug.Filter + var fl0 []*bfe_wasmplugin.Filter val, ok := request.Context[ModWasmBeforeLocationKey] if ok { - fl0 = val.([]*bfe_wasmplug.Filter) + fl0 = val.([]*bfe_wasmplugin.Filter) } fl0 = append(fl0, fl...) @@ -207,7 +207,7 @@ func (m *ModuleWasm) wasmResponseHandler(request *bfe_basic.Request, res *bfe_ht val, ok := request.Context[ModWasmBeforeLocationKey] if ok { - fl, matched := val.([]*bfe_wasmplug.Filter) + fl, matched := val.([]*bfe_wasmplugin.Filter) if !matched { // error return bfe_module.BfeHandlerGoOn diff --git a/bfe_wasmplug/abi/proxywasm010/factory.go b/bfe_wasmplugin/abi/proxywasm010/factory.go similarity index 100% rename from bfe_wasmplug/abi/proxywasm010/factory.go rename to bfe_wasmplugin/abi/proxywasm010/factory.go diff --git a/bfe_wasmplug/abi/proxywasm010/imports.go b/bfe_wasmplugin/abi/proxywasm010/imports.go similarity index 99% rename from bfe_wasmplug/abi/proxywasm010/imports.go rename to bfe_wasmplugin/abi/proxywasm010/imports.go index 3d73b5f9..d0e64e6d 100644 --- a/bfe_wasmplug/abi/proxywasm010/imports.go +++ b/bfe_wasmplugin/abi/proxywasm010/imports.go @@ -18,7 +18,6 @@ import ( "bytes" "io/ioutil" - // http "github.com/bfenetworks/bfe/bfe_http" "net/http" "net/url" "sync/atomic" diff --git a/bfe_wasmplug/abi/proxywasm010/shim.go b/bfe_wasmplugin/abi/proxywasm010/shim.go similarity index 100% rename from bfe_wasmplug/abi/proxywasm010/shim.go rename to bfe_wasmplugin/abi/proxywasm010/shim.go diff --git a/bfe_wasmplug/abi/registry.go b/bfe_wasmplugin/abi/registry.go similarity index 95% rename from bfe_wasmplug/abi/registry.go rename to bfe_wasmplugin/abi/registry.go index 0b553aaf..db19025c 100644 --- a/bfe_wasmplug/abi/registry.go +++ b/bfe_wasmplugin/abi/registry.go @@ -16,7 +16,7 @@ package abi import ( "github.com/baidu/go-lib/log" - "github.com/bfenetworks/bfe/bfe_wasmplug/abi/proxywasm010" + "github.com/bfenetworks/bfe/bfe_wasmplugin/abi/proxywasm010" "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common" proxywasm "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/v1" ) diff --git a/bfe_wasmplug/adapter.go b/bfe_wasmplugin/adapter.go similarity index 88% rename from bfe_wasmplug/adapter.go rename to bfe_wasmplugin/adapter.go index c9335251..73ea1ab5 100644 --- a/bfe_wasmplug/adapter.go +++ b/bfe_wasmplugin/adapter.go @@ -12,14 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package bfe_wasmplug +package bfe_wasmplugin import ( "bytes" "io/ioutil" "github.com/bfenetworks/bfe/bfe_http" - "github.com/bfenetworks/bfe/bfe_wasmplug/abi/proxywasm010" + "github.com/bfenetworks/bfe/bfe_wasmplugin/abi/proxywasm010" "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common" v1Host "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/v1" ) @@ -27,7 +27,6 @@ import ( // v1 Imports type v1Imports struct { proxywasm010.DefaultImportsHandler - //factory *FilterConfigFactory plugin WasmPlugin filter *Filter } @@ -37,13 +36,11 @@ func (v1 *v1Imports) GetRootContextID() int32 { } func (v1 *v1Imports) GetVmConfig() common.IoBuffer { - //return v1.factory.GetVmConfig() return common.NewIoBufferBytes([]byte{}) } func (v1 *v1Imports) GetPluginConfig() common.IoBuffer { return common.NewIoBufferBytes(v1.plugin.GetPluginConfig()) - //return common.NewIoBufferBytes([]byte{}) } func (v1 *v1Imports) GetHttpRequestHeader() common.HeaderMap { @@ -60,7 +57,6 @@ func (v1 *v1Imports) GetHttpRequestBody() common.IoBuffer { } return nil - // return &proxywasm010.IoBufferWrapper{IoBuffer: v1.filter.receiverFilterHandler.GetRequestData()} } func (v1 *v1Imports) GetHttpRequestTrailer() common.HeaderMap { @@ -85,7 +81,6 @@ func (v1 *v1Imports) GetHttpResponseBody() common.IoBuffer { } return nil - //return &proxywasm010.IoBufferWrapper{IoBuffer: v1.filter.senderFilterHandler.GetResponseData()} } func (v1 *v1Imports) GetHttpResponseTrailer() common.HeaderMap { diff --git a/bfe_wasmplug/engine.go b/bfe_wasmplugin/engine.go similarity index 97% rename from bfe_wasmplug/engine.go rename to bfe_wasmplugin/engine.go index a9bf5ae9..2d604349 100644 --- a/bfe_wasmplug/engine.go +++ b/bfe_wasmplugin/engine.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package bfe_wasmplug +package bfe_wasmplugin import ( "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common" diff --git a/bfe_wasmplug/filter.go b/bfe_wasmplugin/filter.go similarity index 98% rename from bfe_wasmplug/filter.go rename to bfe_wasmplugin/filter.go index 0ec3b41e..cfbc7b12 100644 --- a/bfe_wasmplug/filter.go +++ b/bfe_wasmplugin/filter.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package bfe_wasmplug +package bfe_wasmplugin import ( "sync" @@ -23,7 +23,7 @@ import ( "github.com/bfenetworks/bfe/bfe_module" "github.com/baidu/go-lib/log" - wasmABI "github.com/bfenetworks/bfe/bfe_wasmplug/abi" + wasmABI "github.com/bfenetworks/bfe/bfe_wasmplugin/abi" "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common" v1Host "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/v1" ) diff --git a/bfe_wasmplug/plugin.go b/bfe_wasmplugin/plugin.go similarity index 99% rename from bfe_wasmplug/plugin.go rename to bfe_wasmplugin/plugin.go index 2e53d709..8c651b0d 100644 --- a/bfe_wasmplug/plugin.go +++ b/bfe_wasmplugin/plugin.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package bfe_wasmplug +package bfe_wasmplugin import ( "crypto/md5" @@ -26,7 +26,7 @@ import ( "sync/atomic" "github.com/baidu/go-lib/log" - wasmABI "github.com/bfenetworks/bfe/bfe_wasmplug/abi" + wasmABI "github.com/bfenetworks/bfe/bfe_wasmplugin/abi" "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common" v1Host "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/v1" )