Skip to content

Commit

Permalink
Merge pull request #16 from unbekanntes-pferd/features/0.7.0
Browse files Browse the repository at this point in the history
features/0.7.0
  • Loading branch information
unbekanntes-pferd authored Mar 22, 2024
2 parents dbb3bf4 + 68e9339 commit 6934062
Show file tree
Hide file tree
Showing 39 changed files with 1,075 additions and 911 deletions.
38 changes: 19 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dco3"
version = "0.6.1"
version = "0.7.0"
edition = "2021"
authors = ["Octavio Simone"]
repository = "https://github.com/unbekanntes-pferd/dco3"
Expand All @@ -14,41 +14,41 @@ description = "Async API wrapper for DRACOON in Rust."


[dependencies]
# HTTP client
reqwest = {version = "0.11.22", features = ["json", "stream"]}
reqwest-middleware = "0.2.3"
reqwest-retry = "0.3.0"
# HTTP client (currently pinned at 0.11.27 due to reqwest-retry and reqwest-middleware)
reqwest = {version = "0.11.27", features = ["json", "stream"]}
reqwest-middleware = "0.2.5"
reqwest-retry = "0.4.0"

# crypto
dco3_crypto = "0.5.1"
dco3_crypto = "0.6.0"

# async runtime and utils
tokio = { version = "1.33.0", features = ["full"] }
tokio-util = { version = "0.7.9", features = ["full"] }
async-trait = "0.1.74"
tokio = { version = "1", features = ["full"] }
tokio-util = { version = "0.7.10", features = ["full"] }
async-trait = "0.1.78"
async-stream = "0.3.5"
futures-util = "0.3.28"
futures-util = "0.3.30"
bytes = "1.5.0"

