Skip to main content

rustack_cloudfront_core/
arn.rs

1//! ARN helpers for CloudFront.
2//!
3//! CloudFront is a global service: its ARNs omit the region segment.
4//! `arn:aws:cloudfront::{account}:distribution/{id}`
5
6/// Construct a distribution ARN.
7#[must_use]
8pub fn distribution_arn(account_id: &str, distribution_id: &str) -> String {
9    format!("arn:aws:cloudfront::{account_id}:distribution/{distribution_id}")
10}
11
12/// Construct an OAC ARN.
13#[must_use]
14pub fn origin_access_control_arn(account_id: &str, id: &str) -> String {
15    format!("arn:aws:cloudfront::{account_id}:origin-access-control/{id}")
16}
17
18/// Construct an OAI ARN (same shape for identifying).
19#[must_use]
20pub fn oai_arn(account_id: &str, id: &str) -> String {
21    format!("arn:aws:cloudfront::{account_id}:origin-access-identity/{id}")
22}
23
24/// Construct a cache policy ARN.
25#[must_use]
26pub fn cache_policy_arn(account_id: &str, id: &str) -> String {
27    format!("arn:aws:cloudfront::{account_id}:cache-policy/{id}")
28}
29
30/// Construct a response-headers-policy ARN.
31#[must_use]
32pub fn response_headers_policy_arn(account_id: &str, id: &str) -> String {
33    format!("arn:aws:cloudfront::{account_id}:response-headers-policy/{id}")
34}
35
36/// Construct an origin-request-policy ARN.
37#[must_use]
38pub fn origin_request_policy_arn(account_id: &str, id: &str) -> String {
39    format!("arn:aws:cloudfront::{account_id}:origin-request-policy/{id}")
40}
41
42/// Construct a function ARN.
43#[must_use]
44pub fn function_arn(account_id: &str, name: &str) -> String {
45    format!("arn:aws:cloudfront::{account_id}:function/{name}")
46}
47
48/// Construct a key-group ARN.
49#[must_use]
50pub fn key_group_arn(account_id: &str, id: &str) -> String {
51    format!("arn:aws:cloudfront::{account_id}:key-group/{id}")
52}
53
54/// Construct a public-key ARN.
55#[must_use]
56pub fn public_key_arn(account_id: &str, id: &str) -> String {
57    format!("arn:aws:cloudfront::{account_id}:public-key/{id}")
58}
59
60/// Construct a realtime-log ARN.
61#[must_use]
62pub fn realtime_log_arn(account_id: &str, name: &str) -> String {
63    format!("arn:aws:cloudfront::{account_id}:realtime-log-config/{name}")
64}
65
66/// Construct a KVS ARN.
67#[must_use]
68pub fn kvs_arn(account_id: &str, id: &str) -> String {
69    format!("arn:aws:cloudfront::{account_id}:key-value-store/{id}")
70}
71
72/// Extract the distribution ID from a distribution ARN.
73#[must_use]
74pub fn extract_distribution_id(arn: &str) -> Option<&str> {
75    arn.rsplit_once("distribution/").map(|(_, id)| id)
76}