cedarling 0.0.65

The Cedarling: a high-performance local authorization service powered by the Rust Cedar Engine.
Documentation
// This software is available under the Apache-2.0 license.
// See https://www.apache.org/licenses/LICENSE-2.0.txt for full text.
//
// Copyright (c) 2024, Gluu, Inc.

//! Module that contains structures used as configuration internally in the application
//! It is usefull to use it with DI container
use std::sync::Arc;

use derive_more::derive::Display;
use serde::Serialize;
use uuid7::Uuid;

use crate::log::gen_uuid4;

/// Value is used as ID for application
/// represents a unique ID for application
/// generated one on startup
#[derive(Debug, Clone, Copy, Serialize, PartialEq, Display)]
pub(crate) struct PdpID(pub(crate) Uuid);

impl PdpID {
    pub(crate) fn new() -> Self {
        // we use uuid v4 because it is generated based on random numbers.
        PdpID(gen_uuid4())
    }
}

/// Name of application from configuration.
/// Interned as Arc<str> so clone is cheap.
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct ApplicationName(pub(crate) Arc<str>);

impl serde::Serialize for ApplicationName {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str(&self.0)
    }
}

impl<'de> serde::Deserialize<'de> for ApplicationName {
    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let s = String::deserialize(deserializer)?;
        Ok(Self(s.into()))
    }
}

impl From<String> for ApplicationName {
    fn from(value: String) -> Self {
        Self(value.into())
    }
}