oxinat_core 0.14.1

oxinat xapi-oxidized core library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
use std::{fmt::Debug, path::PathBuf, sync::Arc};

use oxinat_derive::uri_builder_alias;

use crate::{UriBuildError, UriBuilder, Version};

uri_builder_alias!(UserAdminUriBuilder);
ImplUserAdminUriBuilder! {
    (String),
}

macro_rules! username_is_some {
    () => {
        |this: &Self| this.parent.as_ref().is_some_and(|p| p.username.is_some())
    };
}

macro_rules! username_is_none {
    () => {
        |this: &Self| this.parent.as_ref().is_some_and(|p| p.username.is_none())
    };
}

/// Represents all URI endpoints for an admin to
/// manage XNAT users.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/users")]
#[match_path(path = "{parent}/users/{username}")]
pub struct UserUriBuilder<Parent>
where
    Parent: UserAdminUriBuilder,
{
    #[param]
    username: Option<String>,
    #[parent]
    parent: Option<Arc<Parent>>
}

/// Represents URI endpoints for an XNAT admin to
/// manage active users and their sessions.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/active", requires = "username_is_none!()")]
#[match_path(path = "{parent}/active/{username}", requires = "username_is_none!()")]
pub struct ActiveUriBuilder<'a> {
    #[param]
    username: Option<String>,
    #[parent]
    parent: Option<&'a UserUriBuilder<String>>
}

#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/access", requires = "username_is_none!()")]
#[match_path(path = "{parent}/access/{username}", requires = "username_is_none!()")]
pub struct AccessUriBuilder<'a> {
    #[param]
    username: Option<String>,
    #[parent]
    parent: Option<&'a UserUriBuilder<String>>
}

/// Represents URI endpoints for an XNAT admin to
/// manage user cached data.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/cache", requires = "username_is_none!()")]
pub struct CacheUriBuilder<'a> {
    #[parent]
    parent: Option<&'a AccessUriBuilder<'a>>
}

/// Represents the URI path to allow an admin to
/// invalidate user cached data.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/flush")]
#[match_path(path = "{parent}/flush/{username}")]
pub struct CacheFlushUriBuilder<'a> {
    #[param]
    username: Option<String>,
    #[parent]
    parent: Option<&'a CacheUriBuilder<'a>>
}

#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "parent/status")]
pub struct CacheStatusUriBuilder<'a> {
    #[parent]
    parent: Option<&'a CacheUriBuilder<'a>>
}

impl CacheUriBuilder<'_> {
    /// Continue the builder into a
    /// `CacheFlushUriBuilder`.
    pub fn flush(&self) -> CacheFlushUriBuilder {
        CacheFlushUriBuilder::from_parent(self)
    }

    /// Continue the builder into a
    /// `CacheStatusUriBuilder`.
    pub fn status(&self) -> CacheStatusUriBuilder {
        CacheStatusUriBuilder::from_parent(self)
    }
}

#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/displays")]
#[match_path(path = "{parent}/displays/{display}")]
pub struct DisplaysUriBuilder<'a> {
    #[param]
    display: Option<String>,
    #[parent]
    parent: Option<&'a AccessUriBuilder<'a>>
}

impl DisplaysUriBuilder<'_> {
    /// Produces the URI displays/modified
    /// endpoint.
    pub fn modified(&self) -> crate::BuildResult {
        if self.display.is_none() {
            self.build_join("modified")
        } else {
            Err(UriBuildError::Validation.into())
        }
    }
}

#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/permissions", requires = "username_is_none!()")]
pub struct PermissionsUriBuilder<'a> {
    #[parent]
    parent: Option<&'a AccessUriBuilder<'a>>
}

#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/group")]
#[match_path(path = "{parent}/group/{project_id}")]
pub struct GroupPermissionsUriBuilder<'a> {
    #[param]
    project_id: Option<String>,
    #[parent]
    parent: Option<&'a PermissionsUriBuilder<'a>>
}

#[derive(Clone, Debug, UriBuilder)]
pub enum IrregularPermission {
    Find,
    Fix
}

#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/irregular/{irregular_permission}")]
pub struct IrregularPermissionsUriBuilder<'a> {
    #[param]
    irregular_permission: Option<IrregularPermission>,
    #[parent]
    parent: Option<&'a PermissionsUriBuilder<'a>>
}

impl PermissionsUriBuilder<'_> {
    /// Continue the builder into a
    /// `GroupPermissionsUriBuilder`.
    pub fn group(&self) -> GroupPermissionsUriBuilder {
        GroupPermissionsUriBuilder::from_parent(self)
    }

    /// Continue the builder into a
    /// `IrregularPermissionsUriBuilder`.
    pub fn irregular(&self) -> IrregularPermissionsUriBuilder {
        IrregularPermissionsUriBuilder::from_parent(self)
    }
}

