Skip to content

Commit

Permalink
PolicyQuery: Refactor so overriding __init__ isn't necessary in most …
Browse files Browse the repository at this point in the history
…cases.

Signed-off-by: Chris PeBenito <[email protected]>
  • Loading branch information
pebenito committed Oct 6, 2023
1 parent 2e4a483 commit bc76014
Show file tree
Hide file tree
Showing 32 changed files with 15 additions and 188 deletions.
6 changes: 0 additions & 6 deletions setools/boolquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
from typing import Iterable, Optional

from .descriptors import CriteriaDescriptor
from .mixins import MatchName
from .policyrep import Boolean
from .query import PolicyQuery
Expand Down Expand Up @@ -39,10 +37,6 @@ def default(self, value) -> None:
else:
self._default = bool(value)

def __init__(self, policy, **kwargs) -> None:
super(BoolQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[Boolean]:
"""Generator which yields all Booleans matching the criteria."""
self.log.info("Generating Boolean results from {0.policy}".format(self))
Expand Down
6 changes: 0 additions & 6 deletions setools/boundsquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
import re
from typing import Iterable

from .descriptors import CriteriaDescriptor, CriteriaSetDescriptor
Expand All @@ -30,10 +28,6 @@ class BoundsQuery(PolicyQuery):
child = CriteriaDescriptor("child_regex")
child_regex: bool = False

def __init__(self, policy, **kwargs) -> None:
super(BoundsQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[Bounds]:
"""Generator which yields all matching *bounds statements."""
self.log.info("Generating bounds results from {0.policy}".format(self))
Expand Down
5 changes: 0 additions & 5 deletions setools/categoryquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
from typing import Iterable

from .mixins import MatchAlias, MatchName
Expand All @@ -27,10 +26,6 @@ class CategoryQuery(MatchAlias, MatchName, PolicyQuery):
will be used on the alias names.
"""

def __init__(self, policy, **kwargs) -> None:
super(CategoryQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[Category]:
"""Generator which yields all matching categories."""
self.log.info("Generating category results from {0.policy}".format(self))
Expand Down
6 changes: 0 additions & 6 deletions setools/commonquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
import re
from typing import Iterable

from .mixins import MatchName, MatchPermission
Expand Down Expand Up @@ -32,10 +30,6 @@ class CommonQuery(MatchPermission, MatchName, PolicyQuery):
on the permission names instead of set logic.
"""

def __init__(self, policy, **kwargs) -> None:
super(CommonQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[Common]:
"""Generator which yields all matching commons."""
self.log.info("Generating common results from {0.policy}".format(self))
Expand Down
8 changes: 1 addition & 7 deletions setools/constraintquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
import re
from typing import Iterable, Set
from typing import Iterable

from .descriptors import CriteriaDescriptor, CriteriaSetDescriptor
from .exception import ConstraintUseError
Expand Down Expand Up @@ -62,10 +60,6 @@ class ConstraintQuery(MatchObjClass, MatchPermission, PolicyQuery):
type_regex: bool = False
type_indirect: bool = True

def __init__(self, policy, **kwargs) -> None:
super(ConstraintQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def _match_expr(self, expr, criteria, indirect, regex):
"""
Match roles/types/users in a constraint expression,
Expand Down
6 changes: 0 additions & 6 deletions setools/defaultquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
import re
from typing import cast, Iterable

from .query import PolicyQuery
Expand Down Expand Up @@ -34,10 +32,6 @@ class DefaultQuery(MatchObjClass, PolicyQuery):
default = CriteriaDescriptor(enum_class=DefaultValue)
default_range = CriteriaDescriptor(enum_class=DefaultRangeValue)

def __init__(self, policy, **kwargs) -> None:
super(DefaultQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[AnyDefault]:
"""Generator which yields all matching default_* statements."""
self.log.info("Generating default_* results from {0.policy}".format(self))
Expand Down
5 changes: 0 additions & 5 deletions setools/devicetreeconquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
from typing import Iterable, Optional

from .mixins import MatchContext
Expand Down Expand Up @@ -46,10 +45,6 @@ class DevicetreeconQuery(MatchContext, PolicyQuery):

path: Optional[str] = None

def __init__(self, policy, **kwargs) -> None:
super(DevicetreeconQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[Devicetreecon]:
"""Generator which yields all matching devicetreecons."""
self.log.info("Generating results from {0.policy}".format(self))
Expand Down
11 changes: 3 additions & 8 deletions setools/dta.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,9 @@ def __init__(self, policy: SELinuxPolicy, reverse: bool = False,
all_paths_step_limit: int = 3,
exclude: Optional[Iterable[Union[Type, str]]] = None) -> None:

self.log = logging.getLogger(__name__)
self.policy = policy
self.source = source
self.target = target
self.mode = mode
self.all_paths_max_steps = all_paths_step_limit
self.exclude = exclude # type: ignore # https://github.com/python/mypy/issues/220
self.reverse = reverse
super().__init__(policy, reverse=reverse, source=source, target=target, mode=mode,
all_paths_step_limit=all_paths_step_limit, exclude=exclude)

self.rebuildgraph = True
self.rebuildsubgraph = True

Expand Down
6 changes: 0 additions & 6 deletions setools/fsusequery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
import re
from typing import Iterable

from .descriptors import CriteriaDescriptor, CriteriaSetDescriptor
Expand Down Expand Up @@ -50,10 +48,6 @@ class FSUseQuery(MatchContext, PolicyQuery):
fs = CriteriaDescriptor("fs_regex")
fs_regex: bool = False

def __init__(self, policy, **kwargs) -> None:
super(FSUseQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[FSUse]:
"""Generator which yields all matching fs_use_* statements."""
self.log.info("Generating fs_use_* results from {0.policy}".format(self))
Expand Down
6 changes: 0 additions & 6 deletions setools/genfsconquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
import re
from typing import Iterable, Optional

from .descriptors import CriteriaDescriptor
Expand Down Expand Up @@ -54,10 +52,6 @@ class GenfsconQuery(MatchContext, PolicyQuery):
path = CriteriaDescriptor("path_regex")
path_regex: bool = False

def __init__(self, policy, **kwargs) -> None:
super(GenfsconQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[Genfscon]:
"""Generator which yields all matching genfscons."""
self.log.info("Generating genfscon results from {0.policy}".format(self))
Expand Down
5 changes: 0 additions & 5 deletions setools/ibendportconquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
from typing import Iterable, Optional

from .mixins import MatchContext, MatchName
Expand Down Expand Up @@ -61,10 +60,6 @@ def port(self, value: Optional[int]) -> None:
else:
self._port = None

def __init__(self, policy, **kwargs):
super(IbendportconQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[Ibendportcon]:
"""Generator which yields all matching ibendportcons."""
self.log.info("Generating ibendportcon results from {0.policy}".format(self))
Expand Down
5 changes: 0 additions & 5 deletions setools/ibpkeyconquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# SPDX-License-Identifier: LGPL-2.1-only
#
from ipaddress import IPv6Address
import logging
from typing import Iterable, Optional, Tuple, Union

from .mixins import MatchContext
Expand Down Expand Up @@ -59,10 +58,6 @@ class IbpkeyconQuery(MatchContext, PolicyQuery):
pkeys_superset: bool = False
pkeys_proper: bool = False

def __init__(self, policy, **kwargs):
super(IbpkeyconQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

@property
def pkeys(self) -> Optional[IbpkeyconRange]:
return self._pkeys
Expand Down
15 changes: 5 additions & 10 deletions setools/infoflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Mode(enum.Enum):
source = CriteriaDescriptor(lookup_function="lookup_type")
target = CriteriaDescriptor(lookup_function="lookup_type")
mode = Mode.ShortestPath
booleans: Optional[Mapping[str, bool]]

def __init__(self, policy: SELinuxPolicy, perm_map: PermissionMap, min_weight: int = 1,
source: Optional[Union[Type, str]] = None,
Expand All @@ -72,20 +73,14 @@ def __init__(self, policy: SELinuxPolicy, perm_map: PermissionMap, min_weight: i
exclude: Optional[Iterable[Union[Type, str]]] = None,
booleans: Optional[Mapping[str, bool]] = None) -> None:

self.log = logging.getLogger(__name__)
self.policy = policy
super().__init__(policy, perm_map=perm_map, min_weight=min_weight, source=source,
target=target, mode=mode, all_paths_step_limit=all_paths_step_limit,
exclude=exclude, booleans=booleans)

self._min_weight: int
self._perm_map: PermissionMap
self._all_paths_max_steps: int

self.source = source
self.target = target
self.mode = mode
self.all_paths_max_steps = all_paths_step_limit
self.min_weight = min_weight
self.perm_map = perm_map
self.exclude = exclude # type: ignore # https://github.com/python/mypy/issues/220
self.booleans = booleans
self.rebuildgraph = True
self.rebuildsubgraph = True

Expand Down
5 changes: 0 additions & 5 deletions setools/initsidquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
from typing import Iterable

from .mixins import MatchContext, MatchName
Expand Down Expand Up @@ -42,10 +41,6 @@ class InitialSIDQuery(MatchName, MatchContext, PolicyQuery):
No effect if not using set operations.
"""

def __init__(self, policy, **kwargs):
super(InitialSIDQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[InitialSID]:
"""Generator which yields all matching initial SIDs."""
self.log.info("Generating initial SID results from {0.policy}".format(self))
Expand Down
5 changes: 0 additions & 5 deletions setools/iomemconquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
from typing import Iterable, Optional, Tuple

from .mixins import MatchContext
Expand Down Expand Up @@ -82,10 +81,6 @@ def addr(self, value: Optional[Tuple[int, int]]) -> None:
else:
self._addr = None

def __init__(self, policy, **kwargs) -> None:
super(IomemconQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[Iomemcon]:
"""Generator which yields all matching iomemcons."""
self.log.info("Generating results from {0.policy}".format(self))
Expand Down
5 changes: 0 additions & 5 deletions setools/ioportconquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
from typing import Iterable, Optional, Tuple

from .mixins import MatchContext
Expand Down Expand Up @@ -81,10 +80,6 @@ def ports(self, value: Optional[Tuple[int, int]]) -> None:
else:
self._ports = None

def __init__(self, policy, **kwargs) -> None:
super(IoportconQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[Ioportcon]:
"""Generator which yields all matching ioportcons."""
self.log.info("Generating results from {0.policy}".format(self))
Expand Down
5 changes: 0 additions & 5 deletions setools/mlsrulequery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
from typing import Iterable

from .descriptors import CriteriaDescriptor, CriteriaSetDescriptor
Expand Down Expand Up @@ -48,10 +47,6 @@ class MLSRuleQuery(MatchObjClass, PolicyQuery):
default_superset: bool = False
default_proper: bool = False

def __init__(self, policy, **kwargs) -> None:
super(MLSRuleQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[MLSRule]:
"""Generator which yields all matching MLS rules."""
self.log.info("Generating MLS rule results from {0.policy}".format(self))
Expand Down
5 changes: 0 additions & 5 deletions setools/netifconquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: LGPL-2.1-only
#
import logging
from typing import Iterable

from .mixins import MatchContext, MatchName
Expand Down Expand Up @@ -43,10 +42,6 @@ class NetifconQuery(MatchContext, MatchName, PolicyQuery):
No effect if not using set operations.
"""

def __init__(self, policy, **kwargs) -> None:
super(NetifconQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[Netifcon]:
"""Generator which yields all matching netifcons."""
self.log.info("Generating netifcon results from {0.policy}".format(self))
Expand Down
6 changes: 0 additions & 6 deletions setools/nodeconquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#
import ipaddress

import logging
from socket import AF_INET, AF_INET6
from typing import Iterable, Optional, Union

from .mixins import MatchContext
Expand Down Expand Up @@ -78,10 +76,6 @@ def network(self, value: Optional[Union[str, AnyIPNetwork]]) -> None:
else:
self._network = None

def __init__(self, policy, **kwargs) -> None:
super(NodeconQuery, self).__init__(policy, **kwargs)
self.log = logging.getLogger(__name__)

def results(self) -> Iterable[Nodecon]:
"""Generator which yields all matching nodecons."""
self.log.info("Generating nodecon results from {0.policy}".format(self))
Expand Down
Loading

0 comments on commit bc76014

Please sign in to comment.