wait for unlock before responding to credentials request
This commit is contained in:
1 parent
5f1ff5e4e8
commit
009eec764e
2 files changed
+47
-5
No files matched your search
@@ -148,19 +148,24 @@ async fn handle_aws_get(uri: Uri, app: AsyncApp) -> Result<Response<Full<Bytes>>
|
||||
let params: HashMap<_, _> = form_urlencoded::parse(qs).collect();
|
||||
let name = params.get("name").map(|n| n.to_string());
|
||||
let session = params.get("session").map(|s| s == "true").unwrap_or(false);
|
||||
|
||||
// we need to hang on to `name` so we can use it to retrieve the credential later
|
||||
let req = CredentialRequest::AwsGet { name: name.clone(), session };
|
||||
|
||||
let (sender, receiver) = oneshot::channel::<CredentialResponse>();
|
||||
app.update_global::<PendingRequests, _>(|pending, _cx| pending.0.push_back((req.clone(), sender)));
|
||||
app.update_global::<PendingRequests, _>(|pending, _cx| pending.0.push_back((req, sender)));
|
||||
|
||||
let resp = receiver.await.unwrap_or_else(|_| CredentialResponse::no());
|
||||
if !resp.approved {
|
||||
return Err(CreddyError::RequestDenied);
|
||||
}
|
||||
|
||||
// eventually: let session = AppSession::wait_for_unlock().await; or something like that
|
||||
let creds = app.read_global::<AppSession, _>(|session, cx| {
|
||||
let AppSession::Unlocked(db) = session else { unreachable!() };
|
||||
// it's possible to approve a request while the app is still locked, so we have to account for that
|
||||
AppSession::wait_for_unlock(&app).await;
|
||||
let creds = app.read_global::<AppSession, _>(|session, _cx| {
|
||||
let AppSession::Unlocked(db) = session else {
|
||||
unreachable!("App re-locked immediately after unlock")
|
||||
};
|
||||
db.load_aws_credential(&name.unwrap_or_else(|| "default".into()))
|
||||
})?;
|
||||
|
||||
|
||||
Reference in new issue
Block a user