# parsing
serde = { version = "1.0.189", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
serde-xml-rs = "0.6.0"
serde_json = "1.0.107"
serde_json = "1"

# error handling
thiserror = "1.0.49"
retry-policies = "0.2.1"
thiserror = "1"
retry-policies = "0.3.0"

# logging and tracing
tracing = "0.1.39"
tracing = "0.1.40"

# utils
url = "2.4.1"
base64 = "0.21.4"
chrono = "0.4.31"
url = "2.5.0"
base64 = "0.22.0"
chrono = "0.4.35"
dco3_derive = { path = "dco3_derive", version = "0.1.0"}


[dev-dependencies]
mockito = "1.2.0"
mockito = "1.4.0"

6 changes: 3 additions & 3 deletions src/auth/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ impl From<ReqError> for DracoonClientError {
fn from(value: ReqError) -> Self {
match value {
ReqError::Middleware(error) => {
DracoonClientError::ConnectionFailed("Error in middleware".into())
},
DracoonClientError::ConnectionFailed("Error in middleware".into())
}
ReqError::Reqwest(error) => {
if error.is_timeout() {
return DracoonClientError::ConnectionFailed("Timeout".into());
Expand All @@ -71,7 +71,7 @@ impl From<ClientError> for DracoonClientError {
if error.is_connect() {
return DracoonClientError::ConnectionFailed("Connection failed".into());
}

DracoonClientError::ConnectionFailed("Unknown".into())
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ impl Connection {

pub fn is_expired(&self) -> bool {
let now = Utc::now();
let expires_at = self.connected_at + chrono::Duration::try_seconds(self.expires_in as i64).expect("overflow creating seconds");
let expires_at = self.connected_at
+ chrono::Duration::try_seconds(self.expires_in as i64)
.expect("overflow creating seconds");
now > expires_at
}

Expand Down
79 changes: 39 additions & 40 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use async_trait::async_trait;
use reqwest::header;

use crate::constants::{
CONFIG_ALGORITHMS, CONFIG_BASE, CONFIG_INFRASTRUCTURE, CONFIG_PASSWORD_POLICIES,
CONFIG_POLICIES, DRACOON_API_PREFIX, CONFIG_DEFAULTS, CONFIG_PRODUCT_PACKAGES,
CONFIG_GENERAL, CONFIG_S3_TAGS, CONFIG_PRODUCT_PACKAGES_CURRENT, CONFIG_CLASSIFICATION_POLICIES
CONFIG_ALGORITHMS, CONFIG_BASE, CONFIG_CLASSIFICATION_POLICIES, CONFIG_DEFAULTS,
CONFIG_GENERAL, CONFIG_INFRASTRUCTURE, CONFIG_PASSWORD_POLICIES, CONFIG_POLICIES,
CONFIG_PRODUCT_PACKAGES, CONFIG_PRODUCT_PACKAGES_CURRENT, CONFIG_S3_TAGS, DRACOON_API_PREFIX,
};
use crate::utils::FromResponse;
use crate::{auth::Connected, Dracoon, DracoonClientError};
Expand All @@ -25,7 +25,9 @@ pub trait Config {

async fn get_password_policies(&self) -> Result<PasswordPoliciesConfig, DracoonClientError>;

async fn get_classification_policies(&self) -> Result<ClassificationPoliciesConfig, DracoonClientError>;
async fn get_classification_policies(
&self,
) -> Result<ClassificationPoliciesConfig, DracoonClientError>;

async fn get_algorithms(&self) -> Result<AlgorithmVersionInfoList, DracoonClientError>;

Expand Down Expand Up @@ -57,9 +59,8 @@ impl Config for Dracoon<Connected> {
}

async fn get_general_settings(&self) -> Result<GeneralSettingsInfo, DracoonClientError> {

let url_part = format!("/{DRACOON_API_PREFIX}/{CONFIG_BASE}/{CONFIG_GENERAL}");

let api_url = self.build_api_url(&url_part);

let response = self
Expand All @@ -76,9 +77,8 @@ impl Config for Dracoon<Connected> {
async fn get_infrastructure_properties(
&self,
) -> Result<InfrastructureProperties, DracoonClientError> {

let url_part = format!("/{DRACOON_API_PREFIX}/{CONFIG_BASE}/{CONFIG_INFRASTRUCTURE}");

let api_url = self.build_api_url(&url_part);

let response = self
Expand All @@ -90,28 +90,30 @@ impl Config for Dracoon<Connected> {
.await?;

InfrastructureProperties::from_response(response).await

}

async fn get_classification_policies(&self) -> Result<ClassificationPoliciesConfig, DracoonClientError> {

let url_part = format!("/{DRACOON_API_PREFIX}/{CONFIG_BASE}/{CONFIG_POLICIES}/{CONFIG_CLASSIFICATION_POLICIES}");

let api_url = self.build_api_url(&url_part);

let response = self
.client
.http
.get(api_url)
.header(header::AUTHORIZATION, self.get_auth_header().await?)
.send()
.await?;

ClassificationPoliciesConfig::from_response(response).await
async fn get_classification_policies(
&self,
) -> Result<ClassificationPoliciesConfig, DracoonClientError> {
let url_part = format!("/{DRACOON_API_PREFIX}/{CONFIG_BASE}/{CONFIG_POLICIES}/{CONFIG_CLASSIFICATION_POLICIES}");

let api_url = self.build_api_url(&url_part);

let response = self
.client
.http
.get(api_url)
.header(header::AUTHORIZATION, self.get_auth_header().await?)
.send()
.await?;

ClassificationPoliciesConfig::from_response(response).await
}

async fn get_password_policies(&self) -> Result<PasswordPoliciesConfig, DracoonClientError> {
let url_part = format!("/{DRACOON_API_PREFIX}/{CONFIG_BASE}/{CONFIG_POLICIES}/{CONFIG_PASSWORD_POLICIES}");
let url_part = format!(
"/{DRACOON_API_PREFIX}/{CONFIG_BASE}/{CONFIG_POLICIES}/{CONFIG_PASSWORD_POLICIES}"
);

let api_url = self.build_api_url(&url_part);

Expand All @@ -124,11 +126,9 @@ impl Config for Dracoon<Connected> {
.await?;

PasswordPoliciesConfig::from_response(response).await

}

async fn get_algorithms(&self) -> Result<AlgorithmVersionInfoList, DracoonClientError> {

let url_part = format!("/{DRACOON_API_PREFIX}/{CONFIG_BASE}/{CONFIG_ALGORITHMS}");

let api_url = self.build_api_url(&url_part);
Expand All @@ -142,11 +142,9 @@ impl Config for Dracoon<Connected> {
.await?;

AlgorithmVersionInfoList::from_response(response).await

}

async fn get_product_packages(&self) -> Result<ProductPackageResponseList, DracoonClientError> {

let url_part = format!("/{DRACOON_API_PREFIX}/{CONFIG_BASE}/{CONFIG_PRODUCT_PACKAGES}");

let api_url = self.build_api_url(&url_part);
Expand All @@ -160,13 +158,11 @@ impl Config for Dracoon<Connected> {
.await?;

ProductPackageResponseList::from_response(response).await

}

async fn get_current_product_package(
&self,
) -> Result<ProductPackageResponseList, DracoonClientError> {

let url_part = format!("/{DRACOON_API_PREFIX}/{CONFIG_BASE}/{CONFIG_PRODUCT_PACKAGES}/{CONFIG_PRODUCT_PACKAGES_CURRENT}");

let api_url = self.build_api_url(&url_part);
Expand All @@ -183,7 +179,6 @@ impl Config for Dracoon<Connected> {
}

async fn get_s3_tags(&self) -> Result<S3TagList, DracoonClientError> {

let url_part = format!("/{DRACOON_API_PREFIX}/{CONFIG_BASE}/{CONFIG_S3_TAGS}");

let api_url = self.build_api_url(&url_part);
Expand All @@ -197,7 +192,6 @@ impl Config for Dracoon<Connected> {
.await?;

S3TagList::from_response(response).await

}
}

Expand Down Expand Up @@ -341,9 +335,17 @@ mod tests {

classification_policies_mock.assert();

assert!(classification_policies.share_classification_policies.is_some());
let share_classification_policies = classification_policies.share_classification_policies.as_ref().unwrap();
assert_eq!(share_classification_policies.classification_requires_share_password, MinimumClassification::NoPassword);
assert!(classification_policies
.share_classification_policies
.is_some());
let share_classification_policies = classification_policies
.share_classification_policies
.as_ref()
.unwrap();
assert_eq!(
share_classification_policies.classification_requires_share_password,
MinimumClassification::NoPassword
);
}

#[tokio::test]
Expand Down Expand Up @@ -444,10 +446,7 @@ mod tests {
assert_eq!(updated_by.avatar_uuid, "string");
assert_eq!(updated_by.user_type, UserType::Internal);

assert_eq!(
encryption_password_policies.reject_dictionary_words,
None
);
assert_eq!(encryption_password_policies.reject_dictionary_words, None);
assert_eq!(encryption_password_policies.reject_user_info, Some(true));
assert_eq!(
encryption_password_policies.reject_keyboard_patterns,
Expand Down
4 changes: 1 addition & 3 deletions src/config/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ impl From<u8> for MinimumClassification {
}
}


#[derive(Debug, Deserialize, Clone, FromResponse)]
#[serde(rename_all = "camelCase")]
pub struct ClassificationPoliciesConfig {
Expand Down Expand Up @@ -128,7 +127,7 @@ pub enum CharacterRule {
#[serde(rename = "all")]
All,
#[serde(rename = "none")]
None
None,
}

#[derive(Debug, Deserialize, Clone)]
Expand Down Expand Up @@ -235,4 +234,3 @@ pub struct S3Tag {
pub struct S3TagList {
pub items: Option<Vec<S3Tag>>,
}

3 changes: 1 addition & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ pub const SHARES_UPLOAD: &str = "uploads";
// SHARES - DOWNLOAD
pub const SHARES_DOWNLOAD: &str = "downloads";


// DEFAULTS
pub const CHUNK_SIZE: usize = 1024 * 1024 * 32; // 32 MB
// concurrent requests
// concurrent requests
pub const BATCH_SIZE: usize = 20;
pub const POLLING_START_DELAY: u64 = 300;
// defines how many keys (users) distributed per file on upload
Expand Down
Loading

0 comments on commit 6934062

Please sign in to comment.