Skip to content
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/add findex redis v7 #20

Merged
merged 1 commit into from
Jan 31, 2025
Merged

Conversation

HatemMn
Copy link
Collaborator

@HatemMn HatemMn commented Dec 3, 2024

  • Upgrade findex to the v7 version but keep the same usages of the server
  • Purge cloudproof : delete all cloudproof imports and references, replacing them with direct import from findex repo when necessary
  • Make sure the DB operations are atomic and asyncronous. For reference, a PR is made on the redis crate : Add transaction_async function redis-rs/redis-rs#1485
  • Minor coding style updates
  • Create a serialization for findex structs <=> byte streams. Write unit tests for those operations. All this is centralized under crate/structs . This will be optimized later on : Deserializer, Serializer #29

@HatemMn HatemMn changed the base branch from develop to reuse_cli December 3, 2024 13:06
@HatemMn HatemMn self-assigned this Dec 3, 2024
@HatemMn HatemMn force-pushed the feat/add_findex_redis_v7 branch 2 times, most recently from a5126b4 to 9f5de93 Compare December 3, 2024 16:22
Base automatically changed from reuse_cli to findex_v6 December 5, 2024 12:09
Base automatically changed from findex_v6 to develop December 9, 2024 14:24
@HatemMn HatemMn force-pushed the feat/add_findex_redis_v7 branch from 474cad4 to cc4b02f Compare December 17, 2024 15:21
}

