-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agama config load/store for "product" uses the HTTP API (#1563)
## Problem **Product** and **registration** part of the migration of the CLI from D-Bus API to HTTP API: - https://trello.com/c/hvPtBtMD/3719-5-replace-d-bus-with-http-based-clients ## Solution - Added `ProductHTTPClient` - Kept (D-Bus) `ProductClient` because it serves as the backend for the above - Added `ManagerHTTPClient`, `/api/manager/probe_sync` is called after the product changes ## Testing - Added a new unit test - Tested manually ## Screenshots No
- Loading branch information
Showing
15 changed files
with
322 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::{base_http_client::BaseHTTPClient, error::ServiceError}; | ||
|
||
pub struct ManagerHTTPClient { | ||
client: BaseHTTPClient, | ||
} | ||
|
||
impl ManagerHTTPClient { | ||
pub fn new() -> Result<Self, ServiceError> { | ||
Ok(Self { | ||
client: BaseHTTPClient::new()?, | ||
}) | ||
} | ||
|
||
pub fn new_with_base(base: BaseHTTPClient) -> Self { | ||
Self { client: base } | ||
} | ||
|
||
pub async fn probe(&self) -> Result<(), ServiceError> { | ||
// BaseHTTPClient did not anticipate POST without request body | ||
// so we pass () which is rendered as `null` | ||
self.client.post_void("/manager/probe_sync", &()).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
//! Implements support for handling the product settings | ||
|
||
mod client; | ||
mod http_client; | ||
pub mod proxies; | ||
mod settings; | ||
mod store; | ||
|
||
pub use client::{Product, ProductClient, RegistrationRequirement}; | ||
pub use crate::software::model::RegistrationRequirement; | ||
pub use client::{Product, ProductClient}; | ||
pub use http_client::ProductHTTPClient; | ||
pub use settings::ProductSettings; | ||
pub use store::ProductStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::software::model::RegistrationInfo; | ||
use crate::software::model::RegistrationParams; | ||
use crate::software::model::SoftwareConfig; | ||
use crate::{base_http_client::BaseHTTPClient, error::ServiceError}; | ||
|
||
pub struct ProductHTTPClient { | ||
client: BaseHTTPClient, | ||
} | ||
|
||
impl ProductHTTPClient { | ||
pub fn new() -> Result<Self, ServiceError> { | ||
Ok(Self { | ||
client: BaseHTTPClient::new()?, | ||
}) | ||
} | ||
|
||
pub fn new_with_base(base: BaseHTTPClient) -> Self { | ||
Self { client: base } | ||
} | ||
|
||
pub async fn get_software(&self) -> Result<SoftwareConfig, ServiceError> { | ||
self.client.get("/software/config").await | ||
} | ||
|
||
pub async fn set_software(&self, config: &SoftwareConfig) -> Result<(), ServiceError> { | ||
self.client.put_void("/software/config", config).await | ||
} | ||
|
||
/// Returns the id of the selected product to install | ||
pub async fn product(&self) -> Result<String, ServiceError> { | ||
let config = self.get_software().await?; | ||
if let Some(product) = config.product { | ||
Ok(product) | ||
} else { | ||
Ok("".to_owned()) | ||
} | ||
} | ||
|
||
/// Selects the product to install | ||
pub async fn select_product(&self, product_id: &str) -> Result<(), ServiceError> { | ||
let config = SoftwareConfig { | ||
product: Some(product_id.to_owned()), | ||
patterns: None, | ||
}; | ||
self.set_software(&config).await | ||
} | ||
|
||
pub async fn get_registration(&self) -> Result<RegistrationInfo, ServiceError> { | ||
self.client.get("/software/registration").await | ||
} | ||
|
||
/// register product | ||
pub async fn register(&self, key: &str, email: &str) -> Result<(u32, String), ServiceError> { | ||
// note RegistrationParams != RegistrationInfo, fun! | ||
let params = RegistrationParams { | ||
key: key.to_owned(), | ||
email: email.to_owned(), | ||
}; | ||
|
||
self.client.post("/software/registration", ¶ms).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.