cyfs_core/app/
app_manager_action.rs

1use crate::coreobj::CoreObjectType;
2use cyfs_base::*;
3use std::collections::HashMap;
4use serde::Serialize;
5
6
7#[derive(Clone, Debug, ProtobufTransform, Serialize)]
8#[cyfs_protobuf_type(crate::codec::protos::DecIpInfo)]
9pub struct DecIpInfo {
10    pub name: String,
11    pub ip: String,
12}
13
14#[derive(Clone, ProtobufTransform, Serialize)]
15#[cyfs_protobuf_type(crate::codec::protos::DecAclInfo)]
16pub struct DecAclInfo {
17    pub name: String,
18    pub acl_info: HashMap<String, bool>,
19}
20
21#[derive(Clone, ProtobufTransform, Serialize)]
22#[cyfs_protobuf_type(crate::codec::protos::RegisterDec)]
23pub struct RegisterDec {
24    pub docker_gateway_ip: String,
25    pub dec_list: HashMap<String, DecIpInfo>,
26}
27
28#[derive(Clone, ProtobufTransform, Serialize)]
29#[cyfs_protobuf_type(crate::codec::protos::UnregisterDec)]
30pub struct UnregisterDec {
31    pub dec_list: HashMap<String, String>,
32}
33
34#[derive(Clone, ProtobufTransform, Serialize)]
35#[cyfs_protobuf_type(crate::codec::protos::ModifyAcl)]
36pub struct ModifyAcl {
37    pub dec_list: HashMap<String, DecAclInfo>,
38}
39
40#[derive(Clone, ProtobufTransform, Serialize)]
41#[cyfs_protobuf_type(crate::codec::protos::app_manager_action_desc::AppManagerActionEnum)]
42pub enum AppManagerActionEnum {
43    RegisterDec(RegisterDec),
44    UnregisterDec(UnregisterDec),
45    ModifyAcl(ModifyAcl),
46}
47
48#[derive(Clone, ProtobufEncode, ProtobufDecode, ProtobufTransform, Serialize)]
49#[cyfs_protobuf_type(crate::codec::protos::AppManagerActionDesc)]
50pub struct AppManagerActionDesc {
51    app_manager_action_enum: AppManagerActionEnum,
52}
53
54impl DescContent for AppManagerActionDesc {
55    fn obj_type() -> u16 {
56        CoreObjectType::AppManagerAction as u16
57    }
58
59    fn format(&self) -> u8 {
60        OBJECT_CONTENT_CODEC_FORMAT_PROTOBUF
61    }
62
63    type OwnerType = Option<ObjectId>;
64    type AreaType = SubDescNone;
65    type AuthorType = SubDescNone;
66    type PublicKeyType = SubDescNone;
67}
68
69#[derive(Clone, Default, ProtobufEmptyEncode, ProtobufEmptyDecode, Serialize)]
70pub struct AppManagerActionBody {}
71
72impl BodyContent for AppManagerActionBody {
73    fn format(&self) -> u8 {
74        OBJECT_CONTENT_CODEC_FORMAT_PROTOBUF
75    }
76}
77
78type AppManagerActionType = NamedObjType<AppManagerActionDesc, AppManagerActionBody>;
79type AppManagerActionBuilder = NamedObjectBuilder<AppManagerActionDesc, AppManagerActionBody>;
80
81pub type AppManagerActionId = NamedObjectId<AppManagerActionType>;
82pub type AppManagerAction = NamedObjectBase<AppManagerActionType>;
83
84pub trait AppManagerActionObj {
85    fn create_register_dec(
86        owner: ObjectId,
87        docker_gateway_ip: String,
88        dec_list: HashMap<String, DecIpInfo>,
89    ) -> Self;
90
91    fn create_unregister_dec(owner: ObjectId, dec_list: HashMap<String, String>) -> Self;
92
93    fn create_modify_acl(owner: ObjectId, dec_list: HashMap<String, DecAclInfo>) -> Self;
94
95    fn action(&self) -> &AppManagerActionEnum;
96}
97
98impl AppManagerActionObj for AppManagerAction {
99    fn create_register_dec(
100        owner: ObjectId,
101        docker_gateway_ip: String,
102        dec_list: HashMap<String, DecIpInfo>,
103    ) -> Self {
104        let action = AppManagerActionEnum::RegisterDec(RegisterDec {
105            docker_gateway_ip,
106            dec_list,
107        });
108
109        let desc = AppManagerActionDesc {
110            app_manager_action_enum: action,
111        };
112        let body = AppManagerActionBody {};
113        AppManagerActionBuilder::new(desc, body)
114            .owner(owner)
115            .build()
116    }
117
118    fn create_unregister_dec(owner: ObjectId, dec_list: HashMap<String, String>) -> Self {
119        let action = AppManagerActionEnum::UnregisterDec(UnregisterDec { dec_list });
120
121        let desc = AppManagerActionDesc {
122            app_manager_action_enum: action,
123        };
124        let body = AppManagerActionBody {};
125        AppManagerActionBuilder::new(desc, body)
126            .owner(owner)
127            .build()
128    }
129
130    fn create_modify_acl(owner: ObjectId, dec_list: HashMap<String, DecAclInfo>) -> Self {
131        let action = AppManagerActionEnum::ModifyAcl(ModifyAcl { dec_list });
132
133        let desc = AppManagerActionDesc {
134            app_manager_action_enum: action,
135        };
136        let body = AppManagerActionBody {};
137        AppManagerActionBuilder::new(desc, body)
138            .owner(owner)
139            .build()
140    }
141
142    fn action(&self) -> &AppManagerActionEnum {
143        &self.desc().content().app_manager_action_enum
144    }
145}