mirror of
https://github.com/amigan/rustypaste-pretty.git
synced 2024-11-21 20:09:48 -05:00
feat(config): support setting the auth token in config
This commit is contained in:
parent
53686c6c93
commit
3cc40deca0
2 changed files with 13 additions and 1 deletions
|
@ -24,6 +24,8 @@ pub struct ServerConfig {
|
|||
pub max_content_length: Byte,
|
||||
/// Storage path.
|
||||
pub upload_path: PathBuf,
|
||||
/// Authentication token.
|
||||
pub auth_token: Option<String>,
|
||||
}
|
||||
|
||||
/// Paste configuration.
|
||||
|
|
|
@ -89,7 +89,17 @@ async fn upload(
|
|||
) -> Result<HttpResponse, Error> {
|
||||
let connection = request.connection_info().clone();
|
||||
let host = connection.remote_addr().unwrap_or("unknown host");
|
||||
auth::check(host, request.headers(), env::var("AUTH_TOKEN").ok())?;
|
||||
auth::check(
|
||||
host,
|
||||
request.headers(),
|
||||
env::var("AUTH_TOKEN").ok().or(config
|
||||
.read()
|
||||
.map_err(|_| error::ErrorInternalServerError("cannot acquire config"))?
|
||||
.server
|
||||
.auth_token
|
||||
.as_ref()
|
||||
.cloned()),
|
||||
)?;
|
||||
let expiry_date = header::parse_expiry_date(request.headers())?;
|
||||
let mut urls: Vec<String> = Vec::new();
|
||||
while let Some(item) = payload.next().await {
|
||||
|
|
Loading…
Reference in a new issue