11use std:: path:: PathBuf ;
22
33use anyhow:: Result ;
4+ use bitflags:: bitflags;
45use regex:: Regex ;
56use serde:: { Deserialize , Serialize } ;
67use simplelog:: warn;
@@ -22,49 +23,33 @@ pub struct PluginsConfig {
2223 plugins : Vec < PluginConfig > ,
2324}
2425
25- #[ allow(
26- clippy:: struct_excessive_bools,
27- reason = "Mybe refactor this in the future to use bitflags"
28- ) ]
26+ bitflags ! {
27+ #[ derive( Serialize , Deserialize , Debug , PartialEq , Eq , Clone ) ]
28+ #[ serde( transparent) ]
29+ pub struct Permissions : u32 {
30+ const INHERIT_STDIO = 1 ;
31+ const INHERIT_ARGS = 1 << 1 ;
32+ const INHERIT_ENV = 1 << 2 ;
33+ const INHERIT_NETWORK = 1 << 3 ;
34+ const ALLOW_IP_NAME_LOOKUP = 1 << 4 ;
35+ const ALLOW_HTTP = 1 << 5 ;
36+ const ALLOW_PROCESS = 1 << 6 ;
37+ const ALLOW_REMOVE_DIR_ALL = 1 << 7 ;
38+ const ALL = Self :: INHERIT_STDIO . bits( ) | Self :: INHERIT_ARGS . bits( ) | Self :: INHERIT_ENV . bits( ) | Self :: INHERIT_NETWORK . bits( ) | Self :: ALLOW_IP_NAME_LOOKUP . bits( ) | Self :: ALLOW_HTTP . bits( ) | Self :: ALLOW_PROCESS . bits( ) | Self :: ALLOW_REMOVE_DIR_ALL . bits( ) ;
39+ }
40+ }
41+
2942#[ derive( Serialize , Deserialize ) ]
3043pub struct PluginConfig {
3144 name : String ,
32- inherit_stdio : bool ,
33- inherit_args : bool ,
34- inherit_env : bool ,
35- inherit_network : bool ,
36- allow_ip_name_lookup : bool ,
37- allow_http : bool ,
38- allow_process : bool ,
39- allow_remove_dir_all : bool ,
45+ permissions : Permissions ,
4046
4147 mounts : Vec < Mount > ,
4248}
4349
4450impl PluginConfig {
45- pub fn has_inherit_stdio ( & self ) -> bool {
46- self . inherit_stdio
47- }
48- pub fn has_inherit_args ( & self ) -> bool {
49- self . inherit_args
50- }
51- pub fn has_inherit_env ( & self ) -> bool {
52- self . inherit_env
53- }
54- pub fn has_inherit_network ( & self ) -> bool {
55- self . inherit_network
56- }
57- pub fn has_allow_ip_name_lookup ( & self ) -> bool {
58- self . allow_ip_name_lookup
59- }
60- pub fn _has_allow_http ( & self ) -> bool {
61- self . allow_http
62- }
63- pub fn _has_allow_process ( & self ) -> bool {
64- self . allow_process
65- }
66- pub fn _has_allow_remove_dir_all ( & self ) -> bool {
67- self . allow_remove_dir_all
51+ pub fn get_permissions ( & self ) -> & Permissions {
52+ & self . permissions
6853 }
6954 pub fn get_mounts ( & self ) -> & [ Mount ] {
7055 & self . mounts
0 commit comments