1
0
mirror of https://github.com/bitwarden/server synced 2026-02-13 15:04:03 +00:00

More consistent api types

This commit is contained in:
Matt Gibson
2026-01-21 12:50:39 -08:00
parent 8f67e249ae
commit 7cb947320b
7 changed files with 41 additions and 21 deletions

1
akd/Cargo.lock generated
View File

@@ -711,6 +711,7 @@ dependencies = [
"akd_storage",
"async-trait",
"bitwarden-akd-configuration",
"bitwarden-encoding",
"config",
"hex",
"serde",

View File

@@ -11,6 +11,7 @@ akd.workspace = true
async-trait = { workspace = true }
akd_storage = { workspace = true }
bitwarden-akd-configuration = { workspace = true }
bitwarden-encoding = { workspace = true }
config = { workspace = true }
serde = { workspace = true }
thiserror.workspace = true

View File

@@ -1,7 +1,26 @@
use akd::{directory::ReadOnlyDirectory, Directory};
use akd_storage::{AkdDatabase, VrfKeyDatabase};
use bitwarden_akd_configuration::BitwardenV1Configuration;
use serde::{Deserialize, Serialize};
pub type BitAkdDirectory = Directory<BitwardenV1Configuration, AkdDatabase, VrfKeyDatabase>;
pub type ReadOnlyBitAkdDirectory =
ReadOnlyDirectory<BitwardenV1Configuration, AkdDatabase, VrfKeyDatabase>;
#[derive(Debug, Serialize, Deserialize)]
pub struct AkdLabelB64(pub(crate) bitwarden_encoding::B64);
impl From<AkdLabelB64> for akd::AkdLabel {
fn from(label_b64: AkdLabelB64) -> Self {
akd::AkdLabel(label_b64.0.into_bytes())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AkdValueB64(pub(crate) bitwarden_encoding::B64);
impl From<AkdValueB64> for akd::AkdValue {
fn from(value_b64: AkdValueB64) -> Self {
akd::AkdValue(value_b64.0.into_bytes())
}
}

View File

@@ -1,14 +1,14 @@
use super::AppState;
use akd::{AkdLabel, AkdValue};
use akd_storage::PublishQueue;
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
use common::{AkdLabelB64, AkdValueB64};
use serde::{Deserialize, Serialize};
use tracing::{error, info, instrument};
#[derive(Debug, Serialize, Deserialize)]
pub struct PublishRequest {
pub akd_label_b64: bitwarden_encoding::B64,
pub akd_value_b64: bitwarden_encoding::B64,
pub label_b64: AkdLabelB64,
pub value_b64: AkdValueB64,
}
#[derive(Debug, Serialize)]
@@ -19,14 +19,17 @@ pub struct PublishResponse {
#[instrument(skip_all)]
pub async fn publish_handler(
State(AppState { publish_queue, .. }): State<AppState>,
Json(request): Json<PublishRequest>,
Json(PublishRequest {
label_b64,
value_b64,
}): Json<PublishRequest>,
) -> impl IntoResponse {
info!("Handling publish request");
let akd_label: AkdLabel = AkdLabel(request.akd_label_b64.into_bytes());
let akd_value: AkdValue = AkdValue(request.akd_value_b64.into_bytes());
if let Err(e) = publish_queue.enqueue(akd_label, akd_value).await {
if let Err(e) = publish_queue
.enqueue(label_b64.into(), value_b64.into())
.await
{
error!("Failed to enqueue publish request: {:?}", e);
return (
StatusCode::INTERNAL_SERVER_ERROR,

View File

@@ -1,10 +1,11 @@
use axum::{extract::State, http::StatusCode, Json};
use common::AkdLabelB64;
use serde::{Deserialize, Serialize};
use tracing::{error, info, instrument};
use crate::{
error::ReaderError,
routes::{get_epoch_hash::EpochData, lookup::AkdLabelB64, Response},
routes::{get_epoch_hash::EpochData, Response},
AppState,
};

View File

@@ -1,4 +1,5 @@
use axum::{extract::State, http::StatusCode, Json};
use common::AkdLabelB64;
use serde::{Deserialize, Serialize};
use tracing::{error, info, instrument};
@@ -10,8 +11,8 @@ use crate::{
#[derive(Debug, Serialize, Deserialize)]
pub struct KeyHistoryRequest {
pub label_b64: AkdLabelB64,
/// the label to look up encoded as an uppercase hex string
pub label: akd::AkdLabel,
pub history_params: HistoryParams,
}
@@ -45,12 +46,14 @@ pub struct HistoryData {
pub async fn key_history_handler(
State(AppState { directory, .. }): State<AppState>,
Json(KeyHistoryRequest {
label,
label_b64,
history_params,
}): Json<KeyHistoryRequest>,
) -> (StatusCode, Json<Response<HistoryData>>) {
info!("Handling get key history request");
let history_proof = directory.key_history(&label, history_params.into()).await;
let history_proof = directory
.key_history(&label_b64.into(), history_params.into())
.await;
match history_proof {
Ok((history_proof, epoch_hash)) => (

View File

@@ -1,4 +1,5 @@
use axum::{extract::State, http::StatusCode, Json};
use common::AkdLabelB64;
use serde::{Deserialize, Serialize};
use tracing::{error, info, instrument};
@@ -8,15 +9,6 @@ use crate::{
AppState,
};
#[derive(Debug, Serialize, Deserialize)]
pub struct AkdLabelB64(pub(crate) bitwarden_encoding::B64);
impl From<AkdLabelB64> for akd::AkdLabel {
fn from(label_b64: AkdLabelB64) -> Self {
akd::AkdLabel(label_b64.0.into_bytes())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct LookupRequest {
/// the label to look up encoded as base64