Skip to content

Commit

Permalink
fix: rename IndexAction to AddAction and flatten Findex actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuthor committed Oct 27, 2024
1 parent 7302140 commit f45e876
Show file tree
Hide file tree
Showing 52 changed files with 323 additions and 559 deletions.
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use_field_init_shorthand = true
version = "Two"

# # Controls the edition of the Rust Style Guide to use for formatting (RFC 3338)
# # Default value: "2015"
# Default value: "2015"
# style_edition = "2021"

# The following rust files listing have been made in october 2021.
Expand Down
107 changes: 17 additions & 90 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ actix-server = { version = "2.5", default-features = false }
actix-web = { version = "4.9.0", default-features = false }
base64 = "0.21"
clap = { version = "4.5", default-features = false }
cloudproof_findex = { path = "../cloudproof_rust/crates/findex" }
# cloudproof_findex = { git = "https://www.github.com/Cosmian/cloudproof_rust", branch = "feat/add_basic_findex_rest_client" }
# cloudproof_findex = { path = "../cloudproof_rust/crates/findex" }
cloudproof_findex = { git = "https://www.github.com/Cosmian/cloudproof_rust", branch = "feat/add_basic_findex_rest_client" }
der = { version = "0.7", default-features = false }
openssl = { version = "0.10", default-features = false }
pem = "3.0"
reqwest = { version = "0.11", default-features = false }
serde = "1.0"
serde_json = "1.0"
thiserror = "1.0"
tokio = { version = "1.40", default-features = false }
serde = "1.0.213"
serde_json = "1.0.132"
thiserror = "1.0.65"
tokio = { version = "1.41", default-features = false }
tracing = "0.1"
url = "2.5"
x509-parser = "0.16"
Expand Down
3 changes: 2 additions & 1 deletion crate/cli/src/actions/console.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::error::result::CliResult;
use serde::Serialize;

use crate::error::result::CliResult;

pub const KMS_CLI_FORMAT: &str = "KMS_CLI_FORMAT";
pub const CLI_DEFAULT_FORMAT: &str = "text";
pub const CLI_JSON_FORMAT: &str = "json";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
use super::FindexParameters;
use crate::{actions::console, error::result::CliResult};
use clap::Parser;
use cloudproof_findex::{
reexport::{
cosmian_crypto_core::FixedSizeCBytes,
cosmian_findex::{Data, IndexedValue, IndexedValueToKeywordsMap, Keyword, Label, UserKey},
},
Configuration, InstantiatedFindex,
};
use cosmian_findex_client::FindexClient;
use std::{
collections::{HashMap, HashSet},
fs::File,
path::PathBuf,
};

use clap::Parser;
use cloudproof_findex::reexport::cosmian_findex::{
Data, IndexedValue, IndexedValueToKeywordsMap, Keyword,
};
use cosmian_findex_client::FindexClient;
use tracing::trace;

/// Index data with Findex
use super::FindexParameters;
use crate::{
actions::{console, findex::instantiate_findex},
error::result::CliResult,
};

/// Findex: Index data.
#[derive(Parser, Debug)]
#[clap(verbatim_doc_comment)]
pub struct IndexAction {
pub struct AddAction {
#[clap(flatten)]
pub findex_parameters: FindexParameters,
pub(crate) findex_parameters: FindexParameters,

/// The path to the CSV file containing the data to index
#[clap(long)]
pub csv: PathBuf,
pub(crate) csv: PathBuf,
}

impl IndexAction {
/// Process the server version action.
impl AddAction {
/// Add keywords to be indexed with `Findex`.
///
/// # Arguments
///
Expand All @@ -41,18 +42,7 @@ impl IndexAction {
/// Returns an error if the version query fails or if there is an issue
/// writing to the console.
#[allow(clippy::future_not_send)]
pub async fn process(&self, findex_rest_client: &FindexClient) -> CliResult<()> {
let config = Configuration::Rest(
findex_rest_client.client.clone(),
findex_rest_client.server_url.clone(),
findex_rest_client.server_url.clone(),
);
let findex = InstantiatedFindex::new(config).await?;

let key = hex::decode(self.findex_parameters.key.clone())?;
let user_key = UserKey::try_from_slice(&key)?;
let label = Label::from(self.findex_parameters.label.as_str());

pub async fn process(&self, findex_rest_client: FindexClient) -> CliResult<()> {
// read the database
let mut csv_additions = Vec::new();
let file = File::open(self.csv.clone())?;
Expand All @@ -72,10 +62,11 @@ impl IndexAction {
csv_additions.iter().cloned().collect();
trace!("additions: {additions:?}");

let findex = instantiate_findex(findex_rest_client).await?;
let keywords = findex
.add(
&user_key,
&label,
&self.findex_parameters.user_key()?,
&self.findex_parameters.label(),
IndexedValueToKeywordsMap::from(additions),
)
.await?;
Expand Down
Loading

0 comments on commit f45e876

Please sign in to comment.