/*
* CrowdStrike API Specification
*
* Use this API specification as a reference for the API endpoints you can use to interact with your Falcon environment. These endpoints support authentication via OAuth2 and interact with detections and network containment. For detailed usage guides and examples, see our [documentation inside the Falcon console](https://falcon.crowdstrike.com/support/documentation). To use the APIs described below, combine the base URL with the path shown for each API endpoint. For commercial cloud customers, your base URL is `https://api.crowdstrike.com`. Each API endpoint requires authorization via an OAuth2 token. Your first API request should retrieve an OAuth2 token using the `oauth2/token` endpoint, such as `https://api.crowdstrike.com/oauth2/token`. For subsequent requests, include the OAuth2 token in an HTTP authorization header. Tokens expire after 30 minutes, after which you should make a new token request to continue making API requests.
*
* The version of the OpenAPI document: rolling
*
* Generated by: https://openapi-generator.tech
*/
use super::{ContentType, Error, configuration};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::de::Error as _;
/// struct for typed errors of method [`create_policies`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreatePoliciesError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::CoreEntitiesResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_policy_groups`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreatePolicyGroupsError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::CoreEntitiesResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_policy`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeletePolicyError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::CoreEntitiesResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_policy_group`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeletePolicyGroupError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::CoreEntitiesResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`read_policies`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ReadPoliciesError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::CoreEntitiesResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`read_policy_exclusions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ReadPolicyExclusionsError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::CoreEntitiesResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`read_policy_groups`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ReadPolicyGroupsError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::CoreEntitiesResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_policies`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdatePoliciesError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::CoreEntitiesResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_policy_exclusions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdatePolicyExclusionsError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::CoreEntitiesResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_policy_groups`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdatePolicyGroupsError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::CoreEntitiesResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_policy_precedence`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdatePolicyPrecedenceError {
Status403(models::MsaReplyMetaOnly),
Status429(models::MsaReplyMetaOnly),
Status500(models::CoreEntitiesResponse),
UnknownValue(serde_json::Value),
}
pub async fn create_policies(
configuration: &configuration::Configuration,
body: models::ModelsCreatePolicyRequest,
) -> Result<models::ModelsPolicyEntityResponse, Error<CreatePoliciesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_body = body;
let uri_str = format!(
"{}/container-security/entities/image-assessment-policies/v1",
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.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_body);
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::ModelsPolicyEntityResponse`",
)));
}
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::ModelsPolicyEntityResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<CreatePoliciesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn create_policy_groups(
configuration: &configuration::Configuration,
body: models::ModelsCreateImageGroupRequest,
) -> Result<models::ModelsPolicyGroupEntityResponse, Error<CreatePolicyGroupsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_body = body;
let uri_str = format!(
"{}/container-security/entities/image-assessment-policy-groups/v1",
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.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_body);
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::ModelsPolicyGroupEntityResponse`",
)));
}
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::ModelsPolicyGroupEntityResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<CreatePolicyGroupsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn delete_policy(
configuration: &configuration::Configuration,
id: &str,
) -> Result<models::CoreEntitiesResponse, Error<DeletePolicyError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_id = id;
let uri_str = format!(
"{}/container-security/entities/image-assessment-policies/v1",
configuration.base_path
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
req_builder = req_builder.query(&[("id", &p_query_id.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.oauth_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::CoreEntitiesResponse`",
)));
}
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::CoreEntitiesResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<DeletePolicyError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn delete_policy_group(
configuration: &configuration::Configuration,
id: &str,
) -> Result<models::CoreEntitiesResponse, Error<DeletePolicyGroupError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_id = id;
let uri_str = format!(
"{}/container-security/entities/image-assessment-policy-groups/v1",
configuration.base_path
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
req_builder = req_builder.query(&[("id", &p_query_id.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.oauth_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::CoreEntitiesResponse`",
)));
}
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::CoreEntitiesResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<DeletePolicyGroupError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn read_policies(
configuration: &configuration::Configuration,
) -> Result<models::ModelsPolicyEntityResponse, Error<ReadPoliciesError>> {
let uri_str = format!(
"{}/container-security/entities/image-assessment-policies/v1",
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.oauth_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::ModelsPolicyEntityResponse`",
)));
}
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::ModelsPolicyEntityResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<ReadPoliciesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn read_policy_exclusions(
configuration: &configuration::Configuration,
) -> Result<models::ModelsPolicyExclusionEntityResponse, Error<ReadPolicyExclusionsError>> {
let uri_str = format!(
"{}/container-security/entities/image-assessment-policy-exclusions/v1",
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.oauth_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::ModelsPolicyExclusionEntityResponse`",
)));
}
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::ModelsPolicyExclusionEntityResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<ReadPolicyExclusionsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn read_policy_groups(
configuration: &configuration::Configuration,
) -> Result<models::ModelsPolicyGroupEntityResponse, Error<ReadPolicyGroupsError>> {
let uri_str = format!(
"{}/container-security/entities/image-assessment-policy-groups/v1",
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.oauth_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::ModelsPolicyGroupEntityResponse`",
)));
}
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::ModelsPolicyGroupEntityResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<ReadPolicyGroupsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn update_policies(
configuration: &configuration::Configuration,
id: &str,
body: models::ModelsPatchPolicyRequest,
) -> Result<models::ModelsPolicyEntityResponse, Error<UpdatePoliciesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_id = id;
let p_body_body = body;
let uri_str = format!(
"{}/container-security/entities/image-assessment-policies/v1",
configuration.base_path
);
let mut req_builder = configuration
.client
.request(reqwest::Method::PATCH, &uri_str);
req_builder = req_builder.query(&[("id", &p_query_id.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.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_body);
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::ModelsPolicyEntityResponse`",
)));
}
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::ModelsPolicyEntityResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<UpdatePoliciesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn update_policy_exclusions(
configuration: &configuration::Configuration,
body: models::ModelsUpdateExclusionsRequest,
) -> Result<models::ModelsPolicyExclusionEntityResponse, Error<UpdatePolicyExclusionsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_body = body;
let uri_str = format!(
"{}/container-security/entities/image-assessment-policy-exclusions/v1",
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.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_body);
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::ModelsPolicyExclusionEntityResponse`",
)));
}
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::ModelsPolicyExclusionEntityResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<UpdatePolicyExclusionsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn update_policy_groups(
configuration: &configuration::Configuration,
id: &str,
body: models::ModelsPatchImageGroupRequest,
) -> Result<models::ModelsPolicyGroupEntityResponse, Error<UpdatePolicyGroupsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_id = id;
let p_body_body = body;
let uri_str = format!(
"{}/container-security/entities/image-assessment-policy-groups/v1",
configuration.base_path
);
let mut req_builder = configuration
.client
.request(reqwest::Method::PATCH, &uri_str);
req_builder = req_builder.query(&[("id", &p_query_id.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.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_body);
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::ModelsPolicyGroupEntityResponse`",
)));
}
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::ModelsPolicyGroupEntityResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<UpdatePolicyGroupsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn update_policy_precedence(
configuration: &configuration::Configuration,
body: models::ModelsApiPrecedenceRequest,
) -> Result<models::ModelsPolicyEntityResponse, Error<UpdatePolicyPrecedenceError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_body = body;
let uri_str = format!(
"{}/container-security/entities/image-assessment-policy-precedence/v1",
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.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_body);
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::ModelsPolicyEntityResponse`",
)));
}
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::ModelsPolicyEntityResponse`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<UpdatePolicyPrecedenceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}