Skip to content

Commit

Permalink
feat: secret demo sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanti committed Oct 21, 2024
1 parent adaa14d commit 8ae6126
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The table below summarizes the feature support for language SDKs.
| Env Variables | Supported | Supported |

## Rust toolchain setup:
- `rustup target add wasm32-wasi`
- `rustup target add wasm32-wasip1`

# The FastEdge Rust SDK

Expand Down
12 changes: 12 additions & 0 deletions examples/secret/Cargo.toml
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"
44 changes: 44 additions & 0 deletions examples/secret/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

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);
},
Err(secret::Error::DecryptError) => {
return Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::empty())
.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::from(value.unwrap_or_default()))
.map_err(Error::msg)
}

0 comments on commit 8ae6126

Please sign in to comment.