Skip to main content

junobuild_storage/well_known/
assert.rs

1use crate::constants::{WELL_KNOWN_CUSTOM_DOMAINS, WELL_KNOWN_II_ALTERNATIVE_ORIGINS};
2use crate::errors::JUNO_STORAGE_ERROR_RESERVED_ASSET;
3use crate::types::state::FullPath;
4
5pub fn assert_not_well_known_asset(full_path: &FullPath) -> Result<(), String> {
6    // /.well-known/ic-domains is automatically generated for custom domains
7    assert_not_reserved_path(full_path, WELL_KNOWN_CUSTOM_DOMAINS)?;
8
9    // /.well-known/ii-alternative-origins is automatically generated for alternative origins
10    assert_not_reserved_path(full_path, WELL_KNOWN_II_ALTERNATIVE_ORIGINS)?;
11
12    Ok(())
13}
14
15fn assert_not_reserved_path(full_path: &str, reserved_path: &str) -> Result<(), String> {
16    if full_path == reserved_path {
17        return Err(format!(
18            "{JUNO_STORAGE_ERROR_RESERVED_ASSET} ({reserved_path})"
19        ));
20    }
21    Ok(())
22}