From 8daaca8d14c5666f85ae1d08338b29b6303829d9 Mon Sep 17 00:00:00 2001 From: Julien Salleyron Date: Tue, 18 Jun 2024 10:00:40 +0200 Subject: [PATCH] first implementation --- .assets/icon.png | Bin 0 -> 24497 bytes .github/workflows/main.yml | 43 ++++++ .github/workflows/release.yml | 34 +++++ .gitignore | 6 + .golangci.yml | 161 ++++++++++++++++++++++ .goreleaser.yml | 32 +++++ .traefik.yml | 10 ++ LICENSE | 202 +++++++++++++++++++++++++++ Makefile | 15 ++ demo.go | 130 ++++++++++++++++++ go.mod | 15 ++ go.sum | 10 ++ readme.md | 252 ++++++++++++++++++++++++++++++++++ 13 files changed, 910 insertions(+) create mode 100644 .assets/icon.png create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 .golangci.yml create mode 100644 .goreleaser.yml create mode 100644 .traefik.yml create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 demo.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 readme.md diff --git a/.assets/icon.png b/.assets/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1a3770b0f9830a8557e845264352ae17126f172d GIT binary patch literal 24497 zcmeEubx>T*_AT!2?(XgccN^RZFbwYQ?k>SY&=A}S?ry?==|IBSlH6z>%jBXN7pB# zu9qG0HA3n*y32@{4#1lc-N59>&@<@4y;|Rc%GXD@E8kB4fLBiB=e_G?fwQF#zGt^T z-}t_jGhIdvajFmeO`L{kst#S_vcj+c{_;Rw=TI| zMt!l;Jbit!ez{M1IOZ~Gzdk(i4?N&ce>DI2 z_PcG_Z*p86iBZw*;lo^lj90*>i$TBZ(Jr3eMd}+zddZpgo;GC}Zhp%x+Cb>UZY=B62Io64qXph}?m>DQmD-e*9^ z$(~eL5#jr8JkB3ncILce74;JzhA4c~D%(fP$}2ku;|1-`f$4@G%YF%%DEY3(+v>`~ zC)b=T`R*xg?pMrBtL{(4BHGNpv$xeR_2hgHQ>ccV1L_OL!_9SRWmqRFw- z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M`bYrz=D7w*3;(R4_ebLFmG4t5f@PP;|{7VhqoWFRtS;!0mvz9tD499&x;-ABA z$??(bTkyUCQ0ivn-X3oQ<>^cp00}2USD|Z+P}kPSyue;~3ymYa8`?Wm#&(H(qeQeT zWGh@H?G9~31Zc?SX{a1mj6ae>p1dWc(kZ+QYkPzK@hAcrKi59ZVOfD3S=HE8dzH4K z_(*8@QR*4a$cQ 0 { + timezone = config.Timezone + } + return &Demo{ + header: config.HeaderName, + timezone: timezone, + }, nil +} + +func (a *Demo) handleRequest(req api.Request, resp api.Response) (next bool, reqCtx uint32) { + response, err := http.Get("http://worldtimeapi.org/api/timezone/" + a.timezone) + if err != nil { + resp.SetStatusCode(http.StatusInternalServerError) + handler.Host.Log(api.LogLevelError, fmt.Sprintf("Could not fetch time %v", err)) + return false, reqCtx + } + + if response.StatusCode != 200 { + resp.SetStatusCode(http.StatusInternalServerError) + handler.Host.Log(api.LogLevelError, fmt.Sprintf("Could not fetch time %d instead of 200", response.Status)) + return false, reqCtx + } + body, err := io.ReadAll(response.Body) + if err != nil { + resp.SetStatusCode(http.StatusInternalServerError) + handler.Host.Log(api.LogLevelError, fmt.Sprintf("Could not read body %v", err)) + return + } + + worldTime := WorldTime{} + err = json.Unmarshal(body, &worldTime) + if err != nil { + resp.SetStatusCode(http.StatusInternalServerError) + handler.Host.Log(api.LogLevelError, fmt.Sprintf("Could not parse body %v", err)) + return + } + req.Headers().Set(a.header, worldTime.Datetime.String()) + + return true, 0 +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..d6b9662 --- /dev/null +++ b/go.mod @@ -0,0 +1,15 @@ +module github.com/traefik/plugindemowasm-http-call + +go 1.22.3 + +toolchain go1.22.4 + +require ( + github.com/http-wasm/http-wasm-guest-tinygo v0.3.0 + github.com/juliens/wasm-goexport v0.0.4 + github.com/stealthrocket/net v0.2.1 +) + +require github.com/tetratelabs/wazero v1.7.2 // indirect + +replace github.com/http-wasm/http-wasm-guest-tinygo => github.com/juliens/http-wasm-guest-tinygo v0.0.0-20240602204949-9cdd64d990eb diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f490dfd --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/juliens/http-wasm-guest-tinygo v0.0.0-20240602204949-9cdd64d990eb h1:zu/1V3TubvsyU/7htboUbtJqEjGjiqqb4d2Zw3Y7rNk= +github.com/juliens/http-wasm-guest-tinygo v0.0.0-20240602204949-9cdd64d990eb/go.mod h1:2y41PPhMXqIPjV7avBDtSfiiVcMpYR9UGqFHL0c6dFQ= +github.com/juliens/wasm-goexport v0.0.4 h1:Kj2xaRSE7x73d/AjJ3moBgMS9kI6TgqOL4QS6WmWym4= +github.com/juliens/wasm-goexport v0.0.4/go.mod h1:9Csd4i5itjBZ/yQdNFOJuVWlAWjyAgyBBZ4YlcWK+oM= +github.com/stealthrocket/net v0.2.1 h1:PehPGAAjuV46zaeHGlNgakFV7QDGUAREMcEQsZQ8NLo= +github.com/stealthrocket/net v0.2.1/go.mod h1:VvoFod9pYC9mo+bEg2NQB/D+KVOjxfhZjZ5zyvozq7M= +github.com/tetratelabs/wazero v1.7.2 h1:1+z5nXJNwMLPAWaTePFi49SSTL0IMx/i3Fg8Yc25GDc= +github.com/tetratelabs/wazero v1.7.2/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..955d469 --- /dev/null +++ b/readme.md @@ -0,0 +1,252 @@ +This repository includes an example plugin, `demo` using [http-wasm](https://http-wasm.io/) and the WasmEdge socket extension to make http calls, for you to use as a reference for developing your own plugins. + +[![Build Status](https://github.com/traefik/plugindemowasm/workflows/Main/badge.svg?branch=master)](https://github.com/traefik/plugindemowasm/actions) + +The existing plugins can be browsed into the [Plugin Catalog](https://plugins.traefik.io). + +# Developing a Traefik plugin + +[Traefik](https://traefik.io) plugins are developed using [http-wasm](https://http-wasm.io/). + +## Usage + +For a plugin to be active for a given Traefik instance, it must be declared in the static configuration. + +Plugins are parsed and loaded exclusively during startup, which allows Traefik to check the integrity of the code and catch errors early on. +If an error occurs during loading, the plugin is disabled. + +For security reasons, it is not possible to start a new plugin or modify an existing one while Traefik is running. + +Once loaded, middleware plugins behave exactly like statically compiled middlewares. +Their instantiation and behavior are driven by the dynamic configuration. + +### Configuration + +For each plugin, the Traefik static configuration must define the module name (as is usual for Go packages). + +The following declaration (given here in YAML) defines a plugin: + +```yaml +# Static configuration + +experimental: + plugins: + example: + moduleName: github.com/traefik/plugindemowasm + version: v0.0.1 +``` + +Here is an example of a file provider dynamic configuration (given here in YAML), where the interesting part is the `http.middlewares` section: + +```yaml +# Dynamic configuration + +http: + routers: + my-router: + rule: host(`demo.localhost`) + service: service-foo + entryPoints: + - web + middlewares: + - my-plugin + + services: + service-foo: + loadBalancer: + servers: + - url: http://127.0.0.1:5000 + + middlewares: + my-plugin: + plugin: + example: + headerName: X-World-Time +``` + +### Local Mode + +Traefik also offers a developer mode that can be used for temporary testing of plugins not hosted on GitHub. +To use a plugin in local mode, the Traefik static configuration must define the module name (as is usual for Go packages). + +The plugins must be placed in `./plugins-local` directory, +which should be in the working directory of the process running the Traefik binary. +The source code of the plugin should be organized as follows: + +``` +./plugins-local/ + └── src + └── github.com + └── traefik + └── plugindemowasm-http-call + ├── plugin.wasm + └── .traefik.yml +``` + +```yaml +# Static configuration + +experimental: + localPlugins: + example: + moduleName: github.com/traefik/plugindemowasm-http-call +``` + +(In the above example, the `plugindemowasm-http-call` plugin will be loaded from the path `./plugins-local/src/github.com/traefik/plugindemowasm-http-call`.) + +```yaml +# Dynamic configuration + +http: + routers: + my-router: + rule: host(`demo.localhost`) + service: service-foo + entryPoints: + - web + middlewares: + - my-plugin + + services: + service-foo: + loadBalancer: + servers: + - url: http://127.0.0.1:5000 + + middlewares: + my-plugin: + plugin: + example: + headerName: X-World-Time +``` + +## Defining a Plugin + +ABI is available [here](https://http-wasm.io/http-handler-abi/) + +If you want to make http call, you need to import ` _ "github.com/stealthrocket/net/http".` + + +```go +package main + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/juliens/wasm-goexport/guest" + _ "github.com/stealthrocket/net/http" + "github.com/http-wasm/http-wasm-guest-tinygo/handler" + "github.com/http-wasm/http-wasm-guest-tinygo/handler/api" +) + +// Config the plugin configuration. +type Config struct { + Headers map[string]string `json:"headers,omitempty"` +} + +func main() { + var config Config + err := json.Unmarshal(handler.Host.GetConfig(), &config) + if err != nil { + handler.Host.Log(api.LogLevelError, fmt.Sprintf("Could not load config %v", err)) + os.Exit(1) + } + + mw, err := New(config) + if err != nil { + handler.Host.Log(api.LogLevelError, fmt.Sprintf("Could not load config %v", err)) + os.Exit(1) + } + handler.HandleRequestFn = mw.handleRequest + + guest.SetExports(handler.GetExports()) + +} + +// Demo a Demo plugin. +type Demo struct{} + +// New created a new Demo plugin. +func New(config Config) (*Demo, error) { + return &Demo{}, nil +} + +func (d Demo) handleRequest(req api.Request, resp api.Response) (next bool, reqCtx uint32) { + return true, 0 +} +``` + +## Plugins Catalog + +Traefik plugins are stored and hosted as public GitHub repositories. + +Every 30 minutes, the Plugins Catalog online service polls Github to find plugins and add them to its catalog. + +### Prerequisites + +To be recognized by Plugins Catalog, your repository must meet the following criteria: + +- The `traefik-plugin` topic must be set. +- The `.traefik.yml` manifest must exist, and be filled with valid contents. +- You need a zip archive in the release assets containing the wasm file (by default `plugin.wasm`) and the `.traefik.yml` file. + +If your repository fails to meet either of these prerequisites, Plugins Catalog will not see it. + +### Manifest + +A manifest is also mandatory, and it should be named `.traefik.yml` and stored at the root of your project. + +This YAML file provides Plugins Catalog with information about your plugin, such as a description, a full name, and so on. + +Here is an example of a typical `.traefik.yml`file: + +```yaml +# The name of your plugin as displayed in the Plugins Catalog web UI. +displayName: Name of your plugin + +# For now, `middleware` is the only type available. +type: middleware + +runtime: wasm + +# A brief description of what your plugin is doing. +summary: Description of what my plugin is doing + +# Medias associated to the plugin (optional) +iconPath: foo/icon.png +bannerPath: foo/banner.png + +# Configuration data for your plugin. +# This is mandatory, +# and Plugins Catalog will try to execute the plugin with the data you provide as part of its startup validity tests. +testData: + HeaderName: X-World-Time +``` + +Properties include: + +- `displayName` (required): The name of your plugin as displayed in the Plugins Catalog web UI. +- `type` (required): For now, `middleware` is the only type available. +- `runtime` (required): The runtime `wasm`. +- `summary` (required): A brief description of what your plugin is doing. +- `testData` (required): Configuration data for your plugin. This is mandatory, and Plugins Catalog will try to execute the plugin with the data you provide as part of its startup validity tests. +- `iconPath` (optional): A local path in the repository to the icon of the project. +- `bannerPath` (optional): A local path in the repository to the image that will be used when you will share your plugin page in social medias. + +### Tags and Dependencies + +Your plugins need to be versioned with a git tag. + +If something goes wrong with the integration of your plugin, Plugins Catalog will create an issue inside your Github repository and will stop trying to add your repo until you close the issue. + +## Troubleshooting + +If Plugins Catalog fails to recognize your plugin, you will need to make one or more changes to your GitHub repository. + +In order for your plugin to be successfully imported by Plugins Catalog, consult this checklist: + +- The `traefik-plugin` topic must be set on your repository. +- There must be a `.traefik.yml` file at the root of your project describing your plugin, and it must have a valid `testData` property for testing purposes. +- Your plugin must be versioned with a git tag.