#[allow(clippy::indexing_slicing)]
fn parse_entries(s: &str) -> CliResult<EncryptedEntries> {
Copy link
Collaborator Author

@HatemMn HatemMn Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm me that this is the right way to parse findex result. It works yes, but idk if my implementation is case specefic or would work on other datasets

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tbrezot what's your opinion abt this function ?

@HatemMn HatemMn force-pushed the feat/add_findex_redis_v7 branch 2 times, most recently from 5bb491c to d5bf147 Compare December 27, 2024 18:26
Copy link
Contributor

@tbrezot tbrezot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many todos, unnecessary clones and "tooling" diffs that I would have preferred not to see here: keep functional changes separate to ease reviewing.

This first review will be followed by a more in-depth one when I have time.

Cargo.toml Outdated Show resolved Hide resolved
crate/cli/src/actions/findex/search.rs Outdated Show resolved Hide resolved
crate/server/src/database/redis/findex.rs Outdated Show resolved Hide resolved
crate/server/src/error/server.rs Outdated Show resolved Hide resolved
crate/cli/src/commands.rs Outdated Show resolved Hide resolved
crate/server/src/routes/utils.rs Outdated Show resolved Hide resolved
cosmian_crypto_core = { workspace = true, features = ["ser"] }
cosmian_findex = { workspace = true }
cosmian_findex_config = { path = "../config" }
rand = "0.8.5"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is rand used for ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests

documentation/build_pdf.sh Outdated Show resolved Hide resolved
crate/server/src/database/redis/permissions.rs Outdated Show resolved Hide resolved
crate/server/src/database/redis/permissions.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@Manuthor Manuthor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partial review only

.rustfmt.toml Outdated Show resolved Hide resolved
.github/scripts/cargo_build.ps1 Outdated Show resolved Hide resolved
.github/scripts/cargo_build.ps1 Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
crate/cli/src/actions/console.rs Outdated Show resolved Hide resolved
crate/cli/src/tests/datasets.rs Outdated Show resolved Hide resolved
crate/client/src/lib.rs Outdated Show resolved Hide resolved
crate/config/Cargo.toml Outdated Show resolved Hide resolved
rust-toolchain Outdated Show resolved Hide resolved
pub(crate) struct FindexServer {
pub(crate) params: ServerParams,
pub(crate) db: Box<dyn DatabaseTraits + Sync + Send>,
pub(crate) db: Redis<WORD_LENGTH>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFO : I had to take this out because batch_read and guarded write are not compatible with Box<dyn ...>

    pub(crate) db: Box<dyn DatabaseTraits + Sync + Send>,

I tried various fixes, didn't work. imo it's BR & GW that should be changed if we want to keep this as box.

Here is the error :

the trait `DatabaseTraits` cannot be made into an object
consider moving `batch_read` to another trait
consider moving `guarded_write` to another trait
only type `database::redis::instance::Redis<WORD_LENGTH>` implements the trait, consider using it directly insteadre

async fn create_index_id(&self, user_id: &str) -> FResult<Uuid> {
let redis_key = user_id.as_bytes();

let mut con = self.client.get_connection()?;
// let mut con = self.client.get_connection()?;
let mut con: redis::aio::ConnectionManager = self.memory.manager.clone();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more need to get the connection "out" of the ConnectionManager. The ConnectionManager implements ConnectionLike trait and can be used directly to execute Redis commands. It handles the connection management internally.

pipe.atomic()
.query_async::<()>(&mut self.memory.manager.clone())
.await
.map_err(FindexServerError::from)?;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing let _:() is a fix for this error :


error: this function depends on never type fallback being `()`
  --> crate/server/src/database/redis/permissions.rs:66:5
   |
66 |     #[instrument(ret(Display), err, skip(self), level = "trace")]
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
   = help: specify the types explicitly
note: in edition 2024, the requirement `!: FromRedisValue` will fail
  --> crate/server/src/database/redis/permissions.rs:79:18
   |
79 |                 .query_async(&mut con_manager)
   |                  ^^^^^^^^^^^
note: the lint level is defined here
  --> crate/server/src/lib.rs:7:5
   |
7  |     future_incompatible,
   |     ^^^^^^^^^^^^^^^^^^^
   = note: `#[deny(dependency_on_unit_never_type_fallback)]` implied by `#[deny(future_incompatible)]`
   = note: this error originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)


@HatemMn HatemMn force-pushed the feat/add_findex_redis_v7 branch 3 times, most recently from d58688a to ece9476 Compare January 9, 2025 13:59
Cargo.toml Outdated Show resolved Hide resolved
crate/cli/src/commands.rs Outdated Show resolved Hide resolved
crate/client/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has to be removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we ? why ?
image

Cargo.toml Outdated
@@ -63,3 +62,5 @@ url = "2.5.4"
x509-parser = "0.16"
zeroize = { version = "1.8", default-features = false }
uuid = { version = "1.11", features = ["v4", "serde"] }
cosmian_findex = { git = "https://github.com/Cosmian/findex", branch = "feat/update_for_findex_server" }
cosmian_crypto_core = { version = "9.3.0", default-features = false }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this dep required?

Suggested change
cosmian_crypto_core = { version = "9.3.0", default-features = false }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, used here in particular crate/structs/src/findex_serialization.rs

@HatemMn HatemMn force-pushed the feat/add_findex_redis_v7 branch 2 times, most recently from ae704a7 to 558e721 Compare January 14, 2025 15:05
@HatemMn HatemMn mentioned this pull request Jan 15, 2025
5 tasks
Copy link
Collaborator Author

@HatemMn HatemMn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial response, the rest coming soon

So far looking good for tests except for the huge dataset

crate/cli/src/commands.rs Outdated Show resolved Hide resolved
@@ -88,14 +88,14 @@ impl CoreFindexActions {
#[allow(clippy::future_not_send)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not agree with this lint rule, at least in this context I don't feel it has meaning

The error :


error: passing a unit value to a function
  --> crate/cli/src/commands.rs:91:39
   |
91 |             Self::Datasets(action) => Ok(println!("{}", action.run(findex_client).await?)),
   |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
   = note: `#[deny(clippy::unit_arg)]` implied by `#[deny(clippy::complexity)]`
help: remove the semicolon from the last statement in the block
  --> /home/cosmian/.rustup/toolchains/1.83.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs:143:9
   |
143|         $crate::io::_print($crate::format_args_nl!($($arg)*))
   |
help: or move the expression in front of the call and replace it with the unit literal `()`
   |
91 ~             Self::Datasets(action) => {
92 +                 {
93 +                     $crate::io::_print($crate::format_args_nl!($($arg)*));
94 +                 };
95 +                 Ok(println!("{}", action.run(findex_client).await?))
96 ~             },

The fix clippy wants to see :

Self::Datasets(action) => {
    let result = action.run(findex_client).await?;
    println!("{}", result);
    Ok(result)
}

Repeating this multiple times, huge boilerplate, etc ...

If you agree with disabling this, mark this as resolved

crate/cli/src/actions/findex/index_or_delete.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
crate/cli/src/actions/findex/search.rs Outdated Show resolved Hide resolved
findex_parameters: FindexParameters {
key: "11223344556677889900AABBCCDDEEFF".to_owned(),
label: "My Findex label".to_owned(),
key: "11223344556677889900AABBCCDDEEFF11223344556677889900AABBCCDDEEFF".to_owned(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the same (for now) but it's supposed to be the same

})
}
/// Instantiate a Findex REST client with a specific index. See below. Do not expose this.
fn new_memory(&self, index_id: Uuid) -> FindexRestClient {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in findex terminology i'd call this a ... new memory. I mean this is how findex sees it, despite what it actually is. Hence the name

}
}
/// Instantiate a Findex REST client with a specific index.
/// Batch read and guarded write operations are defined in the findex crate and thus their signatures are not editable
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should not have been a doc comment but rather some review comment

Here is the full text :
/// Instantiate a Findex REST client with a specific index.
/// Batch read and guarded write operations are defined in the findex crate and thus their signatures are not editable
/// Ideal way to access the Some(index_id) is by having it as a field in the FindexRestClient struct
/// In the cli crate, first instantiate a base FindexRestClient and that will be used to instantiate a findex instance with a specific index
/// each time a call for Findex is needed

What I meant is that "ideally" we should have been able to pass the index_id but since the signature isn't editable, I documented my work around

crate/client/src/rest_client.rs Outdated Show resolved Hide resolved
crate/client/src/rest_client.rs Outdated Show resolved Hide resolved
@Cosmian Cosmian deleted a comment from tbrezot Jan 27, 2025
Copy link
Collaborator Author

@HatemMn HatemMn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part 2/2 done, I will still try to optimize

.pre-commit-config.yaml Outdated Show resolved Hide resolved
Comment on lines 114 to 118
let index_id = self.index_id.clone().expect(
"Unexpected error : this function should never be called while from base instance",
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To call this, instantiate_findex SHOULD be called

Read the instantiate_findex function

It calls the private new_memory function, which in turn always takes an index_id.

If index_id is underfined, a panic happens because by design it should be defined - and hence I unwrapped

Comment on lines 114 to 118
let index_id = self.index_id.clone().expect(
"Unexpected error : this function should never be called while from base instance",
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more clones btw. Mark as solved if ok

trace!("CSV line: {record:?}");
}

// Return the resulting HashMap
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if it's better with the comments i deleted

crate/cli/src/actions/findex/search.rs Outdated Show resolved Hide resolved
documentation/build_pdf.sh Outdated Show resolved Hide resolved
crate/server/src/database/redis/permissions.rs Outdated Show resolved Hide resolved
crate/cli/src/actions/findex/structs.rs Outdated Show resolved Hide resolved
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we ? why ?
image

Cargo.toml Outdated
@@ -63,3 +62,5 @@ url = "2.5.4"
x509-parser = "0.16"
zeroize = { version = "1.8", default-features = false }
uuid = { version = "1.11", features = ["v4", "serde"] }
cosmian_findex = { git = "https://github.com/Cosmian/findex", branch = "feat/update_for_findex_server" }
cosmian_crypto_core = { version = "9.3.0", default-features = false }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, used here in particular crate/structs/src/findex_serialization.rs

@HatemMn
Copy link
Collaborator Author

HatemMn commented Jan 29, 2025

#30 (comment)

@Manuthor Manuthor force-pushed the feat/add_findex_redis_v7 branch from 9991b9b to 75e514c Compare January 29, 2025 11:53
@HatemMn HatemMn force-pushed the feat/add_findex_redis_v7 branch 4 times, most recently from 086c230 to 406216a Compare January 30, 2025 20:15
@Manuthor Manuthor changed the base branch from develop to working-branch January 31, 2025 08:22
@HatemMn HatemMn force-pushed the feat/add_findex_redis_v7 branch 4 times, most recently from ea3a1f5 to 8236ed7 Compare January 31, 2025 08:51
test: a ccr test

chore: clippy

fix: redis red hat issues

fix: stop clearing DB

fix: stop clearing DB 2

fix: MAC OS problems

fix: revoke test
@HatemMn HatemMn force-pushed the feat/add_findex_redis_v7 branch from 8236ed7 to eb1f175 Compare January 31, 2025 09:26
@HatemMn HatemMn merged commit 69034cd into working-branch Jan 31, 2025
34 checks passed
Comment on lines +105 to +108
trace!("{error_prefix} Invalid discriminant flag. Expected 0 or 1, found None");
return Err(FindexServerError::InvalidRequest(
INVALID_REQUEST.to_owned(),
));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
trace!("{error_prefix} Invalid discriminant flag. Expected 0 or 1, found None");
return Err(FindexServerError::InvalidRequest(
INVALID_REQUEST.to_owned(),
));
return Err(FindexServerError::InvalidRequest(format!(
"{error_prefix} Invalid discriminant flag. Expected 0 or 1, found None"
)));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants