Skip to main content

p47h_engine/
utils.rs

1use core_policy::Resource;
2
3/// Helper function to parse resource string into Resource enum
4pub fn parse_resource(resource: &str) -> Resource {
5    if resource == "*" {
6        return Resource::All;
7    }
8
9    if let Some(stripped) = resource.strip_prefix("file:") {
10        return Resource::File(stripped.to_string());
11    }
12
13    if let Some(stripped) = resource.strip_prefix("usb:") {
14        return Resource::Usb(stripped.to_string());
15    }
16
17    if let Some(stripped) = resource.strip_prefix("tunnel:") {
18        return Resource::Tunnel(stripped.to_string());
19    }
20
21    // Try to parse as custom resource (type:path format)
22    if let Some((resource_type, path)) = resource.split_once(':') {
23        Resource::Custom {
24            resource_type: resource_type.to_string(),
25            path: path.to_string(),
26        }
27    } else {
28        // Default to File resource for unqualified paths
29        Resource::File(resource.to_string())
30    }
31}