Skip to content

Commit 610500a

Browse files
committed
starting docs
1 parent b5f5879 commit 610500a

File tree

27 files changed

+658
-31
lines changed

27 files changed

+658
-31
lines changed

server/datastores/s3.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,8 @@ module.exports = class S3Datastore extends Datastore {
550550
filename: metadata.name.replace(/ /g, '-'),
551551
type: metadata.type,
552552
pluginId: pluginId,
553-
template: metadata.template
553+
template: metadata.template,
554+
productTemplate: metadata.productTemplate
554555
};
555556

556557
console.log('generate pluginID', pluginId, newPlugin.pluginId)

server/routers/plugins.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ router.post('/', async (req, res) => {
116116
const out = await Datastore.createEmptyPlugin(req.user.email, req.body.metadata || {
117117
name: req.body.plugin,
118118
type: req.body.type,
119-
template: req.body.template || 'empty'
119+
template: req.body.template || 'empty',
120+
productTemplate: req.body.productTemplate
120121
});
121122

122123
if (out.status !== 201 || !req.body.files) {

server/routers/templates.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ router.get('/', (req, res) => {
1414
error: 'Missing type of project'
1515
})
1616
} else {
17-
const { type } = req.query;
17+
const { type, productTemplate } = req.query;
1818
const template = !req.query.template || req.query.template === 'undefined' ? 'empty' : req.query.template;
19-
19+
2020
if (['rust', 'js', 'go', 'ts', 'opa'].includes(type)) {
21-
getTemplates(type, template, res);
21+
getTemplates(type, template, productTemplate, res);
2222
} else {
2323
res
2424
.status(404)
@@ -36,7 +36,7 @@ function getTemplatesFromPath(type, template, res) {
3636
return res.sendFile(path.join(__dirname, '../templates', `${type}.zip`))
3737
}
3838

39-
function getTemplates(type, template, res) {
39+
function getTemplates(type, template, productTemplate, res) {
4040
const source = ENV.MANAGER_TEMPLATES;
4141
const zipName = `${type}.zip`;
4242

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export function execute() {
2+
let context = JSON.parse(Host.inputString());
3+
4+
if (context.request.headers["foo"] === "bar") {
5+
const out = {
6+
result: true
7+
};
8+
Host.outputString(JSON.stringify(out));
9+
} else {
10+
const error = {
11+
result: false,
12+
error: {
13+
message: "you're not authorized",
14+
status: 401
15+
}
16+
};
17+
Host.outputString(JSON.stringify(error));
18+
}
19+
20+
return 0;
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { WasmAccessValidatorContext, WasmAccessValidatorResponse } from 'otoroshi-ts-types';
2+
3+
export declare var Host: any;
4+
5+
export function execute() {
6+
let context = JSON.parse(Host.inputString()) as WasmAccessValidatorContext;
7+
8+
if (context.request.headers["foo"] === "bar") {
9+
const out: WasmAccessValidatorResponse = {
10+
result: true
11+
};
12+
Host.outputString(JSON.stringify(out));
13+
} else {
14+
const error: WasmAccessValidatorResponse = {
15+
result: false,
16+
error: {
17+
message: "you're not authorized",
18+
status: 401
19+
}
20+
};
21+
Host.outputString(JSON.stringify(error));
22+
}
23+
24+
return 0;
25+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use extism_pdk::*;
2+
use otoroshi_rust_types::types::*;
3+
4+
#[plugin_fn]
5+
pub fn execute(
6+
Json(_context): Json<WasmAccessValidatorContext>,
7+
) -> FnResult<Json<WasmAccessValidatorResponse>> {
8+
let out = types::WasmAccessValidatorResponse {
9+
result: false,
10+
error: Some(types::WasmAccessValidatorError {
11+
message: "you're not authorized".to_owned(),
12+
status: 401,
13+
}),
14+
};
15+
16+
match context.request.headers.get("foo") {
17+
Some(foo) => {
18+
if foo == "bar" {
19+
Ok(Json(types::WasmAccessValidatorResponse {
20+
result: true,
21+
error: None,
22+
}))
23+
} else {
24+
Ok(Json(types::WasmAccessValidatorResponse {
25+
result: false,
26+
error: Some(types::WasmAccessValidatorError {
27+
message: format!("{} is not authorized", foo).to_owned(),
28+
status: 401,
29+
}),
30+
}))
31+
}
32+
}
33+
None => Ok(Json(out)),
34+
}
35+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"github.com/extism/go-pdk"
5+
"github.com/buger/jsonparser"
6+
// "github.com/MAIF/otoroshi-go-types"
7+
)
8+
9+
//export execute
10+
func execute() int32 {
11+
input := pdk.Input()
12+
13+
var foo, err = jsonparser.GetString(input, "request", "headers", "foo")
14+
15+
if err != nil {}
16+
17+
var output = ""
18+
19+
if foo == "bar" {
20+
output = `{
21+
"result": true
22+
}`
23+
} else {
24+
output = `{
25+
"result": false,
26+
"error": {
27+
"message": "you're not authorized",
28+
"status": 401
29+
}
30+
}`
31+
}
32+
33+
mem := pdk.AllocateString(output)
34+
pdk.OutputMemory(mem)
35+
36+
return 0
37+
}
38+
39+
func main() {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package example
2+
3+
default can_access = false
4+
5+
can_access {
6+
input.request.headers.foo == "bar"
7+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
export function execute() {
2+
const str = Host.inputString()
3+
const context = JSON.parse(str)
4+
5+
let headers = { ...context.request.headers }
6+
headers["foo"] = "bar"
7+
8+
const response = {
9+
headers,
10+
'Content-Type': "text/html",
11+
body: `<html lang="en">
12+
13+
<head>
14+
<meta charset="utf-8">
15+
<meta name="viewport" content="width=device-width, initial-scale=1">
16+
</head>
17+
18+
<body style="
19+
display: flex;
20+
align-items: center;
21+
justify-content: center;
22+
flex-direction: column;
23+
height: 100vh;
24+
font-family: monospace;
25+
">
26+
<h1>This HTML comes from the Wasmo plugin</h1>
27+
<img src="https://maif.github.io/wasmo/wasmo.png" style="
28+
width: 200;
29+
">
30+
31+
</body>
32+
</html>`,
33+
status: 200
34+
}
35+
36+
Host.outputString(JSON.stringify(response))
37+
38+
return 0
39+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { WasmQueryContext, WasmQueryResponse } from 'otoroshi-ts-types';
2+
3+
export declare var Host: any;
4+
5+
export function execute() {
6+
const context = JSON.parse(Host.inputString()) as WasmQueryContext;
7+
8+
const headers = {
9+
"foo": "bar",
10+
...(context.request.headers || {})
11+
}
12+
13+
const response: WasmQueryResponse = {
14+
headers,
15+
status: 200,
16+
body: `<html lang="en">
17+
18+
<head>
19+
<meta charset="utf-8">
20+
<meta name="viewport" content="width=device-width, initial-scale=1">
21+
</head>
22+
23+
<body style="
24+
display: flex;
25+
align-items: center;
26+
justify-content: center;
27+
flex-direction: column;
28+
height: 100vh;
29+
font-family: monospace;
30+
">
31+
<h1>This HTML comes from the Wasmo plugin</h1>
32+
<img src="https://maif.github.io/wasmo/wasmo.png" style="
33+
width: 200;
34+
">
35+
36+
</body>
37+
</html>`,
38+
};
39+
Host.outputString(JSON.stringify(response));
40+
41+
return 0;
42+
}
43+

0 commit comments

Comments
 (0)