Skip to content

Commit

Permalink
Use some API types from janus_messages (#87)
Browse files Browse the repository at this point in the history
* use some api types from janus_messages (github dep)

* use janus messages from crates.io

* add some serialization tests copied directly from aggregator_api tests
  • Loading branch information
jbr committed May 12, 2023
1 parent e6a4542 commit efdd6a3
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 114 deletions.
124 changes: 123 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ base64 = "0.21.0"
env_logger = "0.10.0"
fastrand = "1.9.0"
git-version = "0.3.5"
janus_messages = "0.4.8"
log = "0.4.17"
opentelemetry = { version = "0.19.0", features = ["metrics"] }
opentelemetry-prometheus = { version = "0.12.0", features = [
"prometheus-encoding",
] }
querystrong = "0.3.0"
rand = "0.8.5"
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
serde_path_to_error = "0.1.11"
Expand Down
46 changes: 22 additions & 24 deletions src/aggregator_api_mock.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::clients::aggregator_client::api_types::{
HpkeConfig, TaskCreate, TaskIds, TaskMetrics, TaskResponse,
HpkeAeadId, HpkeConfig, HpkeKdfId, HpkeKemId, HpkePublicKey, JanusDuration, JanusTime,
TaskCreate, TaskIds, TaskMetrics, TaskResponse,
};
use fastrand::alphanumeric;
use querystrong::QueryStrong;
use rand::random;
use std::iter::repeat_with;
use trillium::{Conn, Handler, Status};
use trillium_api::{api, Json};
Expand Down Expand Up @@ -34,42 +36,38 @@ async fn post_task(_: &mut Conn, Json(task_create): Json<TaskCreate>) -> Json<Ta

pub fn task_response(task_create: TaskCreate) -> TaskResponse {
TaskResponse {
task_id: repeat_with(alphanumeric).take(10).collect(),
task_id: random(),
aggregator_endpoints: task_create.aggregator_endpoints,
query_type: task_create.query_type,
vdaf: task_create.vdaf,
role: task_create.role,
vdaf_verify_keys: vec![repeat_with(alphanumeric).take(10).collect()],
max_batch_query_count: task_create.max_batch_query_count,
task_expiration: task_create.task_expiration,
task_expiration: JanusTime::from_seconds_since_epoch(task_create.task_expiration),
report_expiry_age: None,
min_batch_size: task_create.min_batch_size,
time_precision: task_create.time_precision,
tolerable_clock_skew: 60,
collector_hpke_config: HpkeConfig {
id: 1,
kem_id: 1,
kdf_id: 1,
aead_id: 1,
public_key: b"this is a public key".to_vec(),
},
time_precision: JanusDuration::from_seconds(task_create.time_precision),
tolerable_clock_skew: JanusDuration::from_seconds(60),
collector_hpke_config: random_hpke_config(),
aggregator_auth_tokens: vec![],
collector_auth_tokens: vec![],
aggregator_hpke_configs: [(
1,
HpkeConfig {
id: 1,
kem_id: 1,
kdf_id: 1,
aead_id: 1,
public_key: b"this is a public key".to_vec(),
},
)]
.into_iter()
.collect(),
aggregator_hpke_configs: std::iter::repeat_with(random_hpke_config)
.take(5)
.map(|config| (*config.id(), config))
.collect(),
}
}

pub fn random_hpke_config() -> HpkeConfig {
HpkeConfig::new(
random(),
HpkeKemId::P256HkdfSha256,
HpkeKdfId::HkdfSha512,
HpkeAeadId::Aes256Gcm,
HpkePublicKey::from(Vec::new()),
)
}

async fn task_ids(conn: &mut Conn, (): ()) -> Result<Json<TaskIds>, Status> {
let query = QueryStrong::parse(conn.querystring()).map_err(|_| Status::InternalServerError)?;
match query.get_str("pagination_token") {
Expand Down
5 changes: 2 additions & 3 deletions src/clients/aggregator_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
clients::{ClientConnExt, ClientError},
entity::NewTask,
ApiConfig,
};
use serde::{de::DeserializeOwned, Serialize};
Expand Down Expand Up @@ -62,8 +61,8 @@ impl AggregatorClient {
self.delete(&format!("/tasks/{task_id}")).await
}

pub async fn create_task(&self, task: NewTask) -> Result<TaskResponse, ClientError> {
self.post("/tasks", &TaskCreate::from(task)).await
pub async fn create_task(&self, task_create: TaskCreate) -> Result<TaskResponse, ClientError> {
self.post("/tasks", &task_create).await
}

// private below here
Expand Down
Loading

0 comments on commit efdd6a3

Please sign in to comment.