Compare commits
4 Commits
734602244d
...
da581f452d
Author | SHA1 | Date |
---|---|---|
_ | da581f452d | |
_ | c2299ab39a | |
_ | daec2b3887 | |
_ | 2ccd5167d9 |
|
@ -1,8 +1,8 @@
|
|||
# https://whitfin.io/speeding-up-rust-docker-builds/
|
||||
# TODO: https://stackoverflow.com/questions/57389547/how-to-define-the-context-for-a-docker-build-as-a-specific-commit-on-one-of-the
|
||||
|
||||
# rust:1.50-slim-buster
|
||||
FROM rust@sha256:5dd85eb0c60bbdea14a6ecba1f6fe4a0f5c878bcf06d2cdfae0aff3a19ed4b10 as build
|
||||
# rust:1.60-slim-buster
|
||||
FROM rust@sha256:c0f26a0b299a8a74cd87be0b4bd291d55aa292198bab1bafd906edd8665edb82 as build
|
||||
|
||||
WORKDIR /
|
||||
ENV USER root
|
||||
|
|
|
@ -143,6 +143,7 @@ pub mod file {
|
|||
pub scraper_keys: Option <Vec <ScraperKey>>,
|
||||
|
||||
pub news_url: Option <String>,
|
||||
pub hide_audit_log: Option <bool>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,6 +157,7 @@ pub struct Config {
|
|||
pub servers: HashMap <String, file::Server>,
|
||||
pub scraper_keys: HashMap <String, ScraperKey>,
|
||||
pub news_url: Option <String>,
|
||||
pub hide_audit_log: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
@ -167,6 +169,7 @@ impl Default for Config {
|
|||
servers: Default::default (),
|
||||
scraper_keys: Default::default (),
|
||||
news_url: None,
|
||||
hide_audit_log: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -195,6 +198,7 @@ impl TryFrom <file::Config> for Config {
|
|||
servers,
|
||||
scraper_keys,
|
||||
news_url: f.news_url,
|
||||
hide_audit_log: f.hide_audit_log.unwrap_or (false),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -433,6 +433,13 @@ async fn handle_audit_log (
|
|||
handlebars: Arc <Handlebars <'static>>
|
||||
) -> Result <Response <Body>, RequestError>
|
||||
{
|
||||
{
|
||||
let cfg = state.config.read ().await;
|
||||
if cfg.hide_audit_log {
|
||||
return Ok (error_reply (StatusCode::FORBIDDEN, "Forbidden")?);
|
||||
}
|
||||
}
|
||||
|
||||
let page = handle_audit_log_internal (state).await;
|
||||
|
||||
let s = handlebars.render ("audit_log", &page)?;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -67,29 +67,25 @@ fn file_server () {
|
|||
let rt = Runtime::new ().expect ("Can't create runtime");
|
||||
|
||||
rt.block_on (async {
|
||||
let file_server_root = PathBuf::from ("./");
|
||||
let files_root = PathBuf::from ("./");
|
||||
let dirs_roots = Default::default ();
|
||||
|
||||
let file_server_root = internal::FileRoots {
|
||||
files: &files_root,
|
||||
dirs: &dirs_roots,
|
||||
};
|
||||
let headers = Default::default ();
|
||||
|
||||
{
|
||||
use internal::Response::*;
|
||||
use crate::file_server::FileServerError;
|
||||
|
||||
let bad_passwords_path = "/files/src/bad_passwords.txt";
|
||||
|
||||
for (uri_path, expected) in vec! [
|
||||
("/", Root),
|
||||
("/files", NotFound),
|
||||
("/files/?", InvalidQuery),
|
||||
("/files/src", Redirect ("src/".to_string ())),
|
||||
("/files/src/?", InvalidQuery),
|
||||
(bad_passwords_path, ServeFile (internal::ServeFileParams {
|
||||
send_body: true,
|
||||
range: range::ValidParsed {
|
||||
range: 0..1_048_576,
|
||||
range_requested: false,
|
||||
},
|
||||
file: AlwaysEqual::testing_blank (),
|
||||
})),
|
||||
("/files/test/test.md", ServeFile (internal::ServeFileParams {
|
||||
send_body: true,
|
||||
range: range::ValidParsed {
|
||||
|
@ -100,7 +96,7 @@ fn file_server () {
|
|||
})),
|
||||
] {
|
||||
let resp = internal::serve_all (
|
||||
&file_server_root,
|
||||
file_server_root,
|
||||
Method::Get,
|
||||
uri_path,
|
||||
&headers,
|
||||
|
@ -117,7 +113,7 @@ fn file_server () {
|
|||
}),
|
||||
] {
|
||||
let resp = internal::serve_all (
|
||||
&file_server_root,
|
||||
file_server_root,
|
||||
Method::Get,
|
||||
uri_path,
|
||||
&headers,
|
||||
|
@ -126,35 +122,6 @@ fn file_server () {
|
|||
|
||||
checker (resp.unwrap_err ());
|
||||
}
|
||||
|
||||
let resp = internal::serve_all (
|
||||
&file_server_root,
|
||||
Method::Get,
|
||||
bad_passwords_path,
|
||||
&hashmap! {
|
||||
"range".into () => b"bytes=0-2000000".to_vec (),
|
||||
},
|
||||
None
|
||||
).await;
|
||||
|
||||
assert_eq! (resp.expect ("Should be Ok (_)"), RangeNotSatisfiable (1_048_576));
|
||||
|
||||
let resp = internal::serve_all (
|
||||
&file_server_root,
|
||||
Method::Head,
|
||||
bad_passwords_path,
|
||||
&headers,
|
||||
None
|
||||
).await;
|
||||
|
||||
assert_eq! (resp.expect ("Should be Ok (_)"), ServeFile (internal::ServeFileParams {
|
||||
send_body: false,
|
||||
range: range::ValidParsed {
|
||||
range: 0..1_048_576,
|
||||
range_requested: false,
|
||||
},
|
||||
file: AlwaysEqual::testing_blank (),
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ impl TestingServer {
|
|||
let (stop_tx, stop_rx) = oneshot::channel ();
|
||||
let task = {
|
||||
spawn (async move {
|
||||
ptth_server::run_server (config_file, stop_rx, None, None).await
|
||||
ptth_server::run_server (config_file, stop_rx, None, None, None).await
|
||||
})
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue