create a marco to add groups
This commit is contained in:
parent
361fe1d2b5
commit
8413131ed4
97
src/api/groups.rs
Normal file
97
src/api/groups.rs
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
use core::ops::Deref;
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[cfg(feature = "schemars")]
|
||||||
|
use schemars::JsonSchema;
|
||||||
|
|
||||||
|
use crate::api::{
|
||||||
|
BulkCreateDomainExtension, BulkDeleteDomainExtension, BulkReadDomainExtension,
|
||||||
|
BulkUpdateDomainExtension, DomainExtension, DomainType
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
|
||||||
|
pub struct Group {
|
||||||
|
pub name: String,
|
||||||
|
pub alias: String
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Group {
|
||||||
|
fn new(name: String, alias: String) -> Self {
|
||||||
|
Self { name, alias }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
|
||||||
|
pub struct GroupAlias {
|
||||||
|
alias: String
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GroupAlias {
|
||||||
|
fn new(alias: String) -> Self {
|
||||||
|
Self { alias }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
|
||||||
|
pub struct BulkGroupUpdate {
|
||||||
|
name: String,
|
||||||
|
attributes: GroupAlias
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BulkGroupUpdate {
|
||||||
|
fn new(name: String, alias: String) -> Self {
|
||||||
|
Self {
|
||||||
|
name,
|
||||||
|
attributes: GroupAlias::new(alias)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! domain_group {
|
||||||
|
($id:ident, $typ:expr) => {
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
|
||||||
|
pub struct $id(Group);
|
||||||
|
|
||||||
|
impl Deref for $id {
|
||||||
|
type Target = Group;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $id {
|
||||||
|
fn new(name: String, alias: String) -> Self {
|
||||||
|
Self(Group::new(name, alias))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DomainExtension for $id {
|
||||||
|
const DOMAIN_TYPE: DomainType = $typ;
|
||||||
|
|
||||||
|
type CreationRequest = Group;
|
||||||
|
type CreationQuery = ();
|
||||||
|
type ReadQuery = ();
|
||||||
|
type UpdateRequest = GroupAlias;
|
||||||
|
type DeleteQuery = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BulkCreateDomainExtension for $id {}
|
||||||
|
impl BulkReadDomainExtension for $id {
|
||||||
|
type BulkReadQuery = ();
|
||||||
|
}
|
||||||
|
impl BulkUpdateDomainExtension for $id {
|
||||||
|
type BulkUpdateRequest = BulkGroupUpdate;
|
||||||
|
}
|
||||||
|
impl BulkDeleteDomainExtension for $id {}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
domain_group!(HostGroup, DomainType::HostGroupConfig);
|
||||||
|
domain_group!(ServiceGroup, DomainType::ServiceGroupConfig);
|
||||||
|
domain_group!(ContactGroup, DomainType::ContactGroupConfig);
|
||||||
@ -1,5 +1,6 @@
|
|||||||
pub mod folders;
|
pub mod folders;
|
||||||
pub mod hosts;
|
pub mod hosts;
|
||||||
|
pub mod groups;
|
||||||
pub(crate) mod rules;
|
pub(crate) mod rules;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user