]>
git.proxmox.com Git - proxmox-backup.git/blob - src/client/backup_repo.rs
5 use proxmox
::api
::const_regex
;
6 use proxmox
::api
::schema
::*;
9 /// Regular expression to parse repository URLs
10 pub BACKUP_REPO_URL_REGEX
= r
"^(?:(?:([\w@]+)@)?([\w\-_.]+):)?(\w+)$";
13 /// API schema format definition for repository URLs
14 pub const BACKUP_REPO_URL
: ApiStringFormat
= ApiStringFormat
::Pattern(&BACKUP_REPO_URL_REGEX
);
16 /// Reference remote backup locations
20 pub struct BackupRepository
{
21 /// The user name used for Authentication
23 /// The host name or IP address
25 /// The name of the datastore
29 impl BackupRepository
{
31 pub fn user(&self) -> &str {
32 if let Some(ref user
) = self.user
{
38 pub fn host(&self) -> &str {
39 if let Some(ref host
) = self.host
{
45 pub fn store(&self) -> &str {
50 impl fmt
::Display
for BackupRepository
{
51 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
52 if let Some(ref user
) = self.user
{
53 write
!(f
, "{}@{}:{}", user
, self.host(), self.store
)
54 } else if let Some(ref host
) = self.host
{
55 write
!(f
, "{}:{}", host
, self.store
)
57 write
!(f
, "{}", self.store
)
62 impl std
::str::FromStr
for BackupRepository
{
65 /// Parse a repository URL.
67 /// This parses strings like `user@host:datastore`. The `user` and
68 /// `host` parts are optional, where `host` defaults to the local
69 /// host, and `user` defaults to `root@pam`.
70 fn from_str(url
: &str) -> Result
<Self, Self::Err
> {
72 let cap
= (BACKUP_REPO_URL_REGEX
.regex_obj
)().captures(url
)
73 .ok_or_else(|| format_err
!("unable to parse repository url '{}'", url
))?
;
76 user
: cap
.get(1).map(|m
| m
.as_str().to_owned()),
77 host
: cap
.get(2).map(|m
| m
.as_str().to_owned()),
78 store
: cap
[3].to_owned(),