]>
git.proxmox.com Git - proxmox-apt.git/blob - src/repositories/standard.rs
1 use std
::convert
::TryFrom
;
4 use anyhow
::{bail, Error}
;
5 use serde
::{Deserialize, Serialize}
;
7 use crate::repositories
::repository
::{
8 APTRepository
, APTRepositoryFileType
, APTRepositoryPackageType
,
11 use proxmox
::api
::api
;
16 description
: "Handle referencing a standard repository.",
21 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
22 #[serde(rename_all = "kebab-case")]
23 /// Reference to a standard repository and configuration status.
24 pub struct APTStandardRepository
{
25 /// Handle referencing a standard repository.
26 pub handle
: APTRepositoryHandle
,
28 /// Configuration status of the associated repository.
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub status
: Option
<bool
>,
32 /// Full name of the repository.
37 #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq)]
38 #[serde(rename_all = "kebab-case")]
39 /// Handles for Proxmox repositories.
40 pub enum APTRepositoryHandle
{
41 /// The enterprise repository for production use.
43 /// The repository that can be used without subscription.
45 /// The test repository.
47 /// Ceph Pacific repository.
49 /// Ceph Pacific test repository.
51 /// Ceph Octoput repository.
53 /// Ceph Octoput test repository.
57 impl TryFrom
<&str> for APTRepositoryHandle
{
60 fn try_from(string
: &str) -> Result
<Self, Error
> {
62 "enterprise" => Ok(APTRepositoryHandle
::Enterprise
),
63 "no-subscription" => Ok(APTRepositoryHandle
::NoSubscription
),
64 "test" => Ok(APTRepositoryHandle
::Test
),
65 "ceph-pacific" => Ok(APTRepositoryHandle
::CephPacific
),
66 "ceph-pacific-test" => Ok(APTRepositoryHandle
::CephPacificTest
),
67 "ceph-octopus" => Ok(APTRepositoryHandle
::CephOctopus
),
68 "ceph-octopus-test" => Ok(APTRepositoryHandle
::CephOctopusTest
),
69 _
=> bail
!("unknown repository handle '{}'", string
),
74 impl Display
for APTRepositoryHandle
{
75 fn fmt(&self, f
: &mut std
::fmt
::Formatter
<'_
>) -> std
::fmt
::Result
{
77 APTRepositoryHandle
::Enterprise
=> write
!(f
, "enterprise"),
78 APTRepositoryHandle
::NoSubscription
=> write
!(f
, "no-subscription"),
79 APTRepositoryHandle
::Test
=> write
!(f
, "test"),
80 APTRepositoryHandle
::CephPacific
=> write
!(f
, "ceph-pacific"),
81 APTRepositoryHandle
::CephPacificTest
=> write
!(f
, "ceph-pacific-test"),
82 APTRepositoryHandle
::CephOctopus
=> write
!(f
, "ceph-octopus"),
83 APTRepositoryHandle
::CephOctopusTest
=> write
!(f
, "ceph-octopus-test"),
88 impl APTRepositoryHandle
{
89 /// Get the full name of the repository.
90 pub fn name(self) -> String
{
92 APTRepositoryHandle
::Enterprise
=> "Enterprise Repository",
93 APTRepositoryHandle
::NoSubscription
=> "No-Subscription Repository",
94 APTRepositoryHandle
::Test
=> "Test Repository",
95 APTRepositoryHandle
::CephPacific
=> "Ceph Pacific Repository",
96 APTRepositoryHandle
::CephPacificTest
=> "Ceph Pacific Test Repository",
97 APTRepositoryHandle
::CephOctopus
=> "Ceph Octopus Repository",
98 APTRepositoryHandle
::CephOctopusTest
=> "Ceph Octopus Test Repository",
103 /// Get the standard file path for the repository referenced by the handle.
104 pub fn path(self, product
: &str) -> String
{
106 APTRepositoryHandle
::Enterprise
=> {
107 format
!("/etc/apt/sources.list.d/{}-enterprise.list", product
)
109 APTRepositoryHandle
::NoSubscription
=> "/etc/apt/sources.list".to_string(),
110 APTRepositoryHandle
::Test
=> "/etc/apt/sources.list".to_string(),
111 APTRepositoryHandle
::CephPacific
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
112 APTRepositoryHandle
::CephPacificTest
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
113 APTRepositoryHandle
::CephOctopus
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
114 APTRepositoryHandle
::CephOctopusTest
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
118 /// Get package type, URI and the component associated with the handle.
119 pub fn info(self, product
: &str) -> (APTRepositoryPackageType
, String
, String
) {
121 APTRepositoryHandle
::Enterprise
=> (
122 APTRepositoryPackageType
::Deb
,
123 format
!("https://enterprise.proxmox.com/debian/{}", product
),
124 format
!("{}-enterprise", product
),
126 APTRepositoryHandle
::NoSubscription
=> (
127 APTRepositoryPackageType
::Deb
,
128 format
!("http://download.proxmox.com/debian/{}", product
),
129 format
!("{}-no-subscription", product
),
131 APTRepositoryHandle
::Test
=> (
132 APTRepositoryPackageType
::Deb
,
133 format
!("http://download.proxmox.com/debian/{}", product
),
134 format
!("{}test", product
),
136 APTRepositoryHandle
::CephPacific
=> (
137 APTRepositoryPackageType
::Deb
,
138 "http://download.proxmox.com/debian/ceph-pacific".to_string(),
141 APTRepositoryHandle
::CephPacificTest
=> (
142 APTRepositoryPackageType
::Deb
,
143 "http://download.proxmox.com/debian/ceph-pacific".to_string(),
146 APTRepositoryHandle
::CephOctopus
=> (
147 APTRepositoryPackageType
::Deb
,
148 "http://download.proxmox.com/debian/ceph-octopus".to_string(),
151 APTRepositoryHandle
::CephOctopusTest
=> (
152 APTRepositoryPackageType
::Deb
,
153 "http://download.proxmox.com/debian/ceph-octopus".to_string(),
159 /// Get the standard repository referenced by the handle.
161 /// An URI in the result is not '/'-terminated (under the assumption that no valid
162 /// product name is).
163 pub fn to_repository(self, product
: &str, suite
: &str) -> APTRepository
{
164 let (package_type
, uri
, component
) = self.info(product
);
167 types
: vec
![package_type
],
169 suites
: vec
![suite
.to_string()],
170 components
: vec
![component
],
172 comment
: String
::new(),
173 file_type
: APTRepositoryFileType
::List
,