-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
82 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[build] | ||
target = "wasm32-wasi" | ||
target = "wasm32-wasip1" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "secret" | ||
version = {workspace = true} | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
fastedge = { path = "../../" } | ||
anyhow = "1.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 anyhow::{Error, Result}; | ||
|
||
use fastedge::body::Body; | ||
use fastedge::http::{Request, Response, StatusCode}; | ||
use fastedge::secret; | ||
|
||
#[allow(dead_code)] | ||
#[fastedge::http] | ||
fn main(_req: Request<Body>) -> Result<Response<Body>> { | ||
|
||
let value = match secret::get("SECRET") { | ||
Ok(value) => value, | ||
Err(secret::Error::AccessDenied) => { | ||
return Response::builder() | ||
.status(StatusCode::FORBIDDEN) | ||
.body(Body::empty()) | ||
.map_err(Error::msg); | ||
}, | ||
Err(secret::Error::Other(msg)) => { | ||
return Response::builder() | ||
.status(StatusCode::FORBIDDEN) | ||
.body(Body::from(msg)) | ||
.map_err(Error::msg); | ||
}, | ||
}; | ||
|
||
if value.is_none() { | ||
return Response::builder() | ||
.status(StatusCode::NOT_FOUND) | ||
.body(Body::empty()) | ||
.map_err(Error::msg); | ||
} | ||
|
||
Response::builder() | ||
.status(StatusCode::OK) | ||
.body(Body::empty()) | ||
.map_err(Error::msg) | ||
} |
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
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,14 @@ | ||
interface secret { | ||
/// Get the secret associated with the specified `key` | ||
/// Returns `ok(none)` if the key does not exist. | ||
get: func(key: string) -> result<option<string>, error>; | ||
|
||
/// The set of errors which may be raised by functions in this interface | ||
variant error { | ||
/// The requesting component does not have access to the specified key | ||
/// (which may or may not exist). | ||
access-denied, | ||
/// Some implementation-specific error has occurred (e.g. I/O) | ||
other(string) | ||
} | ||
} |
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,12 +1,12 @@ | ||
package gcore:fastedge; | ||
package gcore: fastedge; | ||
|
||
world http-reactor { | ||
import http; | ||
import http-client; | ||
import http; | ||
import http-client; | ||
|
||
import dictionary; | ||
import dictionary; | ||
import key-value; | ||
import secret; | ||
|
||
import key-value; | ||
|
||
export http-handler; | ||
export http-handler; | ||
} |