use serde::{Deserialize, Serialize};
use vantage_table::table::Table;
use crate::types::{Arn, AwsDateTime};
use crate::{AwsAccount, eq};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Policy {
#[serde(rename = "PolicyName")]
pub policy_name: String,
#[serde(rename = "PolicyId", default)]
pub policy_id: String,
#[serde(rename = "Arn", default)]
pub arn: String,
#[serde(rename = "Path", default)]
pub path: String,
#[serde(rename = "DefaultVersionId", default)]
pub default_version_id: String,
#[serde(rename = "AttachmentCount", default)]
pub attachment_count: String,
#[serde(rename = "PermissionsBoundaryUsageCount", default)]
pub permissions_boundary_usage_count: String,
#[serde(rename = "IsAttachable", default)]
pub is_attachable: String,
#[serde(rename = "CreateDate", default)]
pub create_date: String,
#[serde(rename = "UpdateDate", default)]
pub update_date: String,
#[serde(rename = "Description", default)]
pub description: String,
}
pub fn policies_table(aws: AwsAccount) -> Table<AwsAccount, Policy> {
Table::new("query/Policies:iam/2010-05-08.ListPolicies", aws)
.with_id_column("PolicyName")
.with_column_of::<String>("PolicyId")
.with_column_of::<Arn>("Arn")
.with_title_column_of::<String>("Path")
.with_column_of::<String>("DefaultVersionId")
.with_title_column_of::<i64>("AttachmentCount")
.with_column_of::<i64>("PermissionsBoundaryUsageCount")
.with_title_column_of::<bool>("IsAttachable")
.with_column_of::<AwsDateTime>("CreateDate")
.with_column_of::<AwsDateTime>("UpdateDate")
.with_column_of::<String>("Description")
}
impl Policy {
pub fn from_arn(arn: &str, aws: AwsAccount) -> Option<Table<AwsAccount, Policy>> {
let after = arn
.strip_prefix("arn:aws:iam::")?
.split(":policy/")
.nth(1)?;
let name = after.rsplit('/').next()?;
if name.is_empty() {
return None;
}
let mut t = policies_table(aws);
t.add_condition(eq("PolicyName", name.to_string()));
Some(t)
}
}