-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: find code to wrap legacy runtime (#675)
* refactor: find code to wrap legacy runtime * misc: update README with test instructions
- Loading branch information
Showing
12 changed files
with
198 additions
and
178 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// The few line below is what we should now codegen for legacy | ||
#[tokio::main] | ||
async fn main() { | ||
shuttle_runtime::start(loader).await; | ||
} | ||
|
||
async fn loader<S: shuttle_common::storage_manager::StorageManager>( | ||
mut factory: shuttle_runtime::ProvisionerFactory<S>, | ||
) -> shuttle_service::ShuttleRocket { | ||
use shuttle_service::ResourceBuilder; | ||
|
||
let secrets = shuttle_secrets::Secrets::new().build(&mut factory).await?; | ||
|
||
rocket(secrets).await | ||
} | ||
|
||
// Everything below this is the usual code a user will write | ||
use anyhow::anyhow; | ||
use rocket::response::status::BadRequest; | ||
use rocket::State; | ||
use shuttle_secrets::SecretStore; | ||
|
||
#[rocket::get("/secret")] | ||
async fn secret(state: &State<MyState>) -> Result<String, BadRequest<String>> { | ||
Ok(state.secret.clone()) | ||
} | ||
|
||
struct MyState { | ||
secret: String, | ||
} | ||
|
||
// #[shuttle_service::main] | ||
pub async fn rocket( | ||
// #[shuttle_secrets::Secrets] secret_store: SecretStore, | ||
secret_store: SecretStore, | ||
) -> shuttle_service::ShuttleRocket { | ||
// get secret defined in `Secrets.toml` file. | ||
let secret = if let Some(secret) = secret_store.get("MY_API_KEY") { | ||
secret | ||
} else { | ||
return Err(anyhow!("secret was not found").into()); | ||
}; | ||
|
||
let state = MyState { secret }; | ||
let rocket = rocket::build() | ||
.mount("/", rocket::routes![secret]) | ||
.manage(state); | ||
|
||
Ok(rocket) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.