feat: add optional provenance query parameter to API calls

This commit is contained in:
Tomáš Mládek 2023-04-23 19:09:14 +02:00
parent 28309cc5c6
commit e167d58210

View file

@ -1,17 +1,6 @@
use upend::addressing::{Address, Addressable};
use upend::common::build;
use upend::config::UpEndConfig;
use upend::database::constants::{ADDED_ATTR, LABEL_ATTR};
use upend::database::entry::{Entry, EntryValue, InvariantEntry};
use upend::database::hierarchies::{list_roots, resolve_path, UHierPath};
use upend::database::lang::Query;
use upend::database::stores::{Blob, UpStore};
use upend::database::UpEndDatabase;
use crate::extractors::{self};
use crate::previews::PreviewStore;
use crate::util::exec::block_background;
use upend::util::hash::{b58_decode, b58_encode};
use upend::util::jobs;
use actix_files::NamedFile;
use actix_multipart::Multipart;
use actix_web::error::{
@ -35,6 +24,17 @@ use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};
use tempfile::NamedTempFile;
use tracing::{debug, info, trace};
use upend::addressing::{Address, Addressable};
use upend::common::build;
use upend::config::UpEndConfig;
use upend::database::constants::{ADDED_ATTR, LABEL_ATTR};
use upend::database::entry::{Entry, EntryValue, InvariantEntry};
use upend::database::hierarchies::{list_roots, resolve_path, UHierPath};
use upend::database::lang::Query;
use upend::database::stores::{Blob, UpStore};
use upend::database::UpEndDatabase;
use upend::util::hash::{b58_decode, b58_encode};
use upend::util::jobs;
use uuid::Uuid;
#[cfg(feature = "desktop")]
@ -369,11 +369,17 @@ impl TryInto<Address> for InAddress {
}
}
#[derive(Deserialize)]
pub struct UpdateQuery {
provenance: Option<String>,
}
#[put("/api/obj")]
pub async fn put_object(
req: HttpRequest,
state: web::Data<State>,
payload: Either<web::Json<PutInput>, Multipart>,
web::Query(query): web::Query<UpdateQuery>,
) -> Result<HttpResponse, Error> {
check_auth(&req, &state)?;
@ -391,7 +397,10 @@ pub async fn put_object(
entity,
attribute: in_entry.attribute,
value: in_entry.value,
provenance: "USER API".to_string(),
provenance: match &query.provenance {
Some(s) => format!("API {}", s),
None => "API".to_string(),
},
timestamp: chrono::Utc::now().naive_utc(),
};
@ -443,7 +452,10 @@ pub async fn put_object(
entity: address.clone(),
attribute: LABEL_ATTR.to_string(),
value: url.clone().into(),
provenance: "USER API".to_string(),
provenance: match &query.provenance {
Some(s) => format!("API {}", s),
None => "API".to_string(),
},
timestamp: chrono::Utc::now().naive_utc(),
}),
};
@ -473,7 +485,10 @@ pub async fn put_object(
.as_secs()
as f64,
),
provenance: "USER API".to_string(),
provenance: match &query.provenance {
Some(s) => format!("API {}", s),
None => "API".to_string(),
},
timestamp: chrono::Utc::now().naive_utc(),
})?;
}
@ -552,6 +567,7 @@ pub async fn put_object_attribute(
state: web::Data<State>,
web::Path((address, attribute)): web::Path<(Address, String)>,
value: web::Json<EntryValue>,
web::Query(query): web::Query<UpdateQuery>,
) -> Result<HttpResponse, Error> {
check_auth(&req, &state)?;
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
@ -569,7 +585,10 @@ pub async fn put_object_attribute(
entity: address,
attribute,
value: value.into_inner(),
provenance: "USER API".to_string(),
provenance: match &query.provenance {
Some(s) => format!("API {}", s),
None => "API".to_string(),
},
timestamp: chrono::Utc::now().naive_utc(),
};