impl AccessUriBuilder<'_> {
    /// Produce the URI path access/projects or
    /// access/{username}/projects
    pub fn build_projects(&self) -> crate::BuildResult {
        self.build_join("projects")
    }

    /// Continue the builder into a
    /// `CacheStatusUriBuilder`.
    pub fn cache(&self) -> CacheUriBuilder {
        CacheUriBuilder::from_parent(self)
    }

    /// Continue the builder into a
    /// `DisplaysUriBuilder`.
    pub fn displays(&self) -> DisplaysUriBuilder {
        DisplaysUriBuilder::from_parent(self)
    }

    /// Continue the builder into a
    /// `PermissionsUriBuilder`.
    pub fn permissions(&self) -> PermissionsUriBuilder {
        PermissionsUriBuilder::from_parent(self)
    }
}

/// Represents URI endpoints for an XNAT admin to
/// manage whether a user is enabled or not.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/enabled", requires = "username_is_some!()")]
#[match_path(path = "{parent}/enabled/{flag}", requires = "username_is_some!()")]
pub struct EnabledUriBuilder<'a> {
    #[param]
    flag: Option<bool>,
    #[parent]
    parent: Option<&'a UserUriBuilder<String>>
}

/// Represents URI enpoints for an XNAT admin to
/// manage user groups.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/groups", requires = "username_is_some!()")]
#[match_path(path = "{parent}/groups/{group}", requires = "username_is_some!()")]
pub struct GroupsUriBuilder<'a>
{
    #[param]
    group: Option<String>,
    #[parent]
    parent: Option<&'a UserUriBuilder<String>>
}

/// Represents the URI endpoints for an XNAT admin
/// to access user profile metadata.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/profiles", requires = "username_is_none!()")]
#[match_path(path = "{parent}/profile/{username}", requires = "username_is_none!()")]
pub struct ProfilesUriBuilder<'a> {
    #[param]
    username: Option<String>,
    #[parent]
    parent: Option<&'a UserUriBuilder<String>>
}

/// Represents the URI endpoints for an XNAT admin
/// manage user roles.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/roles", requires = "username_is_some!()")]
#[match_path(path = "{parent}/roles/{role}", requires = "username_is_some!()")]
pub struct RolesUriBuilder<'a> {
    #[param]
    role: Option<String>,
    #[parent]
    parent: Option<&'a UserUriBuilder<String>>
}

/// Represents the URI endpoints for an XNAT admin
/// manage user roles.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/verified", requires = "username_is_some!()")]
#[match_path(path = "{parent}/verified/{flag}", requires = "username_is_some!()")]
pub struct VerifiedUriBuilder<'a> {
    #[param]
    flag: Option<bool>,
    #[parent]
    parent: Option<&'a UserUriBuilder<String>>
}

impl UserUriBuilder<String>
{
    /// Continue the builder into an
    /// `AccessUriBuilder`
    pub fn access(&self) -> AccessUriBuilder {
        AccessUriBuilder::from_parent(&Arc::new(self))
    }

    /// Continue the builder into a
    /// `ActiveUriBuilder`.
    pub fn active(&self) -> ActiveUriBuilder {
        ActiveUriBuilder::from_parent(&Arc::new(self))
    }

    /// Produces the users/current URI endpoint.
    pub fn build_current(&self) -> crate::BuildResult {
        self.build_join("current")
    }

    /// Produces the users/projects URI endpoint.
    pub fn build_projects(&self) -> crate::BuildResult {
        if self.username.is_none() {
            self.build_join("projects")
        } else {
            Err(UriBuildError::Validation.into())
        }
    }

    /// Produces the users/username URI endpoint.
    pub fn build_username(&self) -> crate::BuildResult {
        if self.username.is_none() {
            self.build_join("username")
        } else {
            Err(UriBuildError::Validation.into())
        }
    }

    /// Continue the builder into an
    /// `EnabledUriBuilder`.
    pub fn enabled(&self) -> EnabledUriBuilder {
        EnabledUriBuilder::from_parent(&Arc::new(self))
    }

    /// Continue the builder into a
    /// `GroupsUriBuilder`.
    pub fn groups(&self) -> GroupsUriBuilder {
        GroupsUriBuilder::from_parent(&Arc::new(self))
    }

    /// Continue the builder into a
    /// `ProfilesUriBuilder`.
    pub fn profiles(&self) -> ProfilesUriBuilder {
        ProfilesUriBuilder::from_parent(&Arc::new(self))
    }

    /// Continue the builder into a
    /// `RolesUriBuilder`.
    pub fn roles(&self) -> RolesUriBuilder {
        RolesUriBuilder::from_parent(&Arc::new(self))
    }

    /// Continue the builder into a
    /// `VerifiedUriBuilder`.
    pub fn verified(&self) -> VerifiedUriBuilder {
        VerifiedUriBuilder::from_parent(&Arc::new(self))
    }
}

