/*
* Fastly API
*
* Via the Fastly API you can perform any of the operations that are possible within the management console, including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/)
*
*/
use reqwest;
use crate::apis::ResponseContent;
use super::{Error, configuration};
/// struct for passing parameters to the method [`create_custom_vcl`]
#[derive(Clone, Debug, Default)]
pub struct CreateCustomVclParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
/// Integer identifying a service version.
pub version_id: i32,
/// The VCL code to be included.
pub content: Option<String>,
/// Set to `true` when this is the main VCL, otherwise `false`.
pub main: Option<bool>,
/// The name of this VCL.
pub name: Option<String>
}
/// struct for passing parameters to the method [`delete_custom_vcl`]
#[derive(Clone, Debug, Default)]
pub struct DeleteCustomVclParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
/// Integer identifying a service version.
pub version_id: i32,
/// The name of this VCL.
pub vcl_name: String
}
/// struct for passing parameters to the method [`get_custom_vcl`]
#[derive(Clone, Debug, Default)]
pub struct GetCustomVclParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
/// Integer identifying a service version.
pub version_id: i32,
/// The name of this VCL.
pub vcl_name: String,
/// Omit VCL content.
pub no_content: Option<String>
}
/// struct for passing parameters to the method [`get_custom_vcl_boilerplate`]
#[derive(Clone, Debug, Default)]
pub struct GetCustomVclBoilerplateParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
/// Integer identifying a service version.
pub version_id: i32
}
/// struct for passing parameters to the method [`get_custom_vcl_generated`]
#[derive(Clone, Debug, Default)]
pub struct GetCustomVclGeneratedParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
/// Integer identifying a service version.
pub version_id: i32
}
/// struct for passing parameters to the method [`get_custom_vcl_generated_highlighted`]
#[derive(Clone, Debug, Default)]
pub struct GetCustomVclGeneratedHighlightedParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
/// Integer identifying a service version.
pub version_id: i32
}
/// struct for passing parameters to the method [`get_custom_vcl_highlighted`]
#[derive(Clone, Debug, Default)]
pub struct GetCustomVclHighlightedParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
/// Integer identifying a service version.
pub version_id: i32,
/// The name of this VCL.
pub vcl_name: String
}
/// struct for passing parameters to the method [`get_custom_vcl_raw`]
#[derive(Clone, Debug, Default)]
pub struct GetCustomVclRawParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
/// Integer identifying a service version.
pub version_id: i32,
/// The name of this VCL.
pub vcl_name: String
}
/// struct for passing parameters to the method [`lint_vcl_default`]
#[derive(Clone, Debug, Default)]
pub struct LintVclDefaultParams {
pub inline_object1: crate::models::InlineObject1
}
/// struct for passing parameters to the method [`lint_vcl_for_service`]
#[derive(Clone, Debug, Default)]
pub struct LintVclForServiceParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
pub inline_object: crate::models::InlineObject
}
/// struct for passing parameters to the method [`list_custom_vcl`]
#[derive(Clone, Debug, Default)]
pub struct ListCustomVclParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
/// Integer identifying a service version.
pub version_id: i32
}
/// struct for passing parameters to the method [`set_custom_vcl_main`]
#[derive(Clone, Debug, Default)]
pub struct SetCustomVclMainParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
/// Integer identifying a service version.
pub version_id: i32,
/// The name of this VCL.
pub vcl_name: String
}
/// struct for passing parameters to the method [`update_custom_vcl`]
#[derive(Clone, Debug, Default)]
pub struct UpdateCustomVclParams {
/// Alphanumeric string identifying the service.
pub service_id: String,
/// Integer identifying a service version.
pub version_id: i32,
/// The name of this VCL.
pub vcl_name: String,
/// The VCL code to be included.
pub content: Option<String>,
/// Set to `true` when this is the main VCL, otherwise `false`.
pub main: Option<bool>,
/// The name of this VCL.
pub name: Option<String>
}
/// struct for typed errors of method [`create_custom_vcl`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateCustomVclError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_custom_vcl`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteCustomVclError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_custom_vcl`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCustomVclError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_custom_vcl_boilerplate`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCustomVclBoilerplateError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_custom_vcl_generated`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCustomVclGeneratedError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_custom_vcl_generated_highlighted`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCustomVclGeneratedHighlightedError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_custom_vcl_highlighted`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCustomVclHighlightedError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_custom_vcl_raw`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetCustomVclRawError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`lint_vcl_default`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LintVclDefaultError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`lint_vcl_for_service`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LintVclForServiceError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_custom_vcl`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListCustomVclError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`set_custom_vcl_main`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SetCustomVclMainError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_custom_vcl`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateCustomVclError {
UnknownValue(serde_json::Value),
}
/// Upload a VCL for a particular service and version.
pub async fn create_custom_vcl(configuration: &mut configuration::Configuration, params: CreateCustomVclParams) -> Result<crate::models::VclResponse, Error<CreateCustomVclError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let version_id = params.version_id;
let content = params.content;
let main = params.main;
let name = params.name;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
let mut local_var_form_params = std::collections::HashMap::new();
if let Some(local_var_param_value) = content {
local_var_form_params.insert("content", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = main {
local_var_form_params.insert("main", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = name {
local_var_form_params.insert("name", local_var_param_value.to_string());
}
local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "POST" != "GET" && "POST" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<CreateCustomVclError> = 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))
}
}
/// Delete the uploaded VCL for a particular service and version.
pub async fn delete_custom_vcl(configuration: &mut configuration::Configuration, params: DeleteCustomVclParams) -> Result<crate::models::InlineResponse200, Error<DeleteCustomVclError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let version_id = params.version_id;
let vcl_name = params.vcl_name;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, 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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "DELETE" != "GET" && "DELETE" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<DeleteCustomVclError> = 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))
}
}
/// Get the uploaded VCL for a particular service and version.
pub async fn get_custom_vcl(configuration: &mut configuration::Configuration, params: GetCustomVclParams) -> Result<crate::models::VclResponse, Error<GetCustomVclError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let version_id = params.version_id;
let vcl_name = params.vcl_name;
let no_content = params.no_content;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
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_str) = no_content {
local_var_req_builder = local_var_req_builder.query(&[("no_content", &local_var_str.to_string())]);
}
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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "GET" != "GET" && "GET" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetCustomVclError> = 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))
}
}
/// Return boilerplate VCL with the service's TTL from the [settings](https://www.fastly.com/documentation/reference/api/vcl-services/settings/).
pub async fn get_custom_vcl_boilerplate(configuration: &mut configuration::Configuration, params: GetCustomVclBoilerplateParams) -> Result<String, Error<GetCustomVclBoilerplateError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let version_id = params.version_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/boilerplate", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "GET" != "GET" && "GET" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetCustomVclBoilerplateError> = 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))
}
}
/// Display the generated VCL for a particular service and version.
pub async fn get_custom_vcl_generated(configuration: &mut configuration::Configuration, params: GetCustomVclGeneratedParams) -> Result<crate::models::VclResponse, Error<GetCustomVclGeneratedError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let version_id = params.version_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/generated_vcl", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "GET" != "GET" && "GET" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetCustomVclGeneratedError> = 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))
}
}
/// Display the content of generated VCL with HTML syntax highlighting. Include line numbers by sending `lineno=true` as a request parameter.
pub async fn get_custom_vcl_generated_highlighted(configuration: &mut configuration::Configuration, params: GetCustomVclGeneratedHighlightedParams) -> Result<crate::models::VclSyntaxHighlightingResponse, Error<GetCustomVclGeneratedHighlightedError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let version_id = params.version_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/generated_vcl/content", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "GET" != "GET" && "GET" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetCustomVclGeneratedHighlightedError> = 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))
}
}
/// Get the uploaded VCL for a particular service and version with HTML syntax highlighting. Include line numbers by sending `lineno=true` as a request parameter.
pub async fn get_custom_vcl_highlighted(configuration: &mut configuration::Configuration, params: GetCustomVclHighlightedParams) -> Result<crate::models::VclSyntaxHighlightingResponse, Error<GetCustomVclHighlightedError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let version_id = params.version_id;
let vcl_name = params.vcl_name;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}/content", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "GET" != "GET" && "GET" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetCustomVclHighlightedError> = 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))
}
}
/// Download the specified VCL.
pub async fn get_custom_vcl_raw(configuration: &mut configuration::Configuration, params: GetCustomVclRawParams) -> Result<String, Error<GetCustomVclRawError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let version_id = params.version_id;
let vcl_name = params.vcl_name;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}/download", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "GET" != "GET" && "GET" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetCustomVclRawError> = 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))
}
}
/// This endpoint validates the submitted VCL against a default set of enabled flags. Consider using the `/service/{service_id}/lint` operation to validate VCL in the context of a specific service.
pub async fn lint_vcl_default(configuration: &mut configuration::Configuration, params: LintVclDefaultParams) -> Result<crate::models::ValidatorResult, Error<LintVclDefaultError>> {
let local_var_configuration = configuration;
// unbox the parameters
let inline_object1 = params.inline_object1;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/vcl_lint", 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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
local_var_req_builder = local_var_req_builder.json(&inline_object1);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "POST" != "GET" && "POST" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<LintVclDefaultError> = 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))
}
}
/// Services may have flags set by a Fastly employee or by the purchase of products as addons to the service, which modify the way VCL is interpreted by that service. This endpoint validates the submitted VCL in the context of the specified service.
pub async fn lint_vcl_for_service(configuration: &mut configuration::Configuration, params: LintVclForServiceParams) -> Result<crate::models::ValidatorResult, Error<LintVclForServiceError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let inline_object = params.inline_object;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/lint", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
local_var_req_builder = local_var_req_builder.json(&inline_object);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "POST" != "GET" && "POST" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<LintVclForServiceError> = 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))
}
}
/// List the uploaded VCLs for a particular service and version.
pub async fn list_custom_vcl(configuration: &mut configuration::Configuration, params: ListCustomVclParams) -> Result<Vec<crate::models::VclResponse>, Error<ListCustomVclError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let version_id = params.version_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "GET" != "GET" && "GET" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<ListCustomVclError> = 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))
}
}
/// Set the specified VCL as the main.
pub async fn set_custom_vcl_main(configuration: &mut configuration::Configuration, params: SetCustomVclMainParams) -> Result<crate::models::VclResponse, Error<SetCustomVclMainError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let version_id = params.version_id;
let vcl_name = params.vcl_name;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}/main", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, 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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "PUT" != "GET" && "PUT" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<SetCustomVclMainError> = 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))
}
}
/// Update the uploaded VCL for a particular service and version.
pub async fn update_custom_vcl(configuration: &mut configuration::Configuration, params: UpdateCustomVclParams) -> Result<crate::models::VclResponse, Error<UpdateCustomVclError>> {
let local_var_configuration = configuration;
// unbox the parameters
let service_id = params.service_id;
let version_id = params.version_id;
let vcl_name = params.vcl_name;
let content = params.content;
let main = params.main;
let name = params.name;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, 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());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
let local_var_value = match local_var_apikey.prefix {
Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
None => local_var_key,
};
local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
};
let mut local_var_form_params = std::collections::HashMap::new();
if let Some(local_var_param_value) = content {
local_var_form_params.insert("content", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = main {
local_var_form_params.insert("main", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = name {
local_var_form_params.insert("name", local_var_param_value.to_string());
}
local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
if "PUT" != "GET" && "PUT" != "HEAD" {
let headers = local_var_resp.headers();
local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => configuration::DEFAULT_RATELIMIT,
};
local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
Some(v) => v.to_str().unwrap().parse().unwrap(),
None => 0,
};
}
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() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<UpdateCustomVclError> = 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))
}
}