Skip to content

Commit

Permalink
Add lang for config (#991)
Browse files Browse the repository at this point in the history
Adds a sourceview lang for fapolicyd config syntax.

Closes #939
  • Loading branch information
jw3 authored Jan 16, 2024
1 parent 3f2c889 commit 34c3086
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright Concurrent Technologies Corporation 2024
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<language id="fapolicyd-config" name="File Access Policy Daemon Config" version="2.0" _section="Other">
<metadata>
<property name="globs">*.config</property>
<property name="line-comment-start">#</property>
</metadata>

<styles>
<style id="config-eq-sign" name="Separator"/>
<style id="config-key" name="Config key name"/>
</styles>

<definitions>
<context id="config-eq-sign" style-ref="config-eq-sign">
<match>=</match>
</context>

<context id="config-key" style-ref="config-key">
<suffix> =</suffix>
<keyword>permissive</keyword>
<keyword>nice_val</keyword>
<keyword>q_size</keyword>
<keyword>uid</keyword>
<keyword>gid</keyword>
<keyword>do_stat_report</keyword>
<keyword>detailed_report</keyword>
<keyword>db_max_size</keyword>
<keyword>subj_cache_size</keyword>
<keyword>obj_cache_size</keyword>
<keyword>watch_fs</keyword>
<keyword>trust</keyword>
<keyword>integrity</keyword>
<keyword>syslog_format</keyword>
<keyword>rpm_sha256_only</keyword>
<keyword>allow_filesystem_mark</keyword>
</context>

<context id="fapolicyd-config">
<include>
<context ref="config-eq-sign"/>
<context ref="config-key"/>
<context ref="def:shell-like-comment"/>
</include>
</context>
</definitions>
</language>
4 changes: 4 additions & 0 deletions fapolicy_analyzer/resources/sourceview/styles/fapolicyd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@
<!-- File markers -->
<style name="fapolicyd-rules:marker" foreground="#AAAA00" bold="true" italic="true"/>

<!-- Config keys -->
<style name="fapolicyd-config:config-key" foreground="black" underline="true"/>
<style name="fapolicyd-config:config-eq-sign" bold="true"/>

</style-scheme>
2 changes: 1 addition & 1 deletion fapolicy_analyzer/ui/config/config_text_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def on_config_changed(self, buffer):
self.config_changed(self._get_text())

def _get_view_lang_id(self) -> Optional[str]:
return None
return "fapolicyd-config"
8 changes: 3 additions & 5 deletions fapolicy_analyzer/ui/editable_text_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _get_view_lang(self):
try:
with resources.path(
"fapolicy_analyzer.resources.sourceview.language-specs",
lang_id,
f"{lang_id}.lang",
) as path:
if (
os.path.dirname(path.as_posix())
Expand All @@ -74,11 +74,9 @@ def _get_view_lang(self):
)
except Exception as ex:
logging.warning("Could not load the rules language file")
logging.debug(
"Error loading GtkSource language file fapolicyd-rules.lang", ex
)
logging.debug(f"Error loading GtkSource language: {lang_id}", ex)

return lang_manager.get_language("fapolicyd-rules")
return lang_manager.get_language(lang_id)

def _get_view_style(self):
style_manager = GtkSource.StyleSchemeManager.get_default()
Expand Down
2 changes: 1 addition & 1 deletion fapolicy_analyzer/ui/rules/rules_text_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ def on_rules_changed(self, buffer):
self.rules_changed(self._get_text())

def _get_view_lang_id(self) -> Optional[str]:
return "fapolicyd-rules.lang"
return "fapolicyd-rules"
1 change: 1 addition & 0 deletions news/991.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added syntax highlighting to the fapolicyd config editor

0 comments on commit 34c3086

Please sign in to comment.