-
Notifications
You must be signed in to change notification settings - Fork 20
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
10 changed files
with
735 additions
and
9 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ members = [ | |
|
||
# ROFL. | ||
"rofl-utils", | ||
"rofl-appd", | ||
"rofl-containers", | ||
|
||
# Test runtimes. | ||
|
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 = "rofl-appd" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
# Oasis SDK. | ||
oasis-runtime-sdk = { path = "../runtime-sdk", features = ["tdx"] } | ||
|
||
# Third party. | ||
rocket = { version = "0.5.1", features = ["json"] } | ||
|
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 @@ | ||
//! REST API daemon accessible by ROFL apps. | ||
mod routes; | ||
mod state; | ||
|
||
use std::sync::Arc; | ||
|
||
use rocket::{figment::Figment, routes}; | ||
|
||
use oasis_runtime_sdk::modules::rofl::app::{App, Environment}; | ||
|
||
/// Start the REST API server. | ||
pub async fn start<A>(address: &str, env: Environment<A>) -> Result<(), rocket::Error> | ||
where | ||
A: App, | ||
{ | ||
let env: Arc<dyn state::Env> = Arc::new(state::EnvImpl::new(env)); | ||
let cfg = Figment::new().join(("address", address)); | ||
|
||
rocket::custom(cfg) | ||
.manage(env) | ||
.mount("/rofl/v1/app", routes![routes::app::id,]) | ||
.mount("/rofl/v1/keys", routes![routes::keys::generate,]) | ||
.launch() | ||
.await?; | ||
|
||
Ok(()) | ||
} |
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,10 @@ | ||
use std::sync::Arc; | ||
|
||
use rocket::State; | ||
|
||
use crate::state::Env; | ||
|
||
#[rocket::get("/id")] | ||
pub fn id(env: &State<Arc<dyn Env>>) -> String { | ||
env.app_id().to_bech32() | ||
} |
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,11 @@ | ||
use std::sync::Arc; | ||
|
||
use rocket::State; | ||
|
||
use crate::state::Env; | ||
|
||
/// Key generation endpoint. | ||
#[rocket::post("/generate")] | ||
pub fn generate(env: &State<Arc<dyn Env>>) -> &'static str { | ||
"TODO" | ||
} |
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,2 @@ | ||
pub mod app; | ||
pub mod keys; |
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 @@ | ||
use oasis_runtime_sdk::modules::rofl::app::{App, AppId, Environment}; | ||
|
||
pub trait Env: Send + Sync { | ||
fn app_id(&self) -> AppId; | ||
} | ||
|
||
pub(crate) struct EnvImpl<A: App> { | ||
env: Environment<A>, | ||
} | ||
|
||
impl<A: App> EnvImpl<A> { | ||
pub fn new(env: Environment<A>) -> Self { | ||
Self { env } | ||
} | ||
} | ||
|
||
impl<A: App> Env for EnvImpl<A> { | ||
fn app_id(&self) -> AppId { | ||
A::id() | ||
} | ||
} |
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