You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Endpoint where the front-end assets are hosted
@@ -55,12 +55,15 @@ pub struct Opts {
55
55
/// Path for atomic data config directory. Defaults to "~/.config/atomic/""
56
56
#[clap(long, env = "ATOMIC_CONFIG_DIR")]
57
57
pubconfig_dir:Option<PathBuf>,
58
-
/// When enabled, it allows POSTing to the /search endpoint
58
+
/// CAUTION: Makes data public on the `/search` endpoint. When enabled, it allows POSTing to the /search endpoint and returns search results as single triples, without performing authentication checks. See https://github.com/joepio/atomic-data-rust/blob/master/server/rdf-search.md
59
59
#[clap(long, env = "ATOMIC_RDF_SEARCH")]
60
60
pubrdf_search:bool,
61
-
/// When enabled, previous versions of resources are removed from the search index when updated.
61
+
/// By default, Atomic-Server keeps previous verions of resources indexed in Search. When enabling this flag, previous versions of resources are removed from the search index when their values are updated.
results_resource.set_propval(urls::DESCRIPTION.into(), atomic_lib::Value::Markdown("Full text-search endpoint. You can use the keyword `AND` and `OR`, or use `\"` for advanced searches. ".into()), store)?;
139
138
results_resource.set_propval(
@@ -147,22 +146,28 @@ pub async fn search_query(
147
146
store,
148
147
)?;
149
148
150
-
if return_subjects {
149
+
if appstate.config.opts.rdf_search{
150
+
// Always return all subjects, don't do authentication
// Default case: return full resources, do authentication
153
154
letmut resources:Vec<Resource> = Vec::new();
155
+
156
+
let for_agent = crate::helpers::get_client_agent(req.headers(),&appstate, subject)?;
154
157
for s in subjects {
155
-
// TODO: use authentication, allow for non-public search
156
-
let r = store.get_resource_extended(&s,true,Some(atomic_lib::authentication::PUBLIC_AGENT.into()))
157
-
.map_err(|e| format!("Failed to construct search results, because one of the Subjects cannot be returned. Try again with the `&subjects=true` query parameter. Error: {}", e))?;
158
-
resources.push(r);
158
+
log::info!("Subject in search result: {}", s);
159
+
match store.get_resource_extended(&s,true, for_agent.clone()){
_missing => Err("Missing authentication headers. You need `x-atomic-public-key`, `x-atomic-signature`, `x-atomic-agent` and `x-atomic-timestamp` for authentication checks.".into()),
55
55
}
56
56
}
57
+
58
+
/// Checks for authentication headers and returns the agent's subject if everything is well.
59
+
/// Skips these checks in public_mode.
60
+
pubfnget_client_agent(
61
+
headers:&HeaderMap,
62
+
appstate:&AppState,
63
+
requested_subject:String,
64
+
) -> AtomicServerResult<Option<String>>{
65
+
if appstate.config.opts.public_mode{
66
+
returnOk(None);
67
+
}
68
+
// Authentication check. If the user has no headers, continue with the Public Agent.
69
+
let auth_header_values = get_auth_headers(headers, requested_subject)?;
70
+
let for_agent = atomic_lib::authentication::get_agent_from_headers_and_check(
0 commit comments