authly_client/
metadata.rs

1//! Client service metadata.
2
3use authly_common::id::ServiceId;
4
5/// A structure which provides various pieces of information about the service.
6///
7/// Metadata is not required for the service to function, but can be used optionally to
8/// convey application-specific data from the Authly database to the service.
9pub struct ServiceMetadata {
10    pub(crate) entity_id: ServiceId,
11
12    pub(crate) label: String,
13
14    pub(crate) namespaces: Vec<NamespaceMetadata>,
15}
16
17impl ServiceMetadata {
18    /// Get the entity ID ([ServiceId]) of the Authly service this client identifies as.
19    pub fn entity_id(&self) -> ServiceId {
20        self.entity_id
21    }
22
23    /// Get the label the service was given when registered in Authly.
24    pub fn label(&self) -> &str {
25        &self.label
26    }
27
28    /// Get the list of namespace metadata for the namespaces this service has access to.
29    ///
30    /// The list comes in no particular order and should be interpreted as a set.
31    pub fn namespaces(&self) -> &[NamespaceMetadata] {
32        &self.namespaces
33    }
34}
35
36/// Metadata about a namespace the service has access to.
37pub struct NamespaceMetadata {
38    pub(crate) label: String,
39    pub(crate) metadata: Option<serde_json::Map<String, serde_json::Value>>,
40}
41
42impl NamespaceMetadata {
43    /// The label of this namespace as configured in Authly.
44    pub fn label(&self) -> &str {
45        &self.label
46    }
47
48    /// Application-specific metadata of this namespace, encoded as a JSON map.
49    pub fn metadata(&self) -> Option<&serde_json::Map<String, serde_json::Value>> {
50        self.metadata.as_ref()
51    }
52
53    /// Application-specific metadata, owned version.
54    pub fn into_metadata(self) -> Option<serde_json::Map<String, serde_json::Value>> {
55        self.metadata
56    }
57}