/*
* Документация публичного API
*
* # Введение API Timeweb Cloud позволяет вам управлять ресурсами в облаке программным способом с использованием обычных HTTP-запросов. Множество функций, которые доступны в панели управления Timeweb Cloud, также доступны через API, что позволяет вам автоматизировать ваши собственные сценарии. В этой документации сперва будет описан общий дизайн и принципы работы API, а после этого конкретные конечные точки. Также будут приведены примеры запросов к ним. ## Запросы Запросы должны выполняться по протоколу `HTTPS`, чтобы гарантировать шифрование транзакций. Поддерживаются следующие методы запроса: |Метод|Применение| |--- |--- | |GET|Извлекает данные о коллекциях и отдельных ресурсах.| |POST|Для коллекций создает новый ресурс этого типа. Также используется для выполнения действий с конкретным ресурсом.| |PUT|Обновляет существующий ресурс.| |PATCH|Некоторые ресурсы поддерживают частичное обновление, то есть обновление только части атрибутов ресурса, в этом случае вместо метода PUT будет использован PATCH.| |DELETE|Удаляет ресурс.| Методы `POST`, `PUT` и `PATCH` могут включать объект в тело запроса с типом содержимого `application/json`. ### Параметры в запросах Некоторые коллекции поддерживают пагинацию, поиск или сортировку в запросах. В параметрах запроса требуется передать: - `limit` — обозначает количество записей, которое необходимо вернуть - `offset` — указывает на смещение, относительно начала списка - `search` — позволяет указать набор символов для поиска - `sort` — можно задать правило сортировки коллекции ## Ответы Запросы вернут один из следующих кодов состояния ответа HTTP: |Статус|Описание| |--- |--- | |200 OK|Действие с ресурсом было выполнено успешно.| |201 Created|Ресурс был успешно создан. При этом ресурс может быть как уже готовым к использованию, так и находиться в процессе запуска.| |204 No Content|Действие с ресурсом было выполнено успешно, и ответ не содержит дополнительной информации в теле.| |400 Bad Request|Был отправлен неверный запрос, например, в нем отсутствуют обязательные параметры и т. д. Тело ответа будет содержать дополнительную информацию об ошибке.| |401 Unauthorized|Ошибка аутентификации.| |403 Forbidden|Аутентификация прошла успешно, но недостаточно прав для выполнения действия.| |404 Not Found|Запрашиваемый ресурс не найден.| |409 Conflict|Запрос конфликтует с текущим состоянием.| |423 Locked|Ресурс из запроса заблокирован от применения к нему указанного метода.| |429 Too Many Requests|Был достигнут лимит по количеству запросов в единицу времени.| |500 Internal Server Error|При выполнении запроса произошла какая-то внутренняя ошибка. Чтобы решить эту проблему, лучше всего создать тикет в панели управления.| ### Структура успешного ответа Все конечные точки будут возвращать данные в формате `JSON`. Ответы на `GET`-запросы будут иметь на верхнем уровне следующую структуру атрибутов: |Название поля|Тип|Описание| |--- |--- |--- | |[entity_name]|object, object[], string[], number[], boolean|Динамическое поле, которое будет меняться в зависимости от запрашиваемого ресурса и будет содержать все атрибуты, необходимые для описания этого ресурса. Например, при запросе списка баз данных будет возвращаться поле `dbs`, а при запросе конкретного облачного сервера `server`. Для некоторых конечных точек в ответе может возвращаться сразу несколько ресурсов.| |meta|object|Опционально. Объект, который содержит вспомогательную информацию о ресурсе. Чаще всего будет встречаться при запросе коллекций и содержать поле `total`, которое будет указывать на количество элементов в коллекции.| |response_id|string|Опционально. В большинстве случаев в ответе будет содержаться ID ответа в формате UUIDv4, который однозначно указывает на ваш запрос внутри нашей системы. Если вам потребуется задать вопрос нашей поддержке, приложите к вопросу этот ID— так мы сможем найти ответ на него намного быстрее. Также вы можете использовать этот ID, чтобы убедиться, что это новый ответ на запрос и результат не был получен из кэша.| Пример запроса на получение списка SSH-ключей: ``` HTTP/2.0 200 OK { \"ssh_keys\":[ { \"body\":\"ssh-rsa AAAAB3NzaC1sdfghjkOAsBwWhs= example@device.local\", \"created_at\":\"2021-09-15T19:52:27Z\", \"expired_at\":null, \"id\":5297, \"is_default\":false, \"name\":\"example@device.local\", \"used_at\":null, \"used_by\":[] } ], \"meta\":{ \"total\":1 }, \"response_id\":\"94608d15-8672-4eed-8ab6-28bd6fa3cdf7\" } ``` ### Структура ответа с ошибкой |Название поля|Тип|Описание| |--- |--- |--- | |status_code|number|Короткий числовой идентификатор ошибки.| |error_code|string|Короткий текстовый идентификатор ошибки, который уточняет числовой идентификатор и удобен для программной обработки. Самый простой пример — это код `not_found` для ошибки 404.| |message|string, string[]|Опционально. В большинстве случаев в ответе будет содержаться человекочитаемое подробное описание ошибки или ошибок, которые помогут понять, что нужно исправить.| |response_id|string|Опционально. В большинстве случае в ответе будет содержаться ID ответа в формате UUIDv4, который однозначно указывает на ваш запрос внутри нашей системы. Если вам потребуется задать вопрос нашей поддержке, приложите к вопросу этот ID — так мы сможем найти ответ на него намного быстрее.| Пример: ``` HTTP/2.0 403 Forbidden { \"status_code\": 403, \"error_code\": \"forbidden\", \"message\": \"You do not have access for the attempted action\", \"response_id\": \"94608d15-8672-4eed-8ab6-28bd6fa3cdf7\" } ``` ## Статусы ресурсов Важно учесть, что при создании большинства ресурсов внутри платформы вам будет сразу возвращен ответ от сервера со статусом `200 OK` или `201 Created` и ID созданного ресурса в теле ответа, но при этом этот ресурс может быть ещё в *состоянии запуска*. Для того чтобы понять, в каком состоянии сейчас находится ваш ресурс, мы добавили поле `status` в ответ на получение информации о ресурсе. Список статусов будет отличаться в зависимости от типа ресурса. Увидеть поддерживаемый список статусов вы сможете в описании каждого конкретного ресурса. ## Ограничение скорости запросов (Rate Limiting) Чтобы обеспечить стабильность для всех пользователей, Timeweb Cloud защищает API от всплесков входящего трафика, анализируя количество запросов c каждого аккаунта к каждой конечной точке. Если ваше приложение отправляет более 20 запросов в секунду на одну конечную точку, то для этого запроса API может вернуть код состояния HTTP `429 Too Many Requests`. ## Аутентификация Доступ к API осуществляется с помощью JWT-токена. Токенами можно управлять внутри панели управления Timeweb Cloud в разделе *API и Terraform*. Токен необходимо передавать в заголовке каждого запроса в формате: ``` Authorization: Bearer $TIMEWEB_CLOUD_TOKEN ``` ## Формат примеров API Примеры в этой документации описаны с помощью `curl`, HTTP-клиента командной строки. На компьютерах `Linux` и `macOS` обычно по умолчанию установлен `curl`, и он доступен для загрузки на всех популярных платформах, включая `Windows`. Каждый пример разделен на несколько строк символом `\\`, который совместим с `bash`. Типичный пример выглядит так: ``` curl -X PATCH -H \"Content-Type: application/json\" -H \"Authorization: Bearer $TIMEWEB_CLOUD_TOKEN\" -d '{\"name\":\"Cute Corvus\",\"comment\":\"Development Server\"}' \"https://api.timeweb.cloud/api/v1/dedicated/1051\" ``` - Параметр `-X` задает метод запроса. Для согласованности метод будет указан во всех примерах, даже если он явно не требуется для методов `GET`. - Строки `-H` задают требуемые HTTP-заголовки. - Примеры, для которых требуется объект JSON в теле запроса, передают требуемые данные через параметр `-d`. Чтобы использовать приведенные примеры, не подставляя каждый раз в них свой токен, вы можете добавить токен один раз в переменные окружения в вашей консоли. Например, на `Linux` это можно сделать с помощью команды: ``` TIMEWEB_CLOUD_TOKEN=\"token\" ``` После этого токен будет автоматически подставляться в ваши запросы. Обратите внимание, что все значения в этой документации являются примерами. Не полагайтесь на IDы операционных систем, тарифов и т.д., используемые в примерах. Используйте соответствующую конечную точку для получения значений перед созданием ресурсов. ## Версионирование API построено согласно принципам [семантического версионирования](https://semver.org/lang/ru). Это значит, что мы гарантируем обратную совместимость всех изменений в пределах одной мажорной версии. Мажорная версия каждой конечной точки обозначается в пути запроса, например, запрос `/api/v1/servers` указывает, что этот метод имеет версию 1.
*
* The version of the OpenAPI document: 1.0.0
* Contact: info@timeweb.cloud
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use super::{ContentType, Error, configuration};
use crate::{apis::ResponseContent, models};
/// struct for typed errors of method [`add_cdn_certificate`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddCdnCertificateError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status409(models::UpdateDatabaseInstance409Response),
Status422(models::AddCdnCertificate422Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`archive_cdn_certificate_task`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ArchiveCdnCertificateTaskError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`clear_cdn_resource_cache`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ClearCdnResourceCacheError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`create_cdn_resource`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateCdnResourceError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status409(models::UpdateDatabaseInstance409Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`delete_cdn_certificate`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteCdnCertificateError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status409(models::UpdateDatabaseInstance409Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`delete_cdn_resource`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteCdnResourceError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`get_cdn_certificate_tasks`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCdnCertificateTasksError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`get_cdn_certificates`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCdnCertificatesError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`get_cdn_origin_nodes`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCdnOriginNodesError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`get_cdn_presets`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCdnPresetsError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`get_cdn_resource`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCdnResourceError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`get_cdn_resource_configuration`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCdnResourceConfigurationError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`get_cdn_resource_nodes`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCdnResourceNodesError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`get_cdn_resource_statistics`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCdnResourceStatisticsError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`get_cdn_resources`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCdnResourcesError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`issue_cdn_certificate`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum IssueCdnCertificateError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status409(models::UpdateDatabaseInstance409Response),
Status422(models::AddCdnCertificate422Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`preload_cdn_resource_cache`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PreloadCdnResourceCacheError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`resume_cdn_resource`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ResumeCdnResourceError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status409(models::UpdateDatabaseInstance409Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`suspend_cdn_resource`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SuspendCdnResourceError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status409(models::UpdateDatabaseInstance409Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// struct for typed errors of method [`update_cdn_resource`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateCdnResourceError {
Status400(models::GetFinances400Response),
Status401(models::GetFinances401Response),
Status403(models::GetAccountStatus403Response),
Status404(models::GetImage404Response),
Status409(models::UpdateDatabaseInstance409Response),
Status429(models::GetFinances429Response),
Status500(models::GetFinances500Response),
UnknownValue(serde_json::Value)
}
/// Чтобы загрузить собственный SSL-сертификат, отправьте POST-запрос на
/// `/api/v1/cdn/certificates`. После загрузки сертификат появится в списке
/// `/api/v1/cdn/certificates` — привязать его к ресурсу можно, передав его ID в
/// поле `config.security.certificate_id` PATCH-запроса на
/// `/api/v1/cdn/http-resources/{resource_id}`. Если сертификат или приватный
/// ключ не проходят проверку — например, истек срок действия или ключ не
/// соответствует сертификату — вернется ошибка `422`.
pub async fn add_cdn_certificate(
configuration: &configuration::Configuration,
add_certificate: models::AddCertificate
) -> Result<(), Error<AddCdnCertificateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_add_certificate = add_certificate;
let uri_str = format!("{}/api/v1/cdn/certificates", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_add_certificate);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<AddCdnCertificateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы убрать из списка задачу на выпуск сертификата, отправьте POST-запрос
/// на `/api/v1/cdn/certificates/tasks/{task_id}/archive`.
pub async fn archive_cdn_certificate_task(
configuration: &configuration::Configuration,
task_id: i32
) -> Result<(), Error<ArchiveCdnCertificateTaskError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_task_id = task_id;
let uri_str = format!(
"{}/api/v1/cdn/certificates/tasks/{task_id}/archive",
configuration.base_path,
task_id = p_path_task_id
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<ArchiveCdnCertificateTaskError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы очистить кэш на узлах CDN, отправьте POST-запрос на
/// `/api/v1/cdn/http-resources/{resource_id}/clear-cache`. При `purge_type` =
/// `full` очищается весь кэш ресурса, при `purge_type` = `partial` — только
/// файлы из списка `paths`.
pub async fn clear_cdn_resource_cache(
configuration: &configuration::Configuration,
resource_id: i32,
clear_cache: models::ClearCache
) -> Result<(), Error<ClearCdnResourceCacheError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_resource_id = resource_id;
let p_body_clear_cache = clear_cache;
let uri_str = format!(
"{}/api/v1/cdn/http-resources/{resource_id}/clear-cache",
configuration.base_path,
resource_id = p_path_resource_id
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_clear_cache);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<ClearCdnResourceCacheError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы создать CDN-ресурс, отправьте POST-запрос на
/// `/api/v1/cdn/http-resources`. Источник контента задается ровно одним из
/// полей: `storage_id` для S3-хранилища или `server` для произвольного
/// origin-сервера. Если ни одно из них не передано, вернется ошибка `400`.
/// Сразу после создания ресурсу выдается технический домен `cdn_domain`, а сам
/// ресурс какое-то время находится в статусе `processing`, пока конфигурация
/// применяется на узлах CDN.
pub async fn create_cdn_resource(
configuration: &configuration::Configuration,
create_http_resource: models::CreateHttpResource
) -> Result<models::CreateCdnResource201Response, Error<CreateCdnResourceError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_create_http_resource = create_http_resource;
let uri_str = format!("{}/api/v1/cdn/http-resources", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_create_http_resource);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::CreateCdnResource201Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::CreateCdnResource201Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<CreateCdnResourceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы удалить SSL-сертификат, отправьте DELETE-запрос на
/// `/api/v1/cdn/certificates/{certificate_id}`. Если сертификат привязан к
/// CDN-ресурсу, вернется ошибка `409` — сначала отвяжите его, передав
/// `config.security.certificate_id` = `null` в PATCH-запросе на
/// `/api/v1/cdn/http-resources/{resource_id}`.
pub async fn delete_cdn_certificate(
configuration: &configuration::Configuration,
certificate_id: i32
) -> Result<(), Error<DeleteCdnCertificateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_certificate_id = certificate_id;
let uri_str = format!(
"{}/api/v1/cdn/certificates/{certificate_id}",
configuration.base_path,
certificate_id = p_path_certificate_id
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DeleteCdnCertificateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы удалить CDN-ресурс, отправьте DELETE-запрос на
/// `/api/v1/cdn/http-resources/{resource_id}`. Вместе с ресурсом освобождается
/// его технический домен, а привязанный сертификат отвязывается.
pub async fn delete_cdn_resource(
configuration: &configuration::Configuration,
resource_id: i32
) -> Result<(), Error<DeleteCdnResourceError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_resource_id = resource_id;
let uri_str = format!(
"{}/api/v1/cdn/http-resources/{resource_id}",
configuration.base_path,
resource_id = p_path_resource_id
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DeleteCdnResourceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы получить список задач на выпуск сертификатов Let's Encrypt, отправьте
/// GET-запрос на `/api/v1/cdn/certificates/tasks`.
pub async fn get_cdn_certificate_tasks(
configuration: &configuration::Configuration,
resource_id: Option<i32>
) -> Result<models::GetCdnCertificateTasks200Response, Error<GetCdnCertificateTasksError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_resource_id = resource_id;
let uri_str = format!("{}/api/v1/cdn/certificates/tasks", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_resource_id {
req_builder = req_builder.query(&[("resource_id", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::GetCdnCertificateTasks200Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::GetCdnCertificateTasks200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetCdnCertificateTasksError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы получить список SSL-сертификатов, доступных для доменов CDN-ресурсов,
/// отправьте GET-запрос на `/api/v1/cdn/certificates`.
pub async fn get_cdn_certificates(
configuration: &configuration::Configuration,
resource_id: Option<i32>
) -> Result<models::GetCdnCertificates200Response, Error<GetCdnCertificatesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_resource_id = resource_id;
let uri_str = format!("{}/api/v1/cdn/certificates", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_resource_id {
req_builder = req_builder.query(&[("resource_id", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::GetCdnCertificates200Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::GetCdnCertificates200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetCdnCertificatesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы получить список IP-адресов и подсетей, с которых узлы CDN обращаются к
/// источнику контента, отправьте GET-запрос на `/api/v1/cdn/nodes/origin`. Этот
/// список удобно использовать, чтобы разрешить доступ к origin-серверу только
/// для узлов CDN.
pub async fn get_cdn_origin_nodes(
configuration: &configuration::Configuration,
with_extra_zones: Option<bool>
) -> Result<models::GetCdnOriginNodes200Response, Error<GetCdnOriginNodesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_with_extra_zones = with_extra_zones;
let uri_str = format!("{}/api/v1/cdn/nodes/origin", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_with_extra_zones {
req_builder = req_builder.query(&[("with_extra_zones", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::GetCdnOriginNodes200Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::GetCdnOriginNodes200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetCdnOriginNodesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы получить список доступных тарифов CDN, отправьте GET-запрос на
/// `/api/v1/cdn/presets`. ID тарифа из этого списка указывается в поле
/// `preset_id` при создании и изменении ресурса.
pub async fn get_cdn_presets(
configuration: &configuration::Configuration
) -> Result<models::GetCdnPresets200Response, Error<GetCdnPresetsError>> {
let uri_str = format!("{}/api/v1/cdn/presets", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::GetCdnPresets200Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::GetCdnPresets200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetCdnPresetsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы получить информацию об отдельном CDN-ресурсе, отправьте GET-запрос на
/// `/api/v1/cdn/http-resources/{resource_id}`.
pub async fn get_cdn_resource(
configuration: &configuration::Configuration,
resource_id: i32
) -> Result<models::CreateCdnResource201Response, Error<GetCdnResourceError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_resource_id = resource_id;
let uri_str = format!(
"{}/api/v1/cdn/http-resources/{resource_id}",
configuration.base_path,
resource_id = p_path_resource_id
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::CreateCdnResource201Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::CreateCdnResource201Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetCdnResourceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы получить текущую конфигурацию CDN-ресурса, отправьте GET-запрос на
/// `/api/v1/cdn/http-resources/{resource_id}/configuration`. Изменить
/// конфигурацию можно в поле `config` PATCH-запроса на
/// `/api/v1/cdn/http-resources/{resource_id}`.
pub async fn get_cdn_resource_configuration(
configuration: &configuration::Configuration,
resource_id: i32
) -> Result<models::GetCdnResourceConfiguration200Response, Error<GetCdnResourceConfigurationError>>
{
// add a prefix to parameters to efficiently prevent name collisions
let p_path_resource_id = resource_id;
let uri_str = format!(
"{}/api/v1/cdn/http-resources/{resource_id}/configuration",
configuration.base_path,
resource_id = p_path_resource_id
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::GetCdnResourceConfiguration200Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::GetCdnResourceConfiguration200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetCdnResourceConfigurationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы получить список узлов, которые раздают контент доменов ресурса,
/// отправьте GET-запрос на `/api/v1/cdn/nodes/http-resources/{resource_id}`.
pub async fn get_cdn_resource_nodes(
configuration: &configuration::Configuration,
resource_id: i32,
with_extra_zones: Option<bool>,
country: Option<Vec<String>>
) -> Result<models::GetCdnResourceNodes200Response, Error<GetCdnResourceNodesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_resource_id = resource_id;
let p_query_with_extra_zones = with_extra_zones;
let p_query_country = country;
let uri_str = format!(
"{}/api/v1/cdn/nodes/http-resources/{resource_id}",
configuration.base_path,
resource_id = p_path_resource_id
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_with_extra_zones {
req_builder = req_builder.query(&[("with_extra_zones", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_country {
req_builder = match "multi" {
"multi" => req_builder.query(
¶m_value
.into_iter()
.map(|p| ("country".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>()
),
_ => req_builder.query(&[(
"country",
¶m_value
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string()
)])
};
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::GetCdnResourceNodes200Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::GetCdnResourceNodes200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetCdnResourceNodesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы получить статистику трафика и запросов CDN-ресурса, отправьте
/// GET-запрос на `/api/v1/cdn/http-resources/{resource_id}/statistics`. Данные
/// возвращаются с разбивкой по часовым интервалам. Если период не указан,
/// вернется статистика за последние 6 часов.
pub async fn get_cdn_resource_statistics(
configuration: &configuration::Configuration,
resource_id: i32,
from: Option<chrono::DateTime<chrono::FixedOffset>>,
to: Option<chrono::DateTime<chrono::FixedOffset>>
) -> Result<models::GetCdnResourceStatistics200Response, Error<GetCdnResourceStatisticsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_resource_id = resource_id;
let p_query_from = from;
let p_query_to = to;
let uri_str = format!(
"{}/api/v1/cdn/http-resources/{resource_id}/statistics",
configuration.base_path,
resource_id = p_path_resource_id
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_from {
req_builder = req_builder.query(&[("from", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_to {
req_builder = req_builder.query(&[("to", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::GetCdnResourceStatistics200Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::GetCdnResourceStatistics200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetCdnResourceStatisticsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы получить список CDN-ресурсов, отправьте GET-запрос на
/// `/api/v1/cdn/http-resources`.
pub async fn get_cdn_resources(
configuration: &configuration::Configuration,
bucket_id: Option<i32>
) -> Result<models::GetCdnResources200Response, Error<GetCdnResourcesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_bucket_id = bucket_id;
let uri_str = format!("{}/api/v1/cdn/http-resources", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_bucket_id {
req_builder = req_builder.query(&[("bucket_id", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::GetCdnResources200Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::GetCdnResources200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<GetCdnResourcesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы выпустить бесплатный сертификат Let's Encrypt для доменов CDN-ресурса,
/// отправьте POST-запрос на `/api/v1/cdn/certificates/issue`. Выпуск
/// выполняется асинхронно: в ответ возвращается код `202`, а следить за ходом
/// выпуска можно по списку задач `/api/v1/cdn/certificates/tasks`. Готовый
/// сертификат привязывается к ресурсу автоматически. Перед выпуском убедитесь,
/// что домены ресурса указывают на его технический домен `cdn_domain` — иначе
/// вернется ошибка `422`.
pub async fn issue_cdn_certificate(
configuration: &configuration::Configuration,
issue_certificate: models::IssueCertificate
) -> Result<(), Error<IssueCdnCertificateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_issue_certificate = issue_certificate;
let uri_str = format!("{}/api/v1/cdn/certificates/issue", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_issue_certificate);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<IssueCdnCertificateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы заранее загрузить файлы в кэш узлов CDN, не дожидаясь первого
/// обращения пользователей, отправьте POST-запрос на
/// `/api/v1/cdn/http-resources/{resource_id}/preload-cache`.
pub async fn preload_cdn_resource_cache(
configuration: &configuration::Configuration,
resource_id: i32,
preload_cache: models::PreloadCache
) -> Result<(), Error<PreloadCdnResourceCacheError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_resource_id = resource_id;
let p_body_preload_cache = preload_cache;
let uri_str = format!(
"{}/api/v1/cdn/http-resources/{resource_id}/preload-cache",
configuration.base_path,
resource_id = p_path_resource_id
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_preload_cache);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<PreloadCdnResourceCacheError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы возобновить раздачу контента после приостановки, отправьте POST-запрос
/// на `/api/v1/cdn/http-resources/{resource_id}/resume`. Если ресурс
/// заблокирован, вернется ошибка `409`.
pub async fn resume_cdn_resource(
configuration: &configuration::Configuration,
resource_id: i32
) -> Result<models::CreateCdnResource201Response, Error<ResumeCdnResourceError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_resource_id = resource_id;
let uri_str = format!(
"{}/api/v1/cdn/http-resources/{resource_id}/resume",
configuration.base_path,
resource_id = p_path_resource_id
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::CreateCdnResource201Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::CreateCdnResource201Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<ResumeCdnResourceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы приостановить раздачу контента, отправьте POST-запрос на
/// `/api/v1/cdn/http-resources/{resource_id}/suspend`. Ресурс перейдет в статус
/// `stopped`, его настройки и домены сохранятся. Если ресурс заблокирован,
/// вернется ошибка `409`.
pub async fn suspend_cdn_resource(
configuration: &configuration::Configuration,
resource_id: i32
) -> Result<models::CreateCdnResource201Response, Error<SuspendCdnResourceError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_resource_id = resource_id;
let uri_str = format!(
"{}/api/v1/cdn/http-resources/{resource_id}/suspend",
configuration.base_path,
resource_id = p_path_resource_id
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::CreateCdnResource201Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::CreateCdnResource201Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<SuspendCdnResourceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}
/// Чтобы изменить CDN-ресурс, отправьте PATCH-запрос на
/// `/api/v1/cdn/http-resources/{resource_id}`. Передавайте только те поля,
/// которые нужно изменить: переданные значения накладываются на текущую
/// конфигурацию, а непереданные остаются без изменений. Чтобы сбросить
/// настройку, передайте в соответствующем поле `null`. Поля `storage_id` и
/// `config.origin.servers` нельзя передавать вместе — источник контента может
/// быть только один.
pub async fn update_cdn_resource(
configuration: &configuration::Configuration,
resource_id: i32,
update_http_resource: models::UpdateHttpResource
) -> Result<models::CreateCdnResource201Response, Error<UpdateCdnResourceError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_resource_id = resource_id;
let p_body_update_http_resource = update_http_resource;
let uri_str = format!(
"{}/api/v1/cdn/http-resources/{resource_id}",
configuration.base_path,
resource_id = p_path_resource_id
);
let mut req_builder = configuration
.client
.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_update_http_resource);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::CreateCdnResource201Response`"
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::CreateCdnResource201Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateCdnResourceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity
}))
}
}