Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serve the wasm filter on /plugins/wasm/http-trace-filter.wasm #333

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

Expand Down
Binary file added backend/pkg/rest/http-trace-filter.wasm
Binary file not shown.
5 changes: 5 additions & 0 deletions backend/pkg/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
package rest

import (
"bytes"
"fmt"
"net/http"
"time"

"github.com/go-openapi/loads"
"github.com/go-openapi/runtime/middleware"
Expand Down Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions backend/pkg/rest/wasm_local.go
Original file line number Diff line number Diff line change
@@ -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