Skip to content

Commit

Permalink
Use paas-api correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
JobDoesburg committed Feb 11, 2025
1 parent b2354ce commit d889033
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "paas-client"
version = "0.5.7"
version = "0.5.8"
authors = [
"Job Doesburg <[email protected]>",
"Julian van der Horst <[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions src/pseudonym_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ impl PseudonymService {
/// If you need to preserve the order, you should call the [pseudonymize] method for each pseudonym individually. (TODO: add a feature flag to preserve order)

Check warning on line 132 in src/pseudonym_service.rs

View workflow job for this annotation

GitHub Actions / cargo test

unresolved link to `pseudonymize`
pub async fn pseudonymize_batch(
&mut self,
encrypted_pseudonyms: &Vec<EncryptedPseudonym>,
encrypted_pseudonyms: &[EncryptedPseudonym],
sessions_from: &EncryptionContexts,
domain_from: &PseudonymizationDomain,
domain_to: &PseudonymizationDomain,
) -> Vec<EncryptedPseudonym> {
if self.pep_crypto_client.is_none() {
self.init().await;
}
let mut transcrypted = encrypted_pseudonyms.clone();
let mut transcrypted = encrypted_pseudonyms.to_owned();
for transcryptor in &self.transcryptors {
transcrypted = transcryptor
.pseudonymize_batch(
Expand Down
37 changes: 31 additions & 6 deletions src/transcryptor_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use libpep::distributed::key_blinding::SessionKeyShare;
use libpep::high_level::contexts::{EncryptionContext, PseudonymizationDomain};
use libpep::high_level::data_types::EncryptedPseudonym;
use paas_api::sessions::StartSessionResponse;
use paas_api::status::{StatusResponse, SystemId};
use paas_api::status::{StatusResponse, SystemId, VersionInfo};
use paas_api::transcrypt::{
PseudonymizationBatchRequest, PseudonymizationBatchResponse, PseudonymizationRequest,
PseudonymizationResponse,
Expand All @@ -27,6 +27,7 @@ pub struct TranscryptorStatus {
pub state: TranscryptorState,
pub last_checked: Option<DateTime<Utc>>,
}

pub type AuthToken = String;

/// A client that communicates with a single Transcryptor.
Expand Down Expand Up @@ -72,16 +73,37 @@ impl TranscryptorClient {
self.session_id.clone(),
)
}
fn make_url(&self, path: &str) -> String {
format!(
"{}{}{}",
self.config.url.trim_end_matches('/'),
paas_api::paths::API_BASE,
path
)
}

fn make_scope_url(&self, scope: &str, path: &str) -> String {
format!(
"{}{}{}{}",
self.config.url.trim_end_matches('/'),
paas_api::paths::API_BASE,
scope,
path
)
}
/// Check the status of the transcryptor.
pub async fn check_status(&mut self) -> Result<(), reqwest::Error> {
let response = reqwest::Client::new()
.get(format!("{}/status", self.config.url))
.get(self.make_url(paas_api::paths::STATUS))
.header("Authorization", format!("Bearer {}", self.auth_token))
.send()
.await?;
// TODO handle errors and update status accordingly
let _session = response.json::<StatusResponse>().await?;
let status = response.json::<StatusResponse>().await?;

let client_version = VersionInfo::default();
assert!(status.version_info.is_compatible_with(&client_version)); // TODO throw error

self.status = TranscryptorStatus {
state: TranscryptorState::Online,
last_checked: Some(chrono::offset::Local::now().into()), // TODO use the time from the response
Expand All @@ -94,7 +116,10 @@ impl TranscryptorClient {
&mut self,
) -> Result<(EncryptionContext, SessionKeyShare), reqwest::Error> {
let response = reqwest::Client::new()
.post(format!("{}/sessions/start", self.config.url))
.post(self.make_scope_url(
paas_api::paths::sessions::SCOPE,
paas_api::paths::sessions::START,
))
.header("Authorization", format!("Bearer {}", self.auth_token))
.send()
.await?;
Expand Down Expand Up @@ -122,7 +147,7 @@ impl TranscryptorClient {
session_to: session_to.clone(),
};
let response = reqwest::Client::new()
.post(format!("{}/pseudonymize", self.config.url))
.post(self.make_url(paas_api::paths::transcrypt::PSEUDONYMIZE))
.header("Authorization", format!("Bearer {}", self.auth_token))
.json(&request)
.send()
Expand All @@ -148,7 +173,7 @@ impl TranscryptorClient {
session_to: session_to.clone(),
};
let response = reqwest::Client::new()
.post(format!("{}/pseudonymize_batch", self.config.url))
.get(self.make_url(paas_api::paths::transcrypt::PSEUDONYMIZE_BATCH))
.header("Authorization", format!("Bearer {}", self.auth_token))
.json(&request)
.send()
Expand Down

0 comments on commit d889033

Please sign in to comment.