-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5f5879
commit 610500a
Showing
27 changed files
with
658 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
server/templates/otoroshi/OTOROSHI_WASM_ACCESS_CONTROL/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
25 changes: 25 additions & 0 deletions
25
server/templates/otoroshi/OTOROSHI_WASM_ACCESS_CONTROL/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { WasmAccessValidatorContext, WasmAccessValidatorResponse } from 'otoroshi-ts-types'; | ||
|
||
export declare var Host: any; | ||
|
||
export function execute() { | ||
let context = JSON.parse(Host.inputString()) as WasmAccessValidatorContext; | ||
|
||
if (context.request.headers["foo"] === "bar") { | ||
const out: WasmAccessValidatorResponse = { | ||
result: true | ||
}; | ||
Host.outputString(JSON.stringify(out)); | ||
} else { | ||
const error: WasmAccessValidatorResponse = { | ||
result: false, | ||
error: { | ||
message: "you're not authorized", | ||
status: 401 | ||
} | ||
}; | ||
Host.outputString(JSON.stringify(error)); | ||
} | ||
|
||
return 0; | ||
} |
35 changes: 35 additions & 0 deletions
35
server/templates/otoroshi/OTOROSHI_WASM_ACCESS_CONTROL/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use extism_pdk::*; | ||
use otoroshi_rust_types::types::*; | ||
|
||
#[plugin_fn] | ||
pub fn execute( | ||
Json(_context): Json<WasmAccessValidatorContext>, | ||
) -> FnResult<Json<WasmAccessValidatorResponse>> { | ||
let out = types::WasmAccessValidatorResponse { | ||
result: false, | ||
error: Some(types::WasmAccessValidatorError { | ||
message: "you're not authorized".to_owned(), | ||
status: 401, | ||
}), | ||
}; | ||
|
||
match context.request.headers.get("foo") { | ||
Some(foo) => { | ||
if foo == "bar" { | ||
Ok(Json(types::WasmAccessValidatorResponse { | ||
result: true, | ||
error: None, | ||
})) | ||
} else { | ||
Ok(Json(types::WasmAccessValidatorResponse { | ||
result: false, | ||
error: Some(types::WasmAccessValidatorError { | ||
message: format!("{} is not authorized", foo).to_owned(), | ||
status: 401, | ||
}), | ||
})) | ||
} | ||
} | ||
None => Ok(Json(out)), | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
server/templates/otoroshi/OTOROSHI_WASM_ACCESS_CONTROL/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/extism/go-pdk" | ||
"github.com/buger/jsonparser" | ||
// "github.com/MAIF/otoroshi-go-types" | ||
) | ||
|
||
//export execute | ||
func execute() int32 { | ||
input := pdk.Input() | ||
|
||
var foo, err = jsonparser.GetString(input, "request", "headers", "foo") | ||
|
||
if err != nil {} | ||
|
||
var output = "" | ||
|
||
if foo == "bar" { | ||
output = `{ | ||
"result": true | ||
}` | ||
} else { | ||
output = `{ | ||
"result": false, | ||
"error": { | ||
"message": "you're not authorized", | ||
"status": 401 | ||
} | ||
}` | ||
} | ||
|
||
mem := pdk.AllocateString(output) | ||
pdk.OutputMemory(mem) | ||
|
||
return 0 | ||
} | ||
|
||
func main() {} |
7 changes: 7 additions & 0 deletions
7
server/templates/otoroshi/OTOROSHI_WASM_ACCESS_CONTROL/policies.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package example | ||
|
||
default can_access = false | ||
|
||
can_access { | ||
input.request.headers.foo == "bar" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export function execute() { | ||
const str = Host.inputString() | ||
const context = JSON.parse(str) | ||
|
||
let headers = { ...context.request.headers } | ||
headers["foo"] = "bar" | ||
|
||
const response = { | ||
headers, | ||
'Content-Type': "text/html", | ||
body: `<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
</head> | ||
<body style=" | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
height: 100vh; | ||
font-family: monospace; | ||
"> | ||
<h1>This HTML comes from the Wasmo plugin</h1> | ||
<img src="https://maif.github.io/wasmo/wasmo.png" style=" | ||
width: 200; | ||
"> | ||
</body> | ||
</html>`, | ||
status: 200 | ||
} | ||
|
||
Host.outputString(JSON.stringify(response)) | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { WasmQueryContext, WasmQueryResponse } from 'otoroshi-ts-types'; | ||
|
||
export declare var Host: any; | ||
|
||
export function execute() { | ||
const context = JSON.parse(Host.inputString()) as WasmQueryContext; | ||
|
||
const headers = { | ||
"foo": "bar", | ||
...(context.request.headers || {}) | ||
} | ||
|
||
const response: WasmQueryResponse = { | ||
headers, | ||
status: 200, | ||
body: `<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
</head> | ||
<body style=" | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
height: 100vh; | ||
font-family: monospace; | ||
"> | ||
<h1>This HTML comes from the Wasmo plugin</h1> | ||
<img src="https://maif.github.io/wasmo/wasmo.png" style=" | ||
width: 200; | ||
"> | ||
</body> | ||
</html>`, | ||
}; | ||
Host.outputString(JSON.stringify(response)); | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use extism_pdk::*; | ||
use otoroshi_rust_types::types::*; | ||
use std::collections::HashMap; | ||
|
||
#[plugin_fn] | ||
pub fn execute(Json(context): Json<types::WasmQueryContext>) -> FnResult<Json<types::WasmQueryResponse>> { | ||
let mut headers = HashMap::new(); | ||
headers.insert("foo".to_string(), "bar".to_string()); | ||
|
||
let response = types::WasmQueryResponse { | ||
headers: Some(headers.into_iter().chain(context.raw_request.headers).collect()), | ||
body: r#"<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
</head> | ||
<body style=" | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
height: 100vh; | ||
font-family: monospace; | ||
"> | ||
<h1>This HTML comes from the Wasmo plugin</h1> | ||
<img src="https://maif.github.io/wasmo/wasmo.png" style=" | ||
width: 200; | ||
"> | ||
</body> | ||
</html>"#.to_owned(), | ||
status: 200 | ||
}; | ||
|
||
Ok(Json(response)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/extism/go-pdk" | ||
"github.com/buger/jsonparser" | ||
// "github.com/MAIF/otoroshi-go-types" | ||
) | ||
|
||
//export execute | ||
func execute() int32 { | ||
input := pdk.Input() | ||
|
||
var headers, dataType, offset, err = jsonparser.Get(input, "request", "headers") | ||
|
||
_ = dataType | ||
_ = offset | ||
_ = headers | ||
|
||
if err != nil {} | ||
|
||
output := `{ "headers": { "Content-Type": "text/html" }, "body": "<html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body style=\"display: flex;align-items: center;justify-content: center;flex-direction: column;height: 100vh;font-family: monospace;\"><h1>This HTML comes from the Wasmo plugin</h1><img src=\"https://maif.github.io/wasmo/wasmo.png\" style=\"width: 200;\"></body></html>", "status": 200 }` | ||
mem := pdk.AllocateString(output) | ||
pdk.OutputMemory(mem) | ||
|
||
return 0 | ||
} | ||
|
||
func main() {} |
20 changes: 20 additions & 0 deletions
20
server/templates/otoroshi/OTOROSHI_WASM_PRE_ROUTE/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export function execute() { | ||
let context = JSON.parse(Host.inputString()) | ||
|
||
if (context.request.headers["bar"] === "foo") { | ||
Host.outputString(JSON.stringify({ | ||
error: false | ||
})) | ||
} else { | ||
Host.outputString(JSON.stringify({ | ||
error: true, | ||
headers: { | ||
'Content-Type': 'text/plain' | ||
}, | ||
status: 401, | ||
body: "you're not authorized" | ||
})) | ||
} | ||
|
||
return 0 | ||
} |
26 changes: 26 additions & 0 deletions
26
server/templates/otoroshi/OTOROSHI_WASM_PRE_ROUTE/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { WasmPreRouteContext, WasmPreRouteResponse } from 'otoroshi-ts-types'; | ||
|
||
export declare var Host: any; | ||
|
||
export function execute() { | ||
let context = JSON.parse(Host.inputString()) as WasmPreRouteContext; | ||
|
||
if (context.request.headers["bar"] === "foo") { | ||
const out: WasmPreRouteResponse = { | ||
error: false | ||
} | ||
Host.outputString(JSON.stringify(out)); | ||
} else { | ||
const error = { | ||
error: true, | ||
status: 401, | ||
headers: { | ||
'Content-Type': 'text/plain' | ||
}, | ||
body: "you're not authorized" | ||
} | ||
Host.outputString(JSON.stringify(error)); | ||
} | ||
|
||
return 0 | ||
} |
Oops, something went wrong.