/// Represents the legacy URI endpoint paths
/// available for a XNAT admin to manage users.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/users")]
#[match_path(path = "{parent}/user/{username}")]
pub struct UsersUriLegacyBuilder<Parent>
where
    Parent: UserAdminUriBuilder,
{
    #[param]
    username: Option<String>,
    #[parent]
    parent: Option<Arc<Parent>>
}

/// Represents the legacy URI endpoint paths
/// available for access to user caches.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/cache", requires = "username_is_none!()")]
pub struct CacheUriLegacyBuilder<'a> {
    #[parent]
    parent: Option<&'a UsersUriLegacyBuilder<String>>
}

/// Represents the legacy URI endpoint paths
/// available for access to user cached resources.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/resources")]
#[match_path(path = "{parent}/resources/{folder}")]
#[match_path(path = "{parent}/resources/{folder}/files/{file}")]
pub struct ResourcesUriBuilder<'a> {
    #[param(map_from = "|pb: &PathBuf| pb.to_str().unwrap().to_string()")]
    file: Option<PathBuf>,
    #[param]
    folder: Option<String>,
    #[parent]
    parent: Option<&'a CacheUriLegacyBuilder<'a>>
}

impl ResourcesUriBuilder<'_> {
    /// Produce the resources/{folder}/files URI
    /// endpoint to access read to all files.
    pub fn build_files(&self) -> crate::BuildResult {
        if self.file.is_none() && self.folder.is_some() {
            self.build_join("projects")
        } else {
            Err(UriBuildError::Validation.into())
        }
    }
}

impl CacheUriLegacyBuilder<'_> {
    /// Continue the builder into a
    /// `ResourcesUriBuilder`
    pub fn resources(&self) -> ResourcesUriBuilder {
        ResourcesUriBuilder::from_parent(&Arc::new(self))
    }
}

/// Represents the URI endpoints available to
/// manage user favorites.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/favorites/Project/{project_id}", requires = "username_is_none!()")]
pub struct FavoritesUriBuilder<'a> {
    #[param]
    project_id: Option<String>,
    #[parent]
    parent: Option<&'a UsersUriLegacyBuilder<String>>
}

/// Represents the URI endpoints available to
/// manage users associated with a project.
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/projects/{project_id}/users", requires = "username_is_none!()")]
#[match_path(path = "{parent}/projects/{project_id}/users/{group_display_name}/{username}", requires = "username_is_none!()")]
pub struct ProjectsUriBuilder<'a> {
    #[param]
    project_id: Option<String>,
    #[param]
    group_display_name: Option<String>,
    #[param]
    username: Option<String>,
    #[parent]
    parent: Option<&'a UsersUriLegacyBuilder<String>>,
}

/// Represents the URI endpoints for user PARs
/// requests (Project Access Request)
#[derive(Clone, Debug, Default, UriBuilder)]
#[match_path(path = "{parent}/pars")]
#[match_path(path = "{parent}/pars/{pars_id}")]
#[match_path(path = "{parent}/projects/{project_id}/pars")]
pub struct ProjectAccessUriBuilder<'a> {
    #[param]
    pars_id: Option<String>,
    #[param]
    project_id: Option<String>,
    #[parent]
    parent: Option<&'a ProjectsUriBuilder<'a>>
}

impl ProjectsUriBuilder<'_> {
    /// Continue the builder into a
    /// `ProjectAccessUriBuilder`.
    pub fn pars(&self) -> ProjectAccessUriBuilder {
        ProjectAccessUriBuilder::from_parent(&Arc::new(self))
    }
}

impl UsersUriLegacyBuilder<String> {
    /// Continue the builder into a
    /// `CacheUriBuilder`.
    pub fn cache(&self) -> CacheUriLegacyBuilder {
        CacheUriLegacyBuilder::from_parent(&Arc::new(self))
    }

    /// Continue the builder into a
    /// `FavoritesUriBuilder`.
    pub fn favorites(&self) -> FavoritesUriBuilder {
        FavoritesUriBuilder::from_parent(&Arc::new(self))
    }

    /// Continue the builder into a
    /// `ProjectsUriBuilder`.
    pub fn projects(&self) -> ProjectsUriBuilder {
        ProjectsUriBuilder::from_parent(&Arc::new(self))
    }
}

/// Represents the URI paths available for
/// endpoints meant for managing users.
pub trait UsersUri: Version {
    /// URI endpoints to access user
    /// administration.
    #[inline]
    fn users(&self) -> UserUriBuilder<String> {
        UserUriBuilder::from_parent(self.root_uri().into())
    }
}

/// Represents the URI paths available for
/// endpoints meant for managing users via the
/// legacy API.
pub trait UsersUriLegacy: Version {
    /// URI legacy endpoints to access user
    /// administration.
    #[inline]
    fn users_legacy(&self) -> UsersUriLegacyBuilder<String> {
        UsersUriLegacyBuilder::from_parent(self.data_uri().into())
    }
}