cognite/dto/iam/
group.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4use serde_with::skip_serializing_none;
5
6use crate::{to_query, IntoParams};
7
8#[skip_serializing_none]
9#[derive(Serialize, Deserialize, Debug, Clone)]
10#[serde(rename_all = "camelCase")]
11/// A CDF group.
12pub struct Group {
13    /// Internal ID.
14    pub id: u64,
15    /// Human readable name.
16    pub name: String,
17    /// ID of the group in the source IdP.
18    pub source_id: Option<String>,
19    /// Group capabilities object.
20    pub capabilities: ::serde_json::Value,
21    /// Whether this group is deleted.
22    pub is_deleted: bool,
23    /// Time this group was deleted.
24    pub deleted_time: Option<i64>,
25    /// Custom, immutable application specific metadata. String key -> String value.
26    /// Limits: Key are at most 32 bytes. Values are at most 512 bytes.
27    /// Up to 16 key-value pairs. Total size is at most 4096.
28    pub metadata: Option<HashMap<String, String>>,
29}
30
31#[skip_serializing_none]
32#[derive(Serialize, Deserialize, Debug, Clone)]
33#[serde(rename_all = "camelCase")]
34/// Create a CDF group.
35pub struct AddGroup {
36    /// Human readable name.
37    pub name: String,
38    /// ID of the group in the source IdP.
39    pub source_id: Option<String>,
40    /// Group capabilities object.
41    pub capabilities: ::serde_json::Value,
42    /// Custom, immutable application specific metadata. String key -> String value.
43    /// Limits: Key are at most 32 bytes. Values are at most 512 bytes.
44    /// Up to 16 key-value pairs. Total size is at most 4096.
45    pub metadata: Option<HashMap<String, String>>,
46}
47
48impl From<Group> for AddGroup {
49    fn from(value: Group) -> Self {
50        Self {
51            name: value.name,
52            source_id: value.source_id,
53            capabilities: value.capabilities,
54            metadata: value.metadata,
55        }
56    }
57}
58
59#[derive(Debug, Default)]
60/// Query for groups.
61pub struct GroupQuery {
62    /// Include all groups, or just groups for the current user.
63    pub all: Option<bool>,
64}
65
66impl IntoParams for GroupQuery {
67    fn into_params(self) -> Vec<(String, String)> {
68        let mut params = Vec::<(String, String)>::new();
69        to_query("all", &self.all, &mut params);
70        params
71    }
72}