#![cfg(feature = "digitalocean_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;
pub type Meta = super::shared::MetaObject;
pub type PageLinks = super::shared::PagesObject;
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct Pagination {
pub links: Option<PageLinks>,
}
pub type SshKeyFingerprint = String;
pub type SshKeyId = i64;
pub type SshKeyName = String;
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct SshKeys {
pub fingerprint: Option<String>,
pub id: Option<i64>,
pub name: String,
pub public_key: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct SshKeysAllResponse {
pub links: Option<PageLinks>,
pub meta: serde_json::Value,
pub ssh_keys: Option<Vec<SshKeys>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct SshKeysNewResponse {
pub ssh_key: Option<SshKeys>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct SshKeysListArgs {
pub per_page: Option<String>,
pub page: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct SshKeysCreateArgs {
pub body: SshKeys,
}
pub async fn ssh_keys_list_request<F>(
client: impl Into<super::shared::ApiClient>,
args: &SshKeysListArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<SshKeysAllResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/v2/account/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()))?;
builder = builder.query("per_page", args.per_page.as_deref());
builder = builder.query("page", args.page.as_deref());
if let Some(f) = builder_mod {
f(&mut builder);
}
super::shared::send_json(client.into(), builder.build()).await
}
pub async fn ssh_keys_create_request<F>(
client: impl Into<super::shared::ApiClient>,
args: &SshKeysCreateArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<SshKeysNewResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/v2/account/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
}