diff --git a/Makefile b/Makefile index 5dfc49ed..2b3039c2 100644 --- a/Makefile +++ b/Makefile @@ -31,18 +31,21 @@ ui: ## Build UI @(cd ui; npm i ; npm run build; ) @ls -l ui/build +.PHONY: copy_wasm +copy_wasm: backend/pkg/rest/http-trace-filter.wasm ## Copy the wasm filter binary file to the APIClarity source code to be emmbeded as a resource + cp wasm-filters/bin/release/http-trace-filter.wasm backend/pkg/rest/http-trace-filter.wasm .PHONY: backend -backend: ## Build Backend +backend: copy_wasm ## Build Backend @(echo "Building Backend ..." ) @(cd backend && go build --tags=json1 -o bin/backend cmd/backend/main.go && ls -l bin/) .PHONY: backend_linux -backend_linux: ## Build Backend Linux +backend_linux: copy_wasm ## Build Backend Linux @(echo "Building Backend linux..." ) @(cd backend && GOOS=linux go build --tags=json1 -o bin/backend_linux cmd/backend/main.go && ls -l bin/) .PHONY: backend_test -backend_test: ## Build Backend test +backend_test: copy_wasm ## Build Backend test @(echo "Building Backend test ..." ) @(cd backend && go build --tags=json1 -o bin/backend_test cmd/test/main.go && ls -l bin/) diff --git a/backend/pkg/rest/http-trace-filter.wasm b/backend/pkg/rest/http-trace-filter.wasm new file mode 100755 index 00000000..8e9d3501 Binary files /dev/null and b/backend/pkg/rest/http-trace-filter.wasm differ diff --git a/backend/pkg/rest/server.go b/backend/pkg/rest/server.go index 881a6fba..aecc3acc 100644 --- a/backend/pkg/rest/server.go +++ b/backend/pkg/rest/server.go @@ -16,8 +16,10 @@ package rest import ( + "bytes" "fmt" "net/http" + "time" "github.com/go-openapi/loads" "github.com/go-openapi/runtime/middleware" @@ -209,6 +211,9 @@ func CreateRESTServer(config *ServerConfig) (*Server, error) { // Enhance the default handler with modules apis handlers newHandler.Handle("/api/modules/", config.ModulesManager.HTTPHandler()) + newHandler.HandleFunc("/plugins/wasm/http-trace-filter.wasm", func(w http.ResponseWriter, r *http.Request) { + http.ServeContent(w, r, "http-trace-filter.wasm", time.Time{}, bytes.NewReader(wasmPluginBinary)) + }) newHandler.Handle("/", origHandler) server.SetHandler(newHandler) s.server = server diff --git a/backend/pkg/rest/wasm_local.go b/backend/pkg/rest/wasm_local.go new file mode 100644 index 00000000..f63027c8 --- /dev/null +++ b/backend/pkg/rest/wasm_local.go @@ -0,0 +1,23 @@ +// Copyright © 2023 Cisco Systems, Inc. and its affiliates. +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package rest + +import ( + _ "embed" +) + +//go:embed http-trace-filter.wasm +var wasmPluginBinary []byte