feat: add optional provenance
query parameter to API calls
This commit is contained in:
parent
28309cc5c6
commit
e167d58210
1 changed files with 34 additions and 15 deletions
|
@ -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::extractors::{self};
|
||||||
use crate::previews::PreviewStore;
|
use crate::previews::PreviewStore;
|
||||||
use crate::util::exec::block_background;
|
use crate::util::exec::block_background;
|
||||||
use upend::util::hash::{b58_decode, b58_encode};
|
|
||||||
use upend::util::jobs;
|
|
||||||
use actix_files::NamedFile;
|
use actix_files::NamedFile;
|
||||||
use actix_multipart::Multipart;
|
use actix_multipart::Multipart;
|
||||||
use actix_web::error::{
|
use actix_web::error::{
|
||||||
|
@ -35,6 +24,17 @@ use std::sync::Arc;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
use tracing::{debug, info, trace};
|
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;
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[cfg(feature = "desktop")]
|
#[cfg(feature = "desktop")]
|
||||||
|
@ -369,11 +369,17 @@ impl TryInto<Address> for InAddress {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct UpdateQuery {
|
||||||
|
provenance: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[put("/api/obj")]
|
#[put("/api/obj")]
|
||||||
pub async fn put_object(
|
pub async fn put_object(
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
state: web::Data<State>,
|
state: web::Data<State>,
|
||||||
payload: Either<web::Json<PutInput>, Multipart>,
|
payload: Either<web::Json<PutInput>, Multipart>,
|
||||||
|
web::Query(query): web::Query<UpdateQuery>,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
check_auth(&req, &state)?;
|
check_auth(&req, &state)?;
|
||||||
|
|
||||||
|
@ -391,7 +397,10 @@ pub async fn put_object(
|
||||||
entity,
|
entity,
|
||||||
attribute: in_entry.attribute,
|
attribute: in_entry.attribute,
|
||||||
value: in_entry.value,
|
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(),
|
timestamp: chrono::Utc::now().naive_utc(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -443,7 +452,10 @@ pub async fn put_object(
|
||||||
entity: address.clone(),
|
entity: address.clone(),
|
||||||
attribute: LABEL_ATTR.to_string(),
|
attribute: LABEL_ATTR.to_string(),
|
||||||
value: url.clone().into(),
|
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(),
|
timestamp: chrono::Utc::now().naive_utc(),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
@ -473,7 +485,10 @@ pub async fn put_object(
|
||||||
.as_secs()
|
.as_secs()
|
||||||
as f64,
|
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(),
|
timestamp: chrono::Utc::now().naive_utc(),
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
@ -552,6 +567,7 @@ pub async fn put_object_attribute(
|
||||||
state: web::Data<State>,
|
state: web::Data<State>,
|
||||||
web::Path((address, attribute)): web::Path<(Address, String)>,
|
web::Path((address, attribute)): web::Path<(Address, String)>,
|
||||||
value: web::Json<EntryValue>,
|
value: web::Json<EntryValue>,
|
||||||
|
web::Query(query): web::Query<UpdateQuery>,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
check_auth(&req, &state)?;
|
check_auth(&req, &state)?;
|
||||||
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
let connection = state.upend.connection().map_err(ErrorInternalServerError)?;
|
||||||
|
@ -569,7 +585,10 @@ pub async fn put_object_attribute(
|
||||||
entity: address,
|
entity: address,
|
||||||
attribute,
|
attribute,
|
||||||
value: value.into_inner(),
|
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(),
|
timestamp: chrono::Utc::now().naive_utc(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue