use crate::types::accessanalyzer::*;
use crate::{AwsHttpClient, Result};
pub struct AccessanalyzerOps<'a> {
pub(crate) client: &'a AwsHttpClient,
}
impl<'a> AccessanalyzerOps<'a> {
pub(crate) fn new(client: &'a AwsHttpClient) -> Self {
Self { client }
}
fn base_url(&self) -> String {
#[cfg(any(test, feature = "test-support"))]
{
if let Some(ref base) = self.client.base_url {
return base.trim_end_matches('/').to_string();
}
}
"https://access-analyzer.{region}.amazonaws.com".replace("{region}", self.client.region())
}
#[allow(dead_code)]
pub(crate) async fn list_analyzers(
&self,
next_token: &str,
max_results: &str,
r#type: &str,
) -> Result<ListAnalyzersResponse> {
let url = format!("{}/analyzer", self.base_url(),);
let url = crate::append_query_params(
url,
&[
("nextToken", next_token),
("maxResults", max_results),
("type", r#type),
],
);
let response = self.client.get_json(&url, "access-analyzer").await?;
let response = response.error_for_status("json").await?;
let response_bytes =
response
.bytes()
.await
.map_err(|e| crate::AwsError::InvalidResponse {
message: format!("Failed to read list_analyzers response: {e}"),
body: None,
})?;
serde_json::from_slice(&response_bytes).map_err(|e| crate::AwsError::InvalidResponse {
message: format!("Failed to parse list_analyzers response: {e}"),
body: Some(String::from_utf8_lossy(&response_bytes).to_string()),
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_list_analyzers() {
let mut mock = crate::MockClient::new();
mock.expect_get(
"/analyzer?nextToken=test-nextToken&maxResults=test-maxResults&type=test-type",
)
.returning_json(serde_json::to_value(ListAnalyzersResponse::fixture()).unwrap());
let client = crate::AwsHttpClient::from_mock(mock);
let ops = AccessanalyzerOps::new(&client);
let result = ops
.list_analyzers("test-nextToken", "test-maxResults", "test-type")
.await;
assert!(result.is_ok());
}
}