-
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
932aeb6
commit e85d154
Showing
6 changed files
with
132 additions
and
46 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,21 +1,25 @@ | ||
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; | ||
} | ||
export function sink_matches() { | ||
// const context = JSON.parse(Host.inputString()) | ||
|
||
Host.outputString(JSON.stringify({ | ||
result: true | ||
})) | ||
|
||
return 0 | ||
} | ||
|
||
export function sink_handle() { | ||
const context = JSON.parse(Host.inputString()) | ||
|
||
Host.outputString(JSON.stringify({ | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body_json: { | ||
"WASM_SINK_RESPONSE": `Unknown path and domain for ${context.request.path}` | ||
} | ||
})) | ||
|
||
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,33 @@ | ||
import { WasmSinkContext, WasmSinkMatchesResponse, WasmSinkHandleResponse } from 'otoroshi-ts-types'; | ||
|
||
export declare var Host: any; | ||
|
||
export function sink_matches() { | ||
// const context = JSON.parse(Host.inputString()) as WasmSinkContext; | ||
|
||
const out: WasmSinkMatchesResponse = { | ||
result: true | ||
} | ||
|
||
Host.outputString(JSON.stringify(out)); | ||
|
||
return 0; | ||
} | ||
|
||
export function sink_handle() { | ||
const context = JSON.parse(Host.inputString()) as WasmSinkContext; | ||
|
||
const out: WasmSinkHandleResponse = { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body_json: { | ||
"WASM_SINK_RESPONSE": `Unknown path and domain for ${context.request.path}` | ||
} | ||
} | ||
|
||
Host.outputString(JSON.stringify(out)) | ||
|
||
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,28 @@ | ||
use extism_pdk::*; | ||
use otoroshi_rust_types::types; | ||
|
||
#[plugin_fn] | ||
pub fn sink_matches( | ||
Json(context): Json<types::WasmSinkContext>, | ||
) -> FnResult<Json<types::WasmSinkMatchesResponse>> { | ||
Ok(Json(types::WasmSinkMatchesResponse { result: true })) | ||
} | ||
|
||
#[plugin_fn] | ||
pub fn sink_handle( | ||
Json(context): Json<types::WasmSinkContext>, | ||
) -> FnResult<Json<types::WasmSinkHandleResponse>> { | ||
let path: String = context.request.path; | ||
|
||
Ok(Json(types::WasmSinkHandleResponse { | ||
status: 404, | ||
body_str: Some(format!( | ||
r#"{{ "WASM_SINK_RESPONSE": "Unknown path and domain for {}" }}"#, | ||
path | ||
)), | ||
headers: context.request.headers, | ||
body_base64: None, | ||
body_bytes: None, | ||
body_json: None, | ||
})) | ||
} |
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,42 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/buger/jsonparser" | ||
"github.com/extism/go-pdk" | ||
// "github.com/MAIF/otoroshi-go-types" | ||
) | ||
|
||
//export sink_matches | ||
func sink_matches() int32 { | ||
output := `{ "result": true }` | ||
mem := pdk.AllocateString(output) | ||
pdk.OutputMemory(mem) | ||
|
||
return 0 | ||
} | ||
|
||
//export sink_handle | ||
func sink_handle() int32 { | ||
input := pdk.Input() | ||
|
||
var path, err = jsonparser.GetString(input, "request", "path") | ||
|
||
if err != nil { | ||
} | ||
|
||
output := `{ | ||
"status": 200, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"body_json": { | ||
"WASM_SINK_RESPONSE": "Unknown path and domain for ` + path + `" | ||
} | ||
}` | ||
mem := pdk.AllocateString(output) | ||
pdk.OutputMemory(mem) | ||
|
||
return 0 | ||
} | ||
|
||
func main() {} |
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