use fakecloud_core::service::AwsRequest;
pub fn now_epoch() -> f64 {
chrono::Utc::now().timestamp_millis() as f64 / 1000.0
}
pub fn database_arn(region: &str, account: &str, name: &str) -> String {
format!("arn:aws:timestream:{region}:{account}:database/{name}")
}
pub fn table_arn(region: &str, account: &str, database: &str, table: &str) -> String {
format!("arn:aws:timestream:{region}:{account}:database/{database}/table/{table}")
}
pub fn scheduled_query_arn(region: &str, account: &str, name: &str, suffix: &str) -> String {
format!("arn:aws:timestream:{region}:{account}:scheduled-query/{name}-{suffix}")
}
pub fn new_id() -> String {
uuid::Uuid::new_v4().simple().to_string().to_uppercase()
}
pub fn table_key(database: &str, table: &str) -> String {
format!("{database}\u{1}{table}")
}
pub fn endpoint_address(req: &AwsRequest) -> String {
req.headers
.get("host")
.and_then(|v| v.to_str().ok())
.filter(|h| !h.is_empty())
.map(|h| h.to_string())
.unwrap_or_else(|| format!("ingest.timestream.{}.amazonaws.com", req.region))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn database_arn_shape() {
assert_eq!(
database_arn("us-east-1", "000000000000", "metrics"),
"arn:aws:timestream:us-east-1:000000000000:database/metrics"
);
}
#[test]
fn table_arn_shape() {
assert_eq!(
table_arn("us-east-1", "000000000000", "metrics", "cpu"),
"arn:aws:timestream:us-east-1:000000000000:database/metrics/table/cpu"
);
}
#[test]
fn table_key_round_trips() {
let k = table_key("metrics", "cpu");
assert_eq!(k.split_once('\u{1}'), Some(("metrics", "cpu")));
}
}