|
1 | | -use std::fmt::Display; |
2 | | - |
3 | | -use strum_macros::EnumCount; |
4 | | - |
5 | | -// ################## |
6 | | -// Admin-specific routes (authentication required) |
7 | | -// ################## |
8 | | -#[derive(EnumCount)] |
9 | | -pub enum AdminRoutes { |
10 | | - StopRunningTask, |
11 | | - PostExecutableEntitlements, |
12 | | - PostExecutableFrameworks, |
13 | | -} |
14 | | - |
15 | | -impl AdminRoutes { |
16 | | - pub fn route_prefix() -> &'static str { |
17 | | - "/api/admin" |
18 | | - } |
19 | | -} |
20 | | - |
21 | | -impl From<AdminRoutes> for String { |
22 | | - fn from(value: AdminRoutes) -> Self { |
23 | | - String::from(&value) |
24 | | - } |
25 | | -} |
26 | | - |
27 | | -impl From<&AdminRoutes> for String { |
28 | | - fn from(value: &AdminRoutes) -> Self { |
29 | | - match value { |
30 | | - AdminRoutes::StopRunningTask => "/tasks/{task_id}/stop".to_string(), |
31 | | - AdminRoutes::PostExecutableEntitlements => "/executable/entitlements".to_string(), |
32 | | - AdminRoutes::PostExecutableFrameworks => "/executable/frameworks".to_string(), |
33 | | - } |
34 | | - } |
35 | | -} |
36 | | - |
37 | | -impl Display for AdminRoutes { |
38 | | - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
39 | | - write!(f, "{}", String::from(self)) |
40 | | - } |
41 | | -} |
42 | | - |
43 | | -// ################## |
44 | | -// Public routes |
45 | | -// ################## |
46 | | -#[derive(EnumCount)] |
47 | | -pub enum PublicRoutes { |
48 | | - // Get stats about server |
49 | | - GetStats, |
50 | | - |
51 | | - // Operating systems |
52 | | - GetOperatingSystems, |
53 | | - GetOperatingSystemById, |
54 | | - |
55 | | - // Devices |
56 | | - GetDevices, |
57 | | - GetDeviceVersions, |
58 | | - |
59 | | - // Operating system versions |
60 | | - GetOperatingSystemVersions, |
61 | | - GetOperatingSystemVersionsById, |
62 | | - GetOperatingSystemVersionsExtended, |
63 | | - GetOperatingSystemVersionsExecutables, |
64 | | - GetOperatingSystemVersionsFrameworks, |
65 | | - |
66 | | - // Executables |
67 | | - GetExecutableVersions, |
68 | | - GetExecutableEntitlements, |
69 | | - GetAllExecutables, |
70 | | - GetAllExecutablesEntitlements, |
71 | | - GetDiffExecutablesOperatingSystemVersion, |
72 | | - |
73 | | - // Entitlements |
74 | | - GetDiffEntitlementsExecutables, |
75 | | - |
76 | | - // Frameworks |
77 | | - GetDiffFrameworksExecutables, |
78 | | - GetExecutableFrameworks, |
79 | | - GetAllFrameworks, |
80 | | - GetFrameworkVersions, |
81 | | - GetFrameworkExecutables, |
82 | | - |
83 | | - // Tasks |
84 | | - GetRunningTasks, |
85 | | -} |
86 | | - |
87 | | -impl PublicRoutes { |
88 | | - pub fn route_prefix() -> &'static str { |
89 | | - "/api/v1" |
90 | | - } |
91 | | -} |
92 | | - |
93 | | -impl From<PublicRoutes> for String { |
94 | | - fn from(value: PublicRoutes) -> Self { |
95 | | - String::from(&value) |
96 | | - } |
97 | | -} |
98 | | - |
99 | | -impl From<&PublicRoutes> for String { |
100 | | - fn from(value: &PublicRoutes) -> Self { |
101 | | - match value { |
102 | | - PublicRoutes::GetStats => "/stats".to_string(), |
103 | | - PublicRoutes::GetOperatingSystems => "/operating_systems/all".to_string(), |
104 | | - PublicRoutes::GetOperatingSystemById => "/operating_systems/{id}".to_string(), |
105 | | - PublicRoutes::GetAllExecutablesEntitlements =>"/operating_systems/{id}/executable_entitlements".to_string(), |
106 | | - PublicRoutes::GetAllExecutables => "/executables/all".to_string(), |
107 | | - PublicRoutes::GetDevices => "/devices/all".to_string(), |
108 | | - PublicRoutes::GetDeviceVersions => "/device/{id}/operating_system_versions".to_string(), |
109 | | - PublicRoutes::GetOperatingSystemVersions => "/operating_system_versions/all".to_string(), |
110 | | - PublicRoutes::GetOperatingSystemVersionsById => "/operating_system_versions/{id}".to_string(), |
111 | | - PublicRoutes::GetOperatingSystemVersionsExtended => "/operating_system_versions/extended".to_string(), |
112 | | - PublicRoutes::GetOperatingSystemVersionsExecutables => "/operating_system_versions/{operating_system_version_id}/executables".to_string(), |
113 | | - PublicRoutes::GetOperatingSystemVersionsFrameworks => "/operating_system_versions/{operating_system_version_id}/frameworks".to_string(), |
114 | | - PublicRoutes::GetExecutableVersions => "/executables/{id}/versions".to_string(), |
115 | | - PublicRoutes::GetExecutableEntitlements => "/executable/{id}/entitlements".to_string(), |
116 | | - PublicRoutes::GetDiffExecutablesOperatingSystemVersion => "/executables/diff/{from_operating_system_version_id}/{to_operating_system_version_id}".to_string(), |
117 | | - PublicRoutes::GetDiffEntitlementsExecutables => "/entitlements/diff/{from_executable_id}/{to_executable_id}".to_string(), |
118 | | - PublicRoutes::GetDiffFrameworksExecutables => "/frameworks/diff/{from_executable_id}/{to_executable_id}".to_string(), |
119 | | - PublicRoutes::GetAllFrameworks => "/frameworks/all".to_string(), |
120 | | - PublicRoutes::GetFrameworkVersions => "/frameworks/{id}/versions".to_string(), |
121 | | - PublicRoutes::GetFrameworkExecutables => "/frameworks/{framework_id}/executables/{operating_system_version_id}".to_string(), |
122 | | - PublicRoutes::GetExecutableFrameworks => "/executable/{executable_operating_system_id}/frameworks".to_string(), |
123 | | - PublicRoutes::GetRunningTasks => "/tasks/running".to_string(), |
124 | | - } |
125 | | - } |
126 | | -} |
127 | | - |
128 | | -impl Display for PublicRoutes { |
129 | | - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
130 | | - write!(f, "{}", String::from(self)) |
131 | | - } |
132 | | -} |
| 1 | +pub const PUBLIC_ROUTES_PREFIX: &str = "/api/v1"; |
| 2 | +pub const ADMIN_ROUTES_PREFIX: &str = "/api/admin"; |
0 commit comments