|
1 | 1 | use core::time::Duration;
|
2 |
| -use minicbor::Decoder; |
3 | 2 | use tracing::trace;
|
4 | 3 |
|
5 | 4 | use crate::authenticator::credential_issuer::CredentialIssuer;
|
6 | 5 | use crate::authenticator::direct::AccountAuthorityInfo;
|
7 | 6 | use crate::authenticator::AuthorityMembersRepository;
|
8 | 7 | use ockam::identity::{Credentials, Identifier, IdentitiesAttributes};
|
9 |
| -use ockam_core::api::{Method, RequestHeader, Response}; |
| 8 | +use ockam_core::api::{Method, Request, Response}; |
10 | 9 | use ockam_core::compat::boxed::Box;
|
11 | 10 | use ockam_core::compat::sync::Arc;
|
12 | 11 | use ockam_core::compat::vec::Vec;
|
@@ -49,41 +48,43 @@ impl CredentialIssuerWorker {
|
49 | 48 | #[ockam_core::worker]
|
50 | 49 | impl Worker for CredentialIssuerWorker {
|
51 | 50 | type Context = Context;
|
52 |
| - type Message = Vec<u8>; |
| 51 | + type Message = Request<Vec<u8>>; |
53 | 52 |
|
54 | 53 | async fn handle_message(&mut self, c: &mut Context, m: Routed<Self::Message>) -> Result<()> {
|
55 | 54 | let secure_channel_info = match SecureChannelLocalInfo::find_info(m.local_message()) {
|
56 | 55 | Ok(secure_channel_info) => secure_channel_info,
|
57 | 56 | Err(_e) => {
|
58 |
| - let resp = Response::bad_request_no_request("secure channel required").to_vec()?; |
| 57 | + let resp = |
| 58 | + Response::bad_request_no_request("secure channel required").into_vec()?; |
59 | 59 | c.send(m.return_route().clone(), resp).await?;
|
60 | 60 | return Ok(());
|
61 | 61 | }
|
62 | 62 | };
|
63 | 63 |
|
64 | 64 | let from = Identifier::from(secure_channel_info.their_identifier());
|
65 | 65 | let return_route = m.return_route().clone();
|
66 |
| - let body = m.into_body()?; |
67 |
| - let mut dec = Decoder::new(&body); |
68 |
| - let req: RequestHeader = dec.decode()?; |
| 66 | + let request = m.into_body()?; |
| 67 | + let header = request.header(); |
69 | 68 | trace! {
|
70 | 69 | target: "credential_issuer",
|
71 | 70 | from = %from,
|
72 |
| - id = %req.id(), |
73 |
| - method = ?req.method(), |
74 |
| - path = %req.path(), |
75 |
| - body = %req.has_body(), |
| 71 | + id = %header.id(), |
| 72 | + method = ?header.method(), |
| 73 | + path = %header.path(), |
| 74 | + body = %header.has_body(), |
76 | 75 | "request"
|
77 | 76 | }
|
78 |
| - let res = match (req.method(), req.path()) { |
| 77 | + let res = match (header.method(), header.path()) { |
79 | 78 | (Some(Method::Post), "/") | (Some(Method::Post), "/credential") => {
|
80 | 79 | match self.credential_issuer.issue_credential(&from).await {
|
81 |
| - Ok(Some(crd)) => Response::ok().with_headers(&req).body(crd).to_vec()?, |
82 |
| - Ok(None) => Response::forbidden(&req, "unauthorized member").to_vec()?, |
83 |
| - Err(error) => Response::internal_error(&req, &error.to_string()).to_vec()?, |
| 80 | + Ok(Some(crd)) => Response::ok().with_headers(header).body(crd).into_vec()?, |
| 81 | + Ok(None) => Response::forbidden(header, "unauthorized member").into_vec()?, |
| 82 | + Err(error) => { |
| 83 | + Response::internal_error(header, &error.to_string()).into_vec()? |
| 84 | + } |
84 | 85 | }
|
85 | 86 | }
|
86 |
| - _ => Response::unknown_path(&req).to_vec()?, |
| 87 | + _ => Response::unknown_path(header).into_vec()?, |
87 | 88 | };
|
88 | 89 |
|
89 | 90 | c.send(return_route, res).await
|
|
0 commit comments