-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sessions): implementing permission revoking #699
Changes from 2 commits
b06a332
4cf2436
8fd31b1
3ddc187
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use { | ||
super::{super::HANDLER_TASK_METRICS, PermissionRevokeRequest, StoragePermissionsItem}, | ||
crate::{ | ||
error::RpcError, | ||
state::AppState, | ||
storage::irn::OperationType, | ||
utils::crypto::{disassemble_caip10, verify_ecdsa_signature}, | ||
}, | ||
axum::{ | ||
extract::{Path, State}, | ||
response::Response, | ||
Json, | ||
}, | ||
std::{sync::Arc, time::SystemTime}, | ||
wc::future::FutureExt, | ||
}; | ||
|
||
pub async fn handler( | ||
state: State<Arc<AppState>>, | ||
address: Path<String>, | ||
Json(request_payload): Json<PermissionRevokeRequest>, | ||
) -> Result<Response, RpcError> { | ||
handler_internal(state, address, request_payload) | ||
.with_metrics(HANDLER_TASK_METRICS.with_name("sessions_revoke")) | ||
.await | ||
} | ||
|
||
#[tracing::instrument(skip(state), level = "debug")] | ||
async fn handler_internal( | ||
state: State<Arc<AppState>>, | ||
Path(address): Path<String>, | ||
request_payload: PermissionRevokeRequest, | ||
) -> Result<Response, RpcError> { | ||
let irn_client = state.irn.as_ref().ok_or(RpcError::IrnNotConfigured)?; | ||
|
||
// Checking the CAIP-10 address format | ||
disassemble_caip10(&address)?; | ||
|
||
// Get the PCI object from the IRN | ||
let irn_call_start = SystemTime::now(); | ||
let storage_permissions_item = irn_client | ||
.hget(address.clone(), request_payload.pci.clone()) | ||
.await? | ||
.ok_or_else(|| RpcError::PermissionNotFound(request_payload.pci.clone()))?; | ||
geekbrother marked this conversation as resolved.
Show resolved
Hide resolved
|
||
state | ||
.metrics | ||
.add_irn_latency(irn_call_start, OperationType::Hget.into()); | ||
let storage_permissions_item = | ||
serde_json::from_str::<StoragePermissionsItem>(&storage_permissions_item)?; | ||
|
||
// Check the signature | ||
verify_ecdsa_signature( | ||
&request_payload.pci, | ||
&request_payload.signature, | ||
&storage_permissions_item.verification_key, | ||
)?; | ||
|
||
// Remove the session/permission item from the IRN | ||
let irn_call_start = SystemTime::now(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! This change should be the followup since we are using this everywhere in blockchain-api. |
||
irn_client.hdel(address, request_payload.pci).await?; | ||
state | ||
.metrics | ||
.add_irn_latency(irn_call_start, OperationType::Hdel.into()); | ||
|
||
Ok(Response::default()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to change to enum but I would go a step further and convert the enum into a string inside
add_irn_latency()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 3ddc187. Thanks!