330 lines
12 KiB
Rust
330 lines
12 KiB
Rust
/*
|
|
* yanpm-agent
|
|
*
|
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
*
|
|
* The version of the OpenAPI document: 0.1.0
|
|
*
|
|
* Generated by: https://openapi-generator.tech
|
|
*/
|
|
|
|
use super::{configuration, Error};
|
|
use crate::apis::ContentType;
|
|
use crate::{apis::ResponseContent, models};
|
|
use async_trait::async_trait;
|
|
#[cfg(feature = "mockall")]
|
|
use mockall::automock;
|
|
use reqwest;
|
|
use serde::{de::Error as _, Deserialize, Serialize};
|
|
use std::sync::Arc;
|
|
|
|
#[cfg_attr(feature = "mockall", automock)]
|
|
#[async_trait]
|
|
pub trait NginxAgentApi: Send + Sync {
|
|
/// GET /status
|
|
///
|
|
///
|
|
async fn status(&self) -> Result<ResponseContent<StatusSuccess>, Error<StatusError>>;
|
|
|
|
/// POST /validate
|
|
///
|
|
///
|
|
async fn validate(
|
|
&self,
|
|
params: ValidateParams,
|
|
) -> Result<ResponseContent<ValidateSuccess>, Error<ValidateError>>;
|
|
|
|
/// POST /validate_and_reload
|
|
///
|
|
///
|
|
async fn validate_and_reload(
|
|
&self,
|
|
params: ValidateAndReloadParams,
|
|
) -> Result<ResponseContent<ValidateAndReloadSuccess>, Error<ValidateAndReloadError>>;
|
|
|
|
/// POST /write_config
|
|
///
|
|
///
|
|
async fn write_config(
|
|
&self,
|
|
params: WriteConfigParams,
|
|
) -> Result<ResponseContent<WriteConfigSuccess>, Error<WriteConfigError>>;
|
|
}
|
|
|
|
pub struct NginxAgentApiClient {
|
|
configuration: Arc<configuration::Configuration>,
|
|
}
|
|
|
|
impl NginxAgentApiClient {
|
|
pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
|
|
Self { configuration }
|
|
}
|
|
}
|
|
|
|
/// struct for passing parameters to the method [`NginxAgentApi::validate`]
|
|
#[derive(Clone, Debug)]
|
|
pub struct ValidateParams {
|
|
pub validate_body: models::ValidateBody,
|
|
}
|
|
|
|
/// struct for passing parameters to the method [`NginxAgentApi::validate_and_reload`]
|
|
#[derive(Clone, Debug)]
|
|
pub struct ValidateAndReloadParams {
|
|
pub validate_and_reload_body: models::ValidateAndReloadBody,
|
|
}
|
|
|
|
/// struct for passing parameters to the method [`NginxAgentApi::write_config`]
|
|
#[derive(Clone, Debug)]
|
|
pub struct WriteConfigParams {
|
|
pub write_config_body: models::WriteConfigBody,
|
|
}
|
|
|
|
#[async_trait]
|
|
impl NginxAgentApi for NginxAgentApiClient {
|
|
async fn status(&self) -> Result<ResponseContent<StatusSuccess>, Error<StatusError>> {
|
|
let local_var_configuration = &self.configuration;
|
|
|
|
let local_var_client = &local_var_configuration.client;
|
|
|
|
let local_var_uri_str = format!("{}/status", local_var_configuration.base_path);
|
|
let mut local_var_req_builder =
|
|
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
|
|
|
|
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
|
|
local_var_req_builder = local_var_req_builder
|
|
.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
|
|
}
|
|
|
|
let local_var_req = local_var_req_builder.build()?;
|
|
let local_var_resp = local_var_client.execute(local_var_req).await?;
|
|
|
|
let local_var_status = local_var_resp.status();
|
|
let local_var_content = local_var_resp.text().await?;
|
|
|
|
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
|
|
let local_var_entity: Option<StatusSuccess> =
|
|
serde_json::from_str(&local_var_content).ok();
|
|
let local_var_result = ResponseContent {
|
|
status: local_var_status,
|
|
content: local_var_content,
|
|
entity: local_var_entity,
|
|
};
|
|
Ok(local_var_result)
|
|
} else {
|
|
let local_var_entity: Option<StatusError> =
|
|
serde_json::from_str(&local_var_content).ok();
|
|
let local_var_error = ResponseContent {
|
|
status: local_var_status,
|
|
content: local_var_content,
|
|
entity: local_var_entity,
|
|
};
|
|
Err(Error::ResponseError(local_var_error))
|
|
}
|
|
}
|
|
|
|
async fn validate(
|
|
&self,
|
|
params: ValidateParams,
|
|
) -> Result<ResponseContent<ValidateSuccess>, Error<ValidateError>> {
|
|
let ValidateParams { validate_body } = params;
|
|
|
|
let local_var_configuration = &self.configuration;
|
|
|
|
let local_var_client = &local_var_configuration.client;
|
|
|
|
let local_var_uri_str = format!("{}/validate", local_var_configuration.base_path);
|
|
let mut local_var_req_builder =
|
|
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
|
|
|
|
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
|
|
local_var_req_builder = local_var_req_builder
|
|
.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
|
|
}
|
|
local_var_req_builder = local_var_req_builder.json(&validate_body);
|
|
|
|
let local_var_req = local_var_req_builder.build()?;
|
|
let local_var_resp = local_var_client.execute(local_var_req).await?;
|
|
|
|
let local_var_status = local_var_resp.status();
|
|
let local_var_content = local_var_resp.text().await?;
|
|
|
|
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
|
|
let local_var_entity: Option<ValidateSuccess> =
|
|
serde_json::from_str(&local_var_content).ok();
|
|
let local_var_result = ResponseContent {
|
|
status: local_var_status,
|
|
content: local_var_content,
|
|
entity: local_var_entity,
|
|
};
|
|
Ok(local_var_result)
|
|
} else {
|
|
let local_var_entity: Option<ValidateError> =
|
|
serde_json::from_str(&local_var_content).ok();
|
|
let local_var_error = ResponseContent {
|
|
status: local_var_status,
|
|
content: local_var_content,
|
|
entity: local_var_entity,
|
|
};
|
|
Err(Error::ResponseError(local_var_error))
|
|
}
|
|
}
|
|
|
|
async fn validate_and_reload(
|
|
&self,
|
|
params: ValidateAndReloadParams,
|
|
) -> Result<ResponseContent<ValidateAndReloadSuccess>, Error<ValidateAndReloadError>> {
|
|
let ValidateAndReloadParams {
|
|
validate_and_reload_body,
|
|
} = params;
|
|
|
|
let local_var_configuration = &self.configuration;
|
|
|
|
let local_var_client = &local_var_configuration.client;
|
|
|
|
let local_var_uri_str =
|
|
format!("{}/validate_and_reload", local_var_configuration.base_path);
|
|
let mut local_var_req_builder =
|
|
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
|
|
|
|
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
|
|
local_var_req_builder = local_var_req_builder
|
|
.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
|
|
}
|
|
local_var_req_builder = local_var_req_builder.json(&validate_and_reload_body);
|
|
|
|
let local_var_req = local_var_req_builder.build()?;
|
|
let local_var_resp = local_var_client.execute(local_var_req).await?;
|
|
|
|
let local_var_status = local_var_resp.status();
|
|
let local_var_content = local_var_resp.text().await?;
|
|
|
|
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
|
|
let local_var_entity: Option<ValidateAndReloadSuccess> =
|
|
serde_json::from_str(&local_var_content).ok();
|
|
let local_var_result = ResponseContent {
|
|
status: local_var_status,
|
|
content: local_var_content,
|
|
entity: local_var_entity,
|
|
};
|
|
Ok(local_var_result)
|
|
} else {
|
|
let local_var_entity: Option<ValidateAndReloadError> =
|
|
serde_json::from_str(&local_var_content).ok();
|
|
let local_var_error = ResponseContent {
|
|
status: local_var_status,
|
|
content: local_var_content,
|
|
entity: local_var_entity,
|
|
};
|
|
Err(Error::ResponseError(local_var_error))
|
|
}
|
|
}
|
|
|
|
async fn write_config(
|
|
&self,
|
|
params: WriteConfigParams,
|
|
) -> Result<ResponseContent<WriteConfigSuccess>, Error<WriteConfigError>> {
|
|
let WriteConfigParams { write_config_body } = params;
|
|
|
|
let local_var_configuration = &self.configuration;
|
|
|
|
let local_var_client = &local_var_configuration.client;
|
|
|
|
let local_var_uri_str = format!("{}/write_config", local_var_configuration.base_path);
|
|
let mut local_var_req_builder =
|
|
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
|
|
|
|
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
|
|
local_var_req_builder = local_var_req_builder
|
|
.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
|
|
}
|
|
local_var_req_builder = local_var_req_builder.json(&write_config_body);
|
|
|
|
let local_var_req = local_var_req_builder.build()?;
|
|
let local_var_resp = local_var_client.execute(local_var_req).await?;
|
|
|
|
let local_var_status = local_var_resp.status();
|
|
let local_var_content = local_var_resp.text().await?;
|
|
|
|
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
|
|
let local_var_entity: Option<WriteConfigSuccess> =
|
|
serde_json::from_str(&local_var_content).ok();
|
|
let local_var_result = ResponseContent {
|
|
status: local_var_status,
|
|
content: local_var_content,
|
|
entity: local_var_entity,
|
|
};
|
|
Ok(local_var_result)
|
|
} else {
|
|
let local_var_entity: Option<WriteConfigError> =
|
|
serde_json::from_str(&local_var_content).ok();
|
|
let local_var_error = ResponseContent {
|
|
status: local_var_status,
|
|
content: local_var_content,
|
|
entity: local_var_entity,
|
|
};
|
|
Err(Error::ResponseError(local_var_error))
|
|
}
|
|
}
|
|
}
|
|
|
|
/// struct for typed successes of method [`NginxAgentApi::status`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum StatusSuccess {
|
|
Status200(models::StatusResp),
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
/// struct for typed successes of method [`NginxAgentApi::validate`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum ValidateSuccess {
|
|
Status200(serde_json::Value),
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
/// struct for typed successes of method [`NginxAgentApi::validate_and_reload`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum ValidateAndReloadSuccess {
|
|
Status200(models::ValidateAndReloadResp),
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
/// struct for typed successes of method [`NginxAgentApi::write_config`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum WriteConfigSuccess {
|
|
Status200(),
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
/// struct for typed errors of method [`NginxAgentApi::status`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum StatusError {
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
/// struct for typed errors of method [`NginxAgentApi::validate`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum ValidateError {
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
/// struct for typed errors of method [`NginxAgentApi::validate_and_reload`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum ValidateAndReloadError {
|
|
UnknownValue(serde_json::Value),
|
|
}
|
|
|
|
/// struct for typed errors of method [`NginxAgentApi::write_config`]
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum WriteConfigError {
|
|
Status500(serde_json::Value),
|
|
UnknownValue(serde_json::Value),
|
|
}
|