mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-05 17:43:33 +00:00
subscription: properly case status enum values
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
38492bde83
commit
baf31dc2d8
@ -49,11 +49,11 @@ fn register_subscription<C: HttpClient<String>>(
|
|||||||
|
|
||||||
fn parse_status(value: &str) -> SubscriptionStatus {
|
fn parse_status(value: &str) -> SubscriptionStatus {
|
||||||
match value.to_lowercase().as_str() {
|
match value.to_lowercase().as_str() {
|
||||||
"active" => SubscriptionStatus::ACTIVE,
|
"active" => SubscriptionStatus::Active,
|
||||||
"new" => SubscriptionStatus::NEW,
|
"new" => SubscriptionStatus::New,
|
||||||
"notfound" => SubscriptionStatus::NOTFOUND,
|
"notfound" => SubscriptionStatus::NotFound,
|
||||||
"invalid" => SubscriptionStatus::INVALID,
|
"invalid" => SubscriptionStatus::Invalid,
|
||||||
_ => SubscriptionStatus::INVALID,
|
_ => SubscriptionStatus::Invalid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ fn parse_register_response(
|
|||||||
) -> Result<SubscriptionInfo, Error> {
|
) -> Result<SubscriptionInfo, Error> {
|
||||||
let mut info = SubscriptionInfo {
|
let mut info = SubscriptionInfo {
|
||||||
key: Some(key),
|
key: Some(key),
|
||||||
status: SubscriptionStatus::NOTFOUND,
|
status: SubscriptionStatus::NotFound,
|
||||||
checktime: Some(checktime),
|
checktime: Some(checktime),
|
||||||
url: Some(product_url),
|
url: Some(product_url),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -97,7 +97,7 @@ fn parse_register_response(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let SubscriptionStatus::ACTIVE = info.status {
|
if let SubscriptionStatus::Active = info.status {
|
||||||
let response_raw = format!("{}{}", SHARED_KEY_DATA, challenge);
|
let response_raw = format!("{}{}", SHARED_KEY_DATA, challenge);
|
||||||
let expected = hex::encode(md5sum(response_raw.as_bytes())?);
|
let expected = hex::encode(md5sum(response_raw.as_bytes())?);
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ fn test_parse_register_response() -> Result<(), Error> {
|
|||||||
SubscriptionInfo {
|
SubscriptionInfo {
|
||||||
key: Some(key),
|
key: Some(key),
|
||||||
serverid: Some(server_id),
|
serverid: Some(server_id),
|
||||||
status: SubscriptionStatus::ACTIVE,
|
status: SubscriptionStatus::Active,
|
||||||
checktime: Some(checktime),
|
checktime: Some(checktime),
|
||||||
url: Some("https://www.proxmox.com/en/proxmox-backup-server/pricing".into()),
|
url: Some("https://www.proxmox.com/en/proxmox-backup-server/pricing".into()),
|
||||||
message: None,
|
message: None,
|
||||||
|
@ -53,7 +53,7 @@ fn parse_subscription_file(raw: &str) -> Result<Option<SubscriptionInfo>, Error>
|
|||||||
let pbs_csum = calc_csum(&encoded)?;
|
let pbs_csum = calc_csum(&encoded)?;
|
||||||
if checksum != pbs_csum.as_ref() && checksum != pve_csum.as_ref() {
|
if checksum != pbs_csum.as_ref() && checksum != pve_csum.as_ref() {
|
||||||
return Ok(Some(SubscriptionInfo {
|
return Ok(Some(SubscriptionInfo {
|
||||||
status: SubscriptionStatus::INVALID,
|
status: SubscriptionStatus::Invalid,
|
||||||
message: Some("checksum mismatch".to_string()),
|
message: Some("checksum mismatch".to_string()),
|
||||||
..info
|
..info
|
||||||
}));
|
}));
|
||||||
@ -62,7 +62,7 @@ fn parse_subscription_file(raw: &str) -> Result<Option<SubscriptionInfo>, Error>
|
|||||||
match info.key {
|
match info.key {
|
||||||
Some(ref info_key) if info_key != key => {
|
Some(ref info_key) if info_key != key => {
|
||||||
return Ok(Some(SubscriptionInfo {
|
return Ok(Some(SubscriptionInfo {
|
||||||
status: SubscriptionStatus::INVALID,
|
status: SubscriptionStatus::Invalid,
|
||||||
message: Some("subscription key mismatch".to_string()),
|
message: Some("subscription key mismatch".to_string()),
|
||||||
..info
|
..info
|
||||||
}))
|
}))
|
||||||
@ -109,7 +109,7 @@ pub fn write_subscription<P: AsRef<Path>>(
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let raw = if info.key == None || info.checktime == None {
|
let raw = if info.key == None || info.checktime == None {
|
||||||
String::new()
|
String::new()
|
||||||
} else if let SubscriptionStatus::NEW = info.status {
|
} else if let SubscriptionStatus::New = info.status {
|
||||||
format!("{}\n", info.key.as_ref().unwrap())
|
format!("{}\n", info.key.as_ref().unwrap())
|
||||||
} else {
|
} else {
|
||||||
let encoded = base64::encode(serde_json::to_string(&info)?);
|
let encoded = base64::encode(serde_json::to_string(&info)?);
|
||||||
@ -167,7 +167,7 @@ fn test_pve_compat() {
|
|||||||
let content = "pve4t-123456789a\nNx5qaBSAwkhF/o39/zPAeA\neyJrZXkiOiJwdmU0dC0xMjM0NTY3ODlhIiwibmV4dGR1ZWRhdGUiOiIwMDAwLTAwLTAwIiwic3Rh\ndHVzIjoiQWN0aXZlIiwidmFsaWRkaXJlY3RvcnkiOiI4MzAwMDAwMDAxMjM0NTY3ODlBQkNERUYw\nMDAwMDA0MiIsImNoZWNrdGltZSI6MTYwMDAwMDAwMCwicHJvZHVjdG5hbWUiOiJQcm94bW94IFZF\nIEZyZWUgVHJpYWwgU3Vic2NyaXB0aW9uIDEyIE1vbnRocyAoNCBDUFVzKSIsInJlZ2RhdGUiOiIy\nMDIyLTA0LTA3IDAwOjAwOjAwIn0=";
|
let content = "pve4t-123456789a\nNx5qaBSAwkhF/o39/zPAeA\neyJrZXkiOiJwdmU0dC0xMjM0NTY3ODlhIiwibmV4dGR1ZWRhdGUiOiIwMDAwLTAwLTAwIiwic3Rh\ndHVzIjoiQWN0aXZlIiwidmFsaWRkaXJlY3RvcnkiOiI4MzAwMDAwMDAxMjM0NTY3ODlBQkNERUYw\nMDAwMDA0MiIsImNoZWNrdGltZSI6MTYwMDAwMDAwMCwicHJvZHVjdG5hbWUiOiJQcm94bW94IFZF\nIEZyZWUgVHJpYWwgU3Vic2NyaXB0aW9uIDEyIE1vbnRocyAoNCBDUFVzKSIsInJlZ2RhdGUiOiIy\nMDIyLTA0LTA3IDAwOjAwOjAwIn0=";
|
||||||
|
|
||||||
let expected = SubscriptionInfo {
|
let expected = SubscriptionInfo {
|
||||||
status: SubscriptionStatus::ACTIVE,
|
status: SubscriptionStatus::Active,
|
||||||
serverid: Some("830000000123456789ABCDEF00000042".to_string()),
|
serverid: Some("830000000123456789ABCDEF00000042".to_string()),
|
||||||
checktime: Some(1600000000),
|
checktime: Some(1600000000),
|
||||||
key: Some("pve4t-123456789a".to_string()),
|
key: Some("pve4t-123456789a".to_string()),
|
||||||
@ -195,7 +195,7 @@ fn test_pbs_compat() {
|
|||||||
let expected = SubscriptionInfo {
|
let expected = SubscriptionInfo {
|
||||||
key: Some("pbst-123456789a".to_string()),
|
key: Some("pbst-123456789a".to_string()),
|
||||||
serverid: Some("830000000123456789ABCDEF00000042".to_string()),
|
serverid: Some("830000000123456789ABCDEF00000042".to_string()),
|
||||||
status: SubscriptionStatus::ACTIVE,
|
status: SubscriptionStatus::Active,
|
||||||
checktime: Some(1600000000),
|
checktime: Some(1600000000),
|
||||||
url: Some("https://www.proxmox.com/en/proxmox-backup-server/pricing".into()),
|
url: Some("https://www.proxmox.com/en/proxmox-backup-server/pricing".into()),
|
||||||
message: None,
|
message: None,
|
||||||
|
@ -24,29 +24,29 @@ pub enum SubscriptionStatus {
|
|||||||
// FIXME: remove?
|
// FIXME: remove?
|
||||||
/// newly set subscription, not yet checked
|
/// newly set subscription, not yet checked
|
||||||
#[serde(alias = "New")]
|
#[serde(alias = "New")]
|
||||||
NEW,
|
New,
|
||||||
/// no subscription set
|
/// no subscription set
|
||||||
#[serde(alias = "Notfound")]
|
#[serde(alias = "Notfound")]
|
||||||
NOTFOUND,
|
NotFound,
|
||||||
/// subscription set and active
|
/// subscription set and active
|
||||||
#[serde(alias = "Active")]
|
#[serde(alias = "Active")]
|
||||||
ACTIVE,
|
Active,
|
||||||
/// subscription set but invalid for this server
|
/// subscription set but invalid for this server
|
||||||
#[serde(alias = "Invalid")]
|
#[serde(alias = "Invalid")]
|
||||||
INVALID,
|
Invalid,
|
||||||
}
|
}
|
||||||
impl Default for SubscriptionStatus {
|
impl Default for SubscriptionStatus {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
SubscriptionStatus::NOTFOUND
|
SubscriptionStatus::NotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for SubscriptionStatus {
|
impl std::fmt::Display for SubscriptionStatus {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
SubscriptionStatus::NEW => write!(f, "New"),
|
SubscriptionStatus::New => write!(f, "New"),
|
||||||
SubscriptionStatus::NOTFOUND => write!(f, "NotFound"),
|
SubscriptionStatus::NotFound => write!(f, "NotFound"),
|
||||||
SubscriptionStatus::ACTIVE => write!(f, "Active"),
|
SubscriptionStatus::Active => write!(f, "Active"),
|
||||||
SubscriptionStatus::INVALID => write!(f, "Invalid"),
|
SubscriptionStatus::Invalid => write!(f, "Invalid"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,28 +145,28 @@ impl SubscriptionInfo {
|
|||||||
|
|
||||||
// allow some delta for DST changes or time syncs, 1.5h
|
// allow some delta for DST changes or time syncs, 1.5h
|
||||||
if age < -5400 {
|
if age < -5400 {
|
||||||
self.status = SubscriptionStatus::INVALID;
|
self.status = SubscriptionStatus::Invalid;
|
||||||
self.message = Some("last check date too far in the future".to_string());
|
self.message = Some("last check date too far in the future".to_string());
|
||||||
self.signature = None;
|
self.signature = None;
|
||||||
} else if age > cutoff {
|
} else if age > cutoff {
|
||||||
if let SubscriptionStatus::ACTIVE = self.status {
|
if let SubscriptionStatus::Active = self.status {
|
||||||
self.status = SubscriptionStatus::INVALID;
|
self.status = SubscriptionStatus::Invalid;
|
||||||
self.message = Some("subscription information too old".to_string());
|
self.message = Some("subscription information too old".to_string());
|
||||||
self.signature = None;
|
self.signature = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.is_signed() && self.status == SubscriptionStatus::ACTIVE {
|
if self.is_signed() && self.status == SubscriptionStatus::Active {
|
||||||
if let Some(next_due) = self.nextduedate.as_ref() {
|
if let Some(next_due) = self.nextduedate.as_ref() {
|
||||||
match parse_next_due(next_due.as_str()) {
|
match parse_next_due(next_due.as_str()) {
|
||||||
Ok(next_due) if now > next_due => {
|
Ok(next_due) if now > next_due => {
|
||||||
self.status = SubscriptionStatus::INVALID;
|
self.status = SubscriptionStatus::Invalid;
|
||||||
self.message = Some("subscription information too old".to_string());
|
self.message = Some("subscription information too old".to_string());
|
||||||
self.signature = None;
|
self.signature = None;
|
||||||
}
|
}
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
self.status = SubscriptionStatus::INVALID;
|
self.status = SubscriptionStatus::Invalid;
|
||||||
self.message = Some(format!("Failed parsing 'nextduedate' - {err}"));
|
self.message = Some(format!("Failed parsing 'nextduedate' - {err}"));
|
||||||
self.signature = None;
|
self.signature = None;
|
||||||
}
|
}
|
||||||
@ -182,17 +182,17 @@ impl SubscriptionInfo {
|
|||||||
pub fn check_server_id(&mut self) {
|
pub fn check_server_id(&mut self) {
|
||||||
match (self.serverid.as_ref(), get_hardware_address()) {
|
match (self.serverid.as_ref(), get_hardware_address()) {
|
||||||
(_, Err(err)) => {
|
(_, Err(err)) => {
|
||||||
self.status = SubscriptionStatus::INVALID;
|
self.status = SubscriptionStatus::Invalid;
|
||||||
self.message = Some(format!("Failed to obtain server ID - {err}."));
|
self.message = Some(format!("Failed to obtain server ID - {err}."));
|
||||||
self.signature = None;
|
self.signature = None;
|
||||||
}
|
}
|
||||||
(None, _) => {
|
(None, _) => {
|
||||||
self.status = SubscriptionStatus::INVALID;
|
self.status = SubscriptionStatus::Invalid;
|
||||||
self.message = Some(format!("Missing server ID."));
|
self.message = Some(format!("Missing server ID."));
|
||||||
self.signature = None;
|
self.signature = None;
|
||||||
}
|
}
|
||||||
(Some(contained), Ok(expected)) if &expected != contained => {
|
(Some(contained), Ok(expected)) if &expected != contained => {
|
||||||
self.status = SubscriptionStatus::INVALID;
|
self.status = SubscriptionStatus::Invalid;
|
||||||
self.message = Some("Server ID mismatch.".to_string());
|
self.message = Some("Server ID mismatch.".to_string());
|
||||||
self.signature = None;
|
self.signature = None;
|
||||||
}
|
}
|
||||||
@ -218,7 +218,7 @@ impl SubscriptionInfo {
|
|||||||
|
|
||||||
if self.is_signed() {
|
if self.is_signed() {
|
||||||
if let Err(err) = verify(&self) {
|
if let Err(err) = verify(&self) {
|
||||||
self.status = SubscriptionStatus::INVALID;
|
self.status = SubscriptionStatus::Invalid;
|
||||||
self.message = Some(format!("Signature validation failed - {err}"));
|
self.message = Some(format!("Signature validation failed - {err}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user