manager: support App Profile template
This commit is contained in:
@@ -148,20 +148,26 @@ enum Profile {
|
||||
policy: String,
|
||||
},
|
||||
|
||||
/// get template of <package-name>
|
||||
/// get template of <id>
|
||||
GetTemplate {
|
||||
/// package name
|
||||
package: String,
|
||||
/// template id
|
||||
id: String,
|
||||
},
|
||||
|
||||
/// set template of <package-name> to <template>
|
||||
/// set template of <id> to <template string>
|
||||
SetTemplate {
|
||||
/// package name
|
||||
package: String,
|
||||
/// template
|
||||
/// template id
|
||||
id: String,
|
||||
/// template string
|
||||
template: String,
|
||||
},
|
||||
|
||||
/// delete template of <id>
|
||||
DeleteTemplate {
|
||||
/// template id
|
||||
id: String,
|
||||
},
|
||||
|
||||
/// list all templates
|
||||
ListTemplates,
|
||||
}
|
||||
@@ -217,10 +223,11 @@ pub fn run() -> Result<()> {
|
||||
Profile::SetSepolicy { package, policy } => {
|
||||
crate::profile::set_sepolicy(package, policy)
|
||||
}
|
||||
Profile::GetTemplate { package } => crate::profile::get_template(package),
|
||||
Profile::SetTemplate { package, template } => {
|
||||
crate::profile::set_template(package, template)
|
||||
}
|
||||
Profile::GetTemplate { id } => crate::profile::get_template(id),
|
||||
Profile::SetTemplate { id, template } => {
|
||||
crate::profile::set_template(id, template)
|
||||
},
|
||||
Profile::DeleteTemplate { id } => crate::profile::delete_template(id),
|
||||
Profile::ListTemplates => crate::profile::list_templates(),
|
||||
},
|
||||
|
||||
|
||||
@@ -18,22 +18,32 @@ pub fn get_sepolicy(pkg: String) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_template(name: String, template: String) -> Result<()> {
|
||||
// ksud doesn't guarteen the correctness of template, it just save
|
||||
pub fn set_template(id: String, template: String) -> Result<()> {
|
||||
ensure_dir_exists(defs::PROFILE_TEMPLATE_DIR)?;
|
||||
let template_file = Path::new(defs::PROFILE_TEMPLATE_DIR).join(name);
|
||||
let template_file = Path::new(defs::PROFILE_TEMPLATE_DIR).join(id);
|
||||
std::fs::write(template_file, template)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_template(name: String) -> Result<()> {
|
||||
let template_file = Path::new(defs::PROFILE_TEMPLATE_DIR).join(name);
|
||||
pub fn get_template(id: String) -> Result<()> {
|
||||
let template_file = Path::new(defs::PROFILE_TEMPLATE_DIR).join(id);
|
||||
let template = std::fs::read_to_string(template_file)?;
|
||||
println!("{template}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn delete_template(id: String) -> Result<()> {
|
||||
let template_file = Path::new(defs::PROFILE_TEMPLATE_DIR).join(id);
|
||||
std::fs::remove_file(template_file)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn list_templates() -> Result<()> {
|
||||
let templates = std::fs::read_dir(defs::PROFILE_TEMPLATE_DIR)?;
|
||||
let templates = std::fs::read_dir(defs::PROFILE_TEMPLATE_DIR);
|
||||
let Ok(templates) = templates else {
|
||||
return Ok(())
|
||||
};
|
||||
for template in templates {
|
||||
let template = template?;
|
||||
let template = template.file_name();
|
||||
|
||||
Reference in New Issue
Block a user