This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 269
Add validation for agent entry #1497
Merged
Merged
Changes from 14 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
f1bc17b
add validation function for agent_entry that is dispatched on validat…
willemolding 4f686f7
adds dispatcher to zome code and stub zome validation function
willemolding 8cd0203
adds __hdk_validate_app_entry callback to existing wasm tests
willemolding d46c2af
adds calling of non-existent AgentValidator on the zome definition
willemolding 67d35b0
add stringified error for no registered agent validator
willemolding d2cf5d8
adds macro field for adding validate_agent
willemolding 242ea6b
fmt
willemolding 13ab846
start fixing test zomes
willemolding 8f71407
add validate agent proc macro
willemolding e595dd1
add validate_agent to proc macro hdk
willemolding 1a0b234
update changelog
willemolding 8b18d56
Merge branch 'develop' into add-validation-for-agent-entry
willemolding 98d892b
fmt
willemolding 63a42e8
Merge branch 'add-validation-for-agent-entry' of https://github.com/h…
willemolding da76f4d
Merge branch 'develop' into add-validation-for-agent-entry
willemolding 6991be8
Merge branch 'develop' of https://github.com/holochain/holochain-rust…
willemolding 600d7ea
fix up hdk-proc-macro tests
willemolding 1305de5
change type formatting on hdk-proc-macro tests
willemolding 5cbc759
adds updated app spec dna to node conductor test dir
willemolding 468218b
Merge branch 'develop' into add-validation-for-agent-entry
willemolding c04d948
Merge branch 'develop' into add-validation-for-agent-entry
c8a8d80
Whitespace
aa677ba
merge develop into add-validation-for-agent-entry
zippy 206dd83
fix merge problem
zippy f59674b
Merge branch 'develop' into add-validation-for-agent-entry
zippy 6410d7b
Merge branch 'develop' into add-validation-for-agent-entry
willemolding b882210
Merge branch 'develop' into add-validation-for-agent-entry
willemolding 638173e
Merge branch 'develop' into add-validation-for-agent-entry
willemolding 40bb8e5
Merge branch 'develop' into add-validation-for-agent-entry
lucksus d125666
merge develop
willemolding aa5160d
update simple zome in app spec
willemolding d09bdc6
add app-spec test for rejecting agents via validate_agent
willemolding fff9f62
add test to proc macro tests also
willemolding 0dffcd6
Merge branch 'develop' into add-validation-for-agent-entry
willemolding File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
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,62 @@ | ||
use crate::{ | ||
context::Context, | ||
nucleus::{ | ||
actions::run_validation_callback::run_validation_callback, | ||
validation::{ValidationError, ValidationResult}, | ||
CallbackFnCall, | ||
}, | ||
}; | ||
use holochain_core_types::{ | ||
agent::AgentId, | ||
cas::content::AddressableContent, | ||
entry::Entry, | ||
validation::{EntryValidationData, ValidationData}, | ||
}; | ||
use holochain_wasm_utils::api_serialization::validation::AgentIdValidationArgs; | ||
|
||
use futures::future; | ||
use futures_util::future::FutureExt; | ||
use std::sync::Arc; | ||
|
||
pub async fn validate_agent_entry( | ||
entry: Entry, | ||
validation_data: ValidationData, | ||
context: &Arc<Context>, | ||
) -> ValidationResult { | ||
let dna = context.get_dna().expect("Callback called without DNA set!"); | ||
|
||
let agent_id = unwrap_to!(entry => Entry::AgentId); | ||
|
||
let params = AgentIdValidationArgs { | ||
validation_data: EntryValidationData::<AgentId>::Create { | ||
entry: agent_id.to_owned(), | ||
validation_data, | ||
}, | ||
}; | ||
|
||
context.log(format!("Validating agent entry with args: {:?}", params)); | ||
|
||
let results = await!(future::join_all(dna.zomes.iter().map(|(zome_name, _)| { | ||
let call = CallbackFnCall::new(&zome_name, "__hdk_validate_agent_entry", params.clone()); | ||
// Need to return a boxed future for it to work with join_all | ||
// https://users.rust-lang.org/t/the-trait-unpin-is-not-implemented-for-genfuture-error-when-using-join-all/23612/2 | ||
run_validation_callback(entry.address(), call, &context).boxed() | ||
}))); | ||
|
||
let errors: Vec<ValidationError> = results | ||
.iter() | ||
.filter_map(|r| match r { | ||
Ok(_) => None, | ||
Err(e) => Some(e.to_owned()), | ||
}) | ||
.collect(); | ||
|
||
if errors.is_empty() { | ||
context.log(format!("Validating agent entry success!: {:?}", results)); | ||
Ok(()) | ||
} else { | ||
Err(ValidationError::Error( | ||
format!("Failed to validate agent ID on a zome, {:?}", errors).into(), | ||
)) | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This file is really the only new piece of core code. The rest is fixing tests and dealing with the macros