use crate::known::{Partition, Region, Service};
use crate::{AccountIdentifier, Identifier, IdentifierLike, ResourceIdentifier, ResourceName};
#[derive(Clone, Debug)]
pub struct ArnBuilder {
arn: ResourceName,
}
#[derive(Clone, Debug, Default)]
pub struct ResourceBuilder {
resource: Vec<ResourceIdentifier>,
}
impl From<ArnBuilder> for ResourceName {
fn from(v: ArnBuilder) -> Self {
v.arn
}
}
impl From<&mut ArnBuilder> for ResourceName {
fn from(v: &mut ArnBuilder) -> Self {
v.arn.clone()
}
}
impl ArnBuilder {
pub fn service(service: Service) -> Self {
Self::service_id(service.into())
}
pub fn service_id(service: Identifier) -> Self {
Self {
arn: ResourceName {
partition: None,
service,
region: None,
account_id: None,
resource: ResourceIdentifier::default(),
},
}
}
pub fn in_partition(&mut self, partition: Partition) -> &mut Self {
self.in_partition_id(partition.into())
}
pub fn in_partition_id(&mut self, partition: Identifier) -> &mut Self {
self.arn.partition = Some(partition);
self
}
pub fn in_default_partition(&mut self) -> &mut Self {
self.arn.partition = Some(Partition::default().into());
self
}
pub fn in_any_partition(&mut self) -> &mut Self {
self.arn.partition = None;
self
}
pub fn in_region(&mut self, region: Region) -> &mut Self {
self.in_region_id(region.into())
}
pub fn in_region_id(&mut self, region: Identifier) -> &mut Self {
self.arn.region = Some(region);
self
}
pub fn and_region(&mut self, region: Region) -> &mut Self {
self.in_region_id(region.into())
}
pub fn and_region_id(&mut self, region: Identifier) -> &mut Self {
self.in_region_id(region)
}
pub fn in_any_region(&mut self) -> &mut Self {
self.in_region_id(Identifier::default())
}
pub fn in_account(&mut self, account: AccountIdentifier) -> &mut Self {
self.arn.account_id = Some(account);
self
}
pub fn and_account(&mut self, account: AccountIdentifier) -> &mut Self {
self.in_account(account)
}
pub fn owned_by(&mut self, account: AccountIdentifier) -> &mut Self {
self.in_account(account)
}
pub fn in_any_account(&mut self) -> &mut Self {
self.in_account(AccountIdentifier::default())
}
pub fn resource(&mut self, resource: ResourceIdentifier) -> &mut Self {
self.arn.resource = resource;
self
}
pub fn is(&mut self, resource: ResourceIdentifier) -> &mut Self {
self.resource(resource)
}
pub fn a(&mut self, resource: ResourceIdentifier) -> &mut Self {
self.resource(resource)
}
pub fn any_resource(&mut self) -> &mut Self {
self.arn.resource = ResourceIdentifier::any();
self
}
pub fn for_any_resource(&mut self) -> &mut Self {
self.any_resource()
}
}
impl From<ResourceIdentifier> for ResourceBuilder {
fn from(v: ResourceIdentifier) -> Self {
Self { resource: vec![v] }
}
}
impl From<Identifier> for ResourceBuilder {
fn from(v: Identifier) -> Self {
Self {
resource: vec![v.into()],
}
}
}
impl ResourceBuilder {
pub fn named(id: Identifier) -> Self {
Self {
resource: vec![id.into()],
}
}
pub fn typed(id: Identifier) -> Self {
Self {
resource: vec![id.into()],
}
}
pub fn add(&mut self, id: ResourceIdentifier) -> &mut Self {
self.resource.push(id);
self
}
pub fn qualified_name(&mut self, id: ResourceIdentifier) -> &mut Self {
self.resource.push(id);
self
}
pub fn resource_path(&mut self, id: ResourceIdentifier) -> &mut Self {
self.resource.push(id);
self
}
pub fn type_name(&mut self, id: Identifier) -> &mut Self {
self.resource.push(id.into());
self
}
pub fn resource_name(&mut self, id: Identifier) -> &mut Self {
self.resource.push(id.into());
self
}
pub fn sub_resource_name(&mut self, id: Identifier) -> &mut Self {
self.resource.push(id.into());
self
}
pub fn version(&mut self, v: u32) -> &mut Self {
self.resource
.push(Identifier::new_unchecked(&v.to_string()).into());
self
}
pub fn build_resource_path(&mut self) -> ResourceIdentifier {
ResourceIdentifier::from_path(&self.resource)
}
pub fn build_qualified_id(&mut self) -> ResourceIdentifier {
ResourceIdentifier::from_qualified(&self.resource)
}
}
pub mod cognito;
pub mod iam;
pub mod lambda;
pub mod s3;