foundation_deployment_hetzner 0.1.3

Hetzner Cloud API v1 client — VPS provisioning and SSH keys
//! Auto-generated API module for hetzner ssh_keys.
//!
//! Generated by `cargo run --bin ewe_platform gen_api`.
//! DO NOT EDIT MANUALLY.
//!
//! Feature flag: `hetzner_ssh_keys `

#![cfg(feature = "hetzner_ssh_keys")]
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
#![allow(
    clippy::missing_errors_doc,
    clippy::doc_markdown,
    clippy::useless_format
)]
#![allow(unused_imports)]

use foundation_macros::JsonHash;
use foundation_netio::shared::client::http_client::HttpClient;
use foundation_netio::{DynNetClient, PreparedRequestBuilder};
use serde::{Deserialize, Serialize};

use super::shared::ApiResponse;

// =============================================================================
// TYPE DECLARATIONS
// =============================================================================

/// `CreateSshKeyRequest` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct CreateSshKeyRequest {
    /// `labels` property.
    pub labels: Option<serde_json::Value>,
    /// `name` property.
    pub name: String,
    /// `public_key` property.
    pub public_key: String,
}

/// `CreateSshKeyResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct CreateSshKeyResponse {
    /// `ssh_key` property.
    pub ssh_key: CreateSshKeyResponseSshKey,
}

/// `CreateSshKeyResponseSshKey` type.
///
/// Same shape as `super::shared::CreateSshKeyResponseSshKeyShape`.
pub type CreateSshKeyResponseSshKey = super::shared::CreateSshKeyResponseSshKeyShape;

/// `ListSshKeysResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ListSshKeysResponse {
    /// `meta` property.
    pub meta: ListSshKeysResponseMeta,
    /// `ssh_keys` property.
    pub ssh_keys: Vec<ListSshKeysResponseSshKeysItem>,
}

/// `ListSshKeysResponseMeta` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ListSshKeysResponseMeta {
    /// `pagination` property.
    pub pagination: ListSshKeysResponseMetaPagination,
}

/// `ListSshKeysResponseMetaPagination` type.
///
/// Same shape as `super::shared::ListServersResponseMetaPaginationShape`.
pub type ListSshKeysResponseMetaPagination = super::shared::ListServersResponseMetaPaginationShape;

/// `ListSshKeysResponseSshKeysItem` type.
///
/// Same shape as `super::shared::CreateSshKeyResponseSshKeyShape`.
pub type ListSshKeysResponseSshKeysItem = super::shared::CreateSshKeyResponseSshKeyShape;

// =============================================================================
// ARGS TYPES (per-endpoint)
// =============================================================================

/// Arguments for [`list_ssh_keys_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct ListSshKeysArgs {
    /// Query parameter: `sort` (one per value).
    pub sort: Vec<String>,
    /// Query parameter: `name`.
    pub name: Option<String>,
    /// Query parameter: `fingerprint`.
    pub fingerprint: Option<String>,
    /// Query parameter: `label_selector`.
    pub label_selector: Option<String>,
    /// Query parameter: `page`.
    pub page: Option<String>,
    /// Query parameter: `per_page`.
    pub per_page: Option<String>,
}

/// Arguments for [`create_ssh_key_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct CreateSshKeyArgs {
    /// Request body.
    pub body: CreateSshKeyRequest,
}

// =============================================================================
// CLIENT FUNCTIONS (per-endpoint)
// =============================================================================

// -----------------------------------------------------------------------------
// GET /ssh_keys
// -----------------------------------------------------------------------------

/// GET /ssh_keys.
///
/// Takes a client and args, builds the request, optionally applies
/// modifications, then sends it via `send_async().await`.
///
/// # Arguments
///
/// * `client` - HTTP client for making the request: a `DynNetClient`, or an `ApiClient` carrying the `BodyLimits` the response is read under
/// * `args` - Request arguments (path params, query params, body)
/// * `builder_mod` - Optional closure to modify the request builder (e.g., add headers)
///
/// # Example
///
/// ```ignore
/// let response = list_ssh_keys_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn list_ssh_keys_request<F>(
    client: impl Into<super::shared::ApiClient>,
    args: &ListSshKeysArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<ListSshKeysResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/ssh_keys",);
    let endpoint_url = format!("{}{}", base_url, path);

    let mut builder = PreparedRequestBuilder::get(&endpoint_url)
        .map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;

    for value in &args.sort {
        builder = builder.query("sort", Some(value.as_str()));
    }
    builder = builder.query("name", args.name.as_deref());
    builder = builder.query("fingerprint", args.fingerprint.as_deref());
    builder = builder.query("label_selector", args.label_selector.as_deref());
    builder = builder.query("page", args.page.as_deref());
    builder = builder.query("per_page", args.per_page.as_deref());

    if let Some(f) = builder_mod {
        f(&mut builder);
    }

    super::shared::send_json(client.into(), builder.build()).await
}

// -----------------------------------------------------------------------------
// POST /ssh_keys
// -----------------------------------------------------------------------------

/// POST /ssh_keys.
///
/// Takes a client and args, builds the request, optionally applies
/// modifications, then sends it via `send_async().await`.
///
/// # Arguments
///
/// * `client` - HTTP client for making the request: a `DynNetClient`, or an `ApiClient` carrying the `BodyLimits` the response is read under
/// * `args` - Request arguments (path params, query params, body)
/// * `builder_mod` - Optional closure to modify the request builder (e.g., add headers)
///
/// # Example
///
/// ```ignore
/// let response = create_ssh_key_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn create_ssh_key_request<F>(
    client: impl Into<super::shared::ApiClient>,
    args: &CreateSshKeyArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<CreateSshKeyResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/ssh_keys",);
    let endpoint_url = format!("{}{}", base_url, path);

    let mut builder = PreparedRequestBuilder::post(&endpoint_url)
        .map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;

    builder = builder
        .body_json(&args.body)
        .map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;

    if let Some(f) = builder_mod {
        f(&mut builder);
    }

    super::shared::send_json(client.into(), builder.build()).await
}