Skip to content

Commit

Permalink
add documentation about new otoroshi templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed Jun 25, 2024
1 parent e5bf436 commit 0f1b49d
Show file tree
Hide file tree
Showing 139 changed files with 2,643 additions and 172 deletions.
20 changes: 0 additions & 20 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ hyper-tls = "0.5.0"
base64 = "0.21.5"
tokio-tungstenite = { version = "0.20.1", features = ["native-tls"] }
futures-channel = "0.3.29"
include_dir = "0.7.4"

[dev-dependencies]
serial_test = "2.0.0"
Expand Down
35 changes: 33 additions & 2 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ with wasm modules:
| `wasmo config set` | path | server | clientId | clientSecret | Globally configure the CLI with the path where the configuration file will be stored and the server to reach during the build. These parameters are optional and can be passed when running the build command. |
| `wasmo config get` | | Get the configuration from the configured path file or from `$HOME/.wasmo` |
| `wasmo config reset` | | Clean configuration and reset to default settings. The default file path configuration will be `$HOME/.wasmo` ||
| `wasmo init` | template | name | path | Initialize a WASM plugin to the specific path. You can choose between many templates, javascript/typescript (js/ts), Open Policy Agent (opa), Rust or Golang (go). |
| `wasmo init` | language | product | product_template | template | name | path | Initialize a WASM plugin to the specific path. You can choose between many templates, javascript/typescript (js/ts), Open Policy Agent (opa), Rust or Golang (go). |
| `wasmo build` | path | host | server | clientId | clientSecret | Build the plugin by sending the contents to the remote or local Wasmo server. As soon as the build is complete, the WASM binary is donwloaded and saved in the plugin folder. |

# Quick start
Expand All @@ -63,7 +63,38 @@ wasmo build --host=OneShotDocker --path=my-first-plugin

Then open the content of your `my-first-plugin` folder. You should find the generated WASM binary named `my-first-plugin-1.0.0.wasm`.

## Selecting a template
## Specifying language, product and product_template to create a plugin

With the newer version, you should create a plugin by specifying the language to be used, the target product, and the template.

```
wasmo init --name=my-first-plugin --language=js --product=otoroshi --product_template=ACCESS_CONTROL
```

The product template parameter accepts multiple values:
- REQUEST_TRANSFORMER: Transform the content of the request with a wasm plugin
- RESPONSE_TRANSFORMER: Transform the content of a response with a wasm plugin
- ACCESS_CONTROL: Delegate route access to a wasm plugin
- BACKEND: This plugin can be used to use a wasm plugin as backend
- ROUTE_MATCHER: This plugin can be used to use a wasm plugin as route matcher
- SINK: Handle unmatched requests with a wasm plugin
- PRE_ROUTE: This plugin can be used to use a wasm plugin as in pre-route phase

You can also create a Izanami plugin

```
wasmo init --name=my-first-plugin --language=js --product=izanami
```

For the moment, Izanami doesn't provide any templates.

If you want to start from scratch, without targeting any products

```
wasmo init --name=my-first-plugin --language=js
```

## Or selecting a template

You can now optionally start a new plugin from a template by appending `--template=[template-name]` to the creation command.

Expand Down
177 changes: 93 additions & 84 deletions cli/src/bin.rs

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub enum WasmoError {
FileSystem(String),
NoDockerRunning(String),
DockerContainer(String),
Configuration(String)
Configuration(String),
Raw(String)
}

impl fmt::Display for WasmoError {
Expand All @@ -34,6 +35,9 @@ impl fmt::Display for WasmoError {
},
WasmoError::Configuration(err) => {
write!(f,"something happened with the configuration, {}", &err)
},
WasmoError::Raw(err) => {
write!(f, "{}", &err)
}
}
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const esbuild = require('esbuild')

esbuild
.build({
entryPoints: ['index.js'],
outdir: 'dist',
bundle: true,
sourcemap: true,
minify: false, // might want to use true for production build
format: 'cjs', // needs to be CJS for now
target: ['es2020'] // don't go over es2020 because quickjs doesn't support it
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export function execute() {
let context = JSON.parse(Host.inputString())

if (context.request.headers["foo"] === "bar") {
const out = {
result: true
}
Host.outputString(JSON.stringify(out))
} else {
const error = {
result: false,
error: {
message: "you're not authorized",
status: 401
}
}
Host.outputString(JSON.stringify(error))
}

return 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@@PLUGIN_NAME@@",
"version": "@@PLUGIN_VERSION@@",
"devDependencies": {
"esbuild": "^0.17.9"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
We must also describe the Wasm interface for our plug-in.
We do this with a typescript module DTS file
DO NOT DELETE THIS FILE
*/
declare module 'main' {
export function execute(): I32;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
33 changes: 32 additions & 1 deletion docs/documentation/app/cli/getting-started/_page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,38 @@ wasmo build --host=OneShotDocker --path=my-first-plugin

Then open the content of your `my-first-plugin` folder. You should find the generated WASM binary named `my-first-plugin-1.0.0.wasm`.

## Selecting a template
## Specifying language and product to create a plugin

With the newer version, you should create a plugin by specifying the language to be used, the target product, and the template.

```
wasmo init --name=my-first-plugin --language=js --product=otoroshi --product_template=ACCESS_CONTROL
```

The product template parameter accepts multiple values:
- **REQUEST_TRANSFORMER**: Transform the content of the request with a wasm plugin
- **RESPONSE_TRANSFORMER**: Transform the content of a response with a wasm plugin
- **ACCESS_CONTROL**: Delegate route access to a wasm plugin
- **BACKEND**: This plugin can be used to use a wasm plugin as backend
- **ROUTE_MATCHER**: This plugin can be used to use a wasm plugin as route matcher
- **SINK**: Handle unmatched requests with a wasm plugin
- **PRE_ROUTE**: This plugin can be used to use a wasm plugin as in pre-route phase

You can also create a Izanami plugin

```
wasmo init --name=my-first-plugin --language=js --product=izanami
```

For the moment, Izanami doesn't provide any templates.

If you want to start from scratch, without targeting any products

```
wasmo init --name=my-first-plugin --language=js
```

## Or selecting a template

You can now optionally start a new plugin from a template by appending `--template=[template-name]` to the creation command.

Expand Down
Loading

0 comments on commit 0f1b49d

Please sign in to comment.