summaryrefslogtreecommitdiffhomepage
path: root/tools/unitctl/unit-client-rs/src/unit_client.rs
diff options
context:
space:
mode:
authorAva Hahn <a.hahn@f5.com>2024-06-14 21:04:15 -0700
committerAva Hahn <110854134+avahahn@users.noreply.github.com>2024-06-18 16:21:10 -0700
commite0c15ae4575335fb079e2d33fc853a547b2380c9 (patch)
treece2a4e6eb80f79d1bb2d89c5667c71dbf11d375e /tools/unitctl/unit-client-rs/src/unit_client.rs
parentd96d583328f614c658d42f5bb0d2a0f81621327e (diff)
downloadunit-e0c15ae4575335fb079e2d33fc853a547b2380c9.tar.gz
unit-e0c15ae4575335fb079e2d33fc853a547b2380c9.tar.bz2
tools/unitctl: implement application subcommand
* application subcommand UI schema * application subcommand handler * additions to unit-client-rs to expose application API * elaborate on OpenAPI error handling * adds wasm and wasi app schemas to OpenAPI Schema * updates tools/unitctl OpenAPI library * many linter fixes * README.md updates Signed-off-by: Ava Hahn <a.hahn@f5.com>
Diffstat (limited to '')
-rw-r--r--tools/unitctl/unit-client-rs/src/unit_client.rs48
1 files changed, 45 insertions, 3 deletions
diff --git a/tools/unitctl/unit-client-rs/src/unit_client.rs b/tools/unitctl/unit-client-rs/src/unit_client.rs
index b8c73ec0..b3f07308 100644
--- a/tools/unitctl/unit-client-rs/src/unit_client.rs
+++ b/tools/unitctl/unit-client-rs/src/unit_client.rs
@@ -15,9 +15,11 @@ use serde::{Deserialize, Serialize};
use crate::control_socket_address::ControlSocket;
use unit_openapi::apis::configuration::Configuration;
-use unit_openapi::apis::{Error as OpenAPIError, StatusApi};
-use unit_openapi::apis::{ListenersApi, ListenersApiClient, StatusApiClient};
-use unit_openapi::models::{ConfigListener, Status};
+use unit_openapi::apis::{
+ ApplicationsApi, ApplicationsApiClient, AppsApi, AppsApiClient, Error as OpenAPIError, ListenersApi,
+ ListenersApiClient, StatusApi, StatusApiClient,
+};
+use unit_openapi::models::{ConfigApplication, ConfigListener, Status};
const USER_AGENT: &str = concat!("UNIT CLI/", env!("CARGO_PKG_VERSION"), "/rust");
@@ -276,6 +278,46 @@ impl UnitClient {
})
}
+ pub fn applications_api(&self) -> Box<dyn ApplicationsApi + 'static> {
+ new_openapi_client!(self, ApplicationsApiClient, ApplicationsApi)
+ }
+
+ pub async fn applications(&self) -> Result<HashMap<String, ConfigApplication>, Box<UnitClientError>> {
+ self.applications_api().get_applications().await.or_else(|err| {
+ if let OpenAPIError::Hyper(hyper_error) = err {
+ Err(Box::new(UnitClientError::new(
+ hyper_error,
+ self.control_socket.to_string(),
+ "/applications".to_string(),
+ )))
+ } else {
+ Err(Box::new(UnitClientError::OpenAPIError { source: err }))
+ }
+ })
+ }
+
+ pub async fn per_application_api(&self) -> Box<dyn AppsApi + 'static> {
+ new_openapi_client!(self, AppsApiClient, AppsApi)
+ }
+
+ pub async fn restart_application(&self, name: &String) -> Result<HashMap<String, String>, Box<UnitClientError>> {
+ self.per_application_api()
+ .await
+ .get_app_restart(name.as_str())
+ .await
+ .or_else(|err| {
+ if let OpenAPIError::Hyper(hyper_error) = err {
+ Err(Box::new(UnitClientError::new(
+ hyper_error,
+ self.control_socket.to_string(),
+ format!("/control/applications/{}/restart", name),
+ )))
+ } else {
+ Err(Box::new(UnitClientError::OpenAPIError { source: err }))
+ }
+ })
+ }
+
pub async fn is_running(&self) -> bool {
self.status().await.is_ok()
}