Skip to content

Commit 3271a1a

Browse files
committed
fix: rename IndexAction to AddAction and flatten Findex actions
1 parent 7302140 commit 3271a1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+319
-557
lines changed

.rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use_field_init_shorthand = true
4949
version = "Two"
5050

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

5555
# The following rust files listing have been made in october 2021.

Cargo.lock

Lines changed: 15 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ der = { version = "0.7", default-features = false }
5151
openssl = { version = "0.10", default-features = false }
5252
pem = "3.0"
5353
reqwest = { version = "0.11", default-features = false }
54-
serde = "1.0"
55-
serde_json = "1.0"
56-
thiserror = "1.0"
57-
tokio = { version = "1.40", default-features = false }
54+
serde = "1.0.213"
55+
serde_json = "1.0.132"
56+
thiserror = "1.0.65"
57+
tokio = { version = "1.41", default-features = false }
5858
tracing = "0.1"
5959
url = "2.5"
6060
x509-parser = "0.16"

crate/cli/src/actions/console.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::error::result::CliResult;
21
use serde::Serialize;
32

3+
use crate::error::result::CliResult;
4+
45
pub const KMS_CLI_FORMAT: &str = "KMS_CLI_FORMAT";
56
pub const CLI_DEFAULT_FORMAT: &str = "text";
67
pub const CLI_JSON_FORMAT: &str = "json";

crate/cli/src/actions/findex/index.rs renamed to crate/cli/src/actions/findex/add.rs

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1-
use super::FindexParameters;
2-
use crate::{actions::console, error::result::CliResult};
3-
use clap::Parser;
4-
use cloudproof_findex::{
5-
reexport::{
6-
cosmian_crypto_core::FixedSizeCBytes,
7-
cosmian_findex::{Data, IndexedValue, IndexedValueToKeywordsMap, Keyword, Label, UserKey},
8-
},
9-
Configuration, InstantiatedFindex,
10-
};
11-
use cosmian_findex_client::FindexClient;
121
use std::{
132
collections::{HashMap, HashSet},
143
fs::File,
154
path::PathBuf,
165
};
6+
7+
use clap::Parser;
8+
use cloudproof_findex::reexport::cosmian_findex::{
9+
Data, IndexedValue, IndexedValueToKeywordsMap, Keyword,
10+
};
11+
use cosmian_findex_client::FindexClient;
1712
use tracing::trace;
1813

19-
/// Index data with Findex
14+
use super::FindexParameters;
15+
use crate::{
16+
actions::{console, findex::instantiate_findex},
17+
error::result::CliResult,
18+
};
19+
20+
/// Findex: Index data.
2021
#[derive(Parser, Debug)]
2122
#[clap(verbatim_doc_comment)]
22-
pub struct IndexAction {
23+
pub struct AddAction {
2324
#[clap(flatten)]
24-
pub findex_parameters: FindexParameters,
25+
pub(crate) findex_parameters: FindexParameters,
2526

2627
/// The path to the CSV file containing the data to index
2728
#[clap(long)]
28-
pub csv: PathBuf,
29+
pub(crate) csv: PathBuf,
2930
}
3031

31-
impl IndexAction {
32-
/// Process the server version action.
32+
impl AddAction {
33+
/// Add keywords to be indexed with `Findex`.
3334
///
3435
/// # Arguments
3536
///
@@ -41,18 +42,7 @@ impl IndexAction {
4142
/// Returns an error if the version query fails or if there is an issue
4243
/// writing to the console.
4344
#[allow(clippy::future_not_send)]
44-
pub async fn process(&self, findex_rest_client: &FindexClient) -> CliResult<()> {
45-
let config = Configuration::Rest(
46-
findex_rest_client.client.clone(),
47-
findex_rest_client.server_url.clone(),
48-
findex_rest_client.server_url.clone(),
49-
);
50-
let findex = InstantiatedFindex::new(config).await?;
51-
52-
let key = hex::decode(self.findex_parameters.key.clone())?;
53-
let user_key = UserKey::try_from_slice(&key)?;
54-
let label = Label::from(self.findex_parameters.label.as_str());
55-
45+
pub async fn process(&self, findex_rest_client: FindexClient) -> CliResult<()> {
5646
// read the database
5747
let mut csv_additions = Vec::new();
5848
let file = File::open(self.csv.clone())?;
@@ -72,10 +62,11 @@ impl IndexAction {
7262
csv_additions.iter().cloned().collect();
7363
trace!("additions: {additions:?}");
7464

65+
let findex = instantiate_findex(findex_rest_client).await?;
7566
let keywords = findex
7667
.add(
77-
&user_key,
78-
&label,
68+
&self.findex_parameters.user_key()?,
69+
&self.findex_parameters.label(),
7970
IndexedValueToKeywordsMap::from(additions),
8071
)
8172
.await?;

0 commit comments

Comments
 (0)