Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload rules while profiling #990

Merged
merged 8 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wipwip
  • Loading branch information
jw3 committed Jan 7, 2024
commit ab3114ce89070a173bf932cf3548622fdf71053d
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/pyo3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fapolicy-app = { path = "../app" }
fapolicy-daemon = { path = "../daemon" }
fapolicy-rules = { path = "../rules" }
fapolicy-trust = { path = "../trust" }
fapolicy-util = { path = "../util" }

[features]
default = []
Expand Down
6 changes: 3 additions & 3 deletions crates/pyo3/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use fapolicy_app::cfg;
use fapolicy_app::sys::deploy_app_state;
use fapolicy_rules::db::Entry::Comment;
use fapolicy_trust::stat::Status::*;
use fapolicy_util::sha::sha256_digest;
// use fapolicy_util::sha::sha256_digest;

use crate::acl::{PyGroup, PyUser};
Expand Down Expand Up @@ -269,9 +270,8 @@ pub fn rule_identity(system: &PySystem) -> PyResult<String> {
Comment(_) => acc,
e => format!("{}\n{}\n", acc, crate::rules::text_for_entry(e)),
});
Ok("".to_owned())
// sha256_digest(txt.as_bytes())
// .map_err(|e| exceptions::PyRuntimeError::new_err(format!("{:?}", e)))
sha256_digest(txt.as_bytes())
.map_err(|e| exceptions::PyRuntimeError::new_err(format!("{:?}", e)))
}

pub fn init_module(_py: Python, m: &PyModule) -> PyResult<()> {
Expand Down
32 changes: 31 additions & 1 deletion fapolicy_analyzer/ui/rules/rules_admin_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import logging
from typing import Any, Optional, Sequence, Tuple

from events import Events

from fapolicy_analyzer import Rule, System
from fapolicy_analyzer.ui.actions import (
Notification,
Expand All @@ -29,13 +31,15 @@
request_rules_text,
)
from fapolicy_analyzer.ui.changeset_wrapper import Changeset, RuleChangeset
from fapolicy_analyzer.ui.reducers.profiler_reducer import ProfilerState
from fapolicy_analyzer.ui.rules.rules_list_view import RulesListView
from fapolicy_analyzer.ui.rules.rules_status_info import RulesStatusInfo
from fapolicy_analyzer.ui.rules.rules_text_view import RulesTextView
from fapolicy_analyzer.ui.store import (
dispatch,
get_notifications_feature,
get_system_feature,
get_profiling_feature,
)
from fapolicy_analyzer.ui.strings import (
APPLY_CHANGESETS_ERROR_MESSAGE,
Expand All @@ -56,13 +60,19 @@
VALIDATION_NOTE_CATEGORY = "invalid rules"


class RulesAdminPage(UIConnectedWidget, UIPage):
class RulesAdminPage(UIConnectedWidget, UIPage, Events):
__events__ = [
"refresh_toolbar",
]

def __init__(self):
features = [
{get_system_feature(): {"on_next": self.on_next_system}},
{get_notifications_feature(): {"on_next": self.on_next_notifications}},
{get_profiling_feature(): {"on_next": self.on_next_profiling_state}},
]
UIConnectedWidget.__init__(self, features=features)
Events.__init__(self)

actions = {
"rules": [
Expand All @@ -80,6 +90,13 @@ def __init__(self):
signals={"clicked": self.on_save_clicked},
sensitivity_func=self.__rules_dirty,
),
UIAction(
name="Profile",
tooltip="Load Rules in Profiler",
icon="media-seek-forward",
signals={"clicked": self.on_load_in_profiler},
sensitivity_func=self.__can_load_in_profiler,
),
],
}
UIPage.__init__(self, actions)
Expand All @@ -100,6 +117,7 @@ def __init__(self):
self._first_pass = True
self.__system: System = None
self.__validation_notifications: Sequence[Notification] = []
self.__profiling_active = False

self._list_view.treeView.connect(
"row-collapsed", self._list_view.on_row_collapsed
Expand Down Expand Up @@ -310,3 +328,15 @@ def on_next_notifications(self, notifications: Sequence[Notification]):
self.__validation_notifications = [
n for n in notifications if n.category == VALIDATION_NOTE_CATEGORY
]

def on_next_profiling_state(self, state: ProfilerState):
if self.__profiling_active != state.running:
print(state)
self.__profiling_active = state.running
self.refresh_toolbar()

def on_load_in_profiler(self, *args):
print("on load in profiler")

def __can_load_in_profiler(self):
return self.__profiling_active