1 //! Authentication via a static ticket file
3 use std
::io
::prelude
::*;
5 use anyhow
::{bail, format_err, Error}
;
7 use proxmox_rest_server
::{ApiAuth, AuthError}
;
9 const TICKET_FILE
: &str = "/ticket";
11 pub struct StaticAuth
{
15 impl ApiAuth
for StaticAuth
{
18 headers
: &http
::HeaderMap
,
19 _method
: &hyper
::Method
,
20 ) -> Result
<String
, AuthError
> {
21 match headers
.get(hyper
::header
::AUTHORIZATION
) {
22 Some(header
) if header
.to_str().unwrap_or("") == &self.ticket
=> {
23 Ok(String
::from("root@pam"))
26 return Err(AuthError
::Generic(format_err
!(
27 "invalid file restore ticket provided"
34 pub fn ticket_auth() -> Result
<StaticAuth
, Error
> {
35 let mut ticket_file
= File
::open(TICKET_FILE
)?
;
36 let mut ticket
= String
::new();
37 let len
= ticket_file
.read_to_string(&mut ticket
)?
;
39 bail
!("invalid ticket: cannot be empty");
41 Ok(StaticAuth { ticket }
)