kinetics/tools.rs
1pub mod config;
2pub mod http;
3pub mod queue;
4
5/// Unique resource name
6///
7/// Construct a readable name by escaping non-ascii chars, and appending a hash of
8/// a full unescaped name (for uniqueness reason).
9///
10/// The string is truncated to 64 symbols, which is the maximum length
11/// for a resource name in most platforms.
12pub fn resource_name(user_name: &str, project_name: &str, resource_name: &str) -> String {
13 format!(
14 "{}{}",
15 // Keep readable name to distinguish resources in the dahsboards
16 resource_name
17 .chars()
18 .take(32)
19 .filter(|c| c.is_ascii_alphanumeric())
20 .collect::<String>()
21 .to_lowercase(),
22 // Add hash for uniqueness
23 sha256::digest(format!("{}-{}-{}", user_name, project_name, resource_name))
24 .to_string()
25 .chars()
26 .take(32)
27 .collect::<String>(),
28 )
29}