From 731032a770714641beb09c0bab9951ab07d65453 Mon Sep 17 00:00:00 2001 From: Nander Stabel Date: Tue, 19 Nov 2024 12:33:22 +0100 Subject: [PATCH] style: box `CredentialConfigurationsSupportedObject` (#143) --- agent_api_rest/src/issuance/credentials.rs | 46 ++++++++++---------- agent_issuance/src/credential/aggregate.rs | 8 ++-- agent_issuance/src/credential/command.rs | 2 +- agent_issuance/src/credential/event.rs | 2 +- agent_issuance/src/credential/queries/mod.rs | 2 +- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/agent_api_rest/src/issuance/credentials.rs b/agent_api_rest/src/issuance/credentials.rs index 41e3a56e..1aa73aa9 100644 --- a/agent_api_rest/src/issuance/credentials.rs +++ b/agent_api_rest/src/issuance/credentials.rs @@ -65,29 +65,31 @@ pub(crate) async fn credentials( let credential_id = uuid::Uuid::new_v4().to_string(); - let credential_configuration = match query_handler(SERVER_CONFIG_ID, &state.query.server_config).await { - Ok(Some(ServerConfigView { - credential_issuer_metadata: - Some(CredentialIssuerMetadata { - credential_configurations_supported, - .. - }), - .. - })) => { - if let Some(credential_configuration) = - credential_configurations_supported.get(&credential_configuration_id) - { - credential_configuration.clone() - } else { - return ( - StatusCode::NOT_FOUND, - format!("No Credential Configuration found with id: `{credential_configuration_id}`"), - ) - .into_response(); + let credential_configuration = Box::new( + match query_handler(SERVER_CONFIG_ID, &state.query.server_config).await { + Ok(Some(ServerConfigView { + credential_issuer_metadata: + Some(CredentialIssuerMetadata { + credential_configurations_supported, + .. + }), + .. + })) => { + if let Some(credential_configuration) = + credential_configurations_supported.get(&credential_configuration_id) + { + credential_configuration.clone() + } else { + return ( + StatusCode::NOT_FOUND, + format!("No Credential Configuration found with id: `{credential_configuration_id}`"), + ) + .into_response(); + } } - } - _ => return StatusCode::INTERNAL_SERVER_ERROR.into_response(), - }; + _ => return StatusCode::INTERNAL_SERVER_ERROR.into_response(), + }, + ); let command = if is_signed { CredentialCommand::CreateSignedCredential { diff --git a/agent_issuance/src/credential/aggregate.rs b/agent_issuance/src/credential/aggregate.rs index b64ee7da..a6ec1ac5 100644 --- a/agent_issuance/src/credential/aggregate.rs +++ b/agent_issuance/src/credential/aggregate.rs @@ -241,7 +241,7 @@ impl Aggregate for Credential { credential_configuration, } => { self.data.replace(data); - self.credential_configuration = credential_configuration; + self.credential_configuration = *credential_configuration; } SignedCredentialCreated { signed_credential } => { self.signed.replace(signed_credential); @@ -295,13 +295,13 @@ pub mod credential_tests { data: Data { raw: credential_subject, }, - credential_configuration: credential_configuration.clone(), + credential_configuration: Box::new(credential_configuration.clone()), }) .then_expect_events(vec![CredentialEvent::UnsignedCredentialCreated { data: Data { raw: unsigned_credential, }, - credential_configuration, + credential_configuration: Box::new(credential_configuration), }]) } @@ -327,7 +327,7 @@ pub mod credential_tests { data: Data { raw: unsigned_credential, }, - credential_configuration, + credential_configuration: Box::new(credential_configuration), }]) .when(CredentialCommand::SignCredential { subject_id: SUBJECT_KEY_DID.identifier("did:key", Algorithm::EdDSA).await.unwrap(), diff --git a/agent_issuance/src/credential/command.rs b/agent_issuance/src/credential/command.rs index f4234d56..8b2c60a0 100644 --- a/agent_issuance/src/credential/command.rs +++ b/agent_issuance/src/credential/command.rs @@ -8,7 +8,7 @@ use super::entity::Data; pub enum CredentialCommand { CreateUnsignedCredential { data: Data, - credential_configuration: CredentialConfigurationsSupportedObject, + credential_configuration: Box, }, CreateSignedCredential { signed_credential: serde_json::Value, diff --git a/agent_issuance/src/credential/event.rs b/agent_issuance/src/credential/event.rs index 51688bca..dd049ee3 100644 --- a/agent_issuance/src/credential/event.rs +++ b/agent_issuance/src/credential/event.rs @@ -9,7 +9,7 @@ pub enum CredentialEvent { // TODO: rename to `DataCredentialCreated`? UnsignedCredentialCreated { data: Data, - credential_configuration: CredentialConfigurationsSupportedObject, + credential_configuration: Box, }, SignedCredentialCreated { signed_credential: serde_json::Value, diff --git a/agent_issuance/src/credential/queries/mod.rs b/agent_issuance/src/credential/queries/mod.rs index dccea99e..93486be4 100644 --- a/agent_issuance/src/credential/queries/mod.rs +++ b/agent_issuance/src/credential/queries/mod.rs @@ -21,7 +21,7 @@ impl View for CredentialView { credential_configuration, } => { self.data.replace(data.clone()); - self.credential_configuration = credential_configuration.clone(); + self.credential_configuration = *credential_configuration.clone(); } CredentialEvent::SignedCredentialCreated { signed_credential } => { self.signed.replace(signed_credential.clone());