Home | History | Annotate | Download | only in policyrep
      1 # Copyright 2014, Tresys Technology, LLC
      2 #
      3 # This file is part of SETools.
      4 #
      5 # SETools is free software: you can redistribute it and/or modify
      6 # it under the terms of the GNU Lesser General Public License as
      7 # published by the Free Software Foundation, either version 2.1 of
      8 # the License, or (at your option) any later version.
      9 #
     10 # SETools is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU Lesser General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU Lesser General Public
     16 # License along with SETools.  If not, see
     17 # <http://www.gnu.org/licenses/>.
     18 #
     19 from . import exception
     20 from . import symbol
     21 from . import objclass
     22 
     23 
     24 class PolicyRule(symbol.PolicySymbol):
     25 
     26     """This is base class for policy rules."""
     27 
     28     def __str__(self):
     29         raise NotImplementedError
     30 
     31     @property
     32     def ruletype(self):
     33         """The rule type for the rule."""
     34         return self.qpol_symbol.rule_type(self.policy)
     35 
     36     @property
     37     def source(self):
     38         """
     39         The source for the rule. This should be overridden by
     40         subclasses.
     41         """
     42         raise NotImplementedError
     43 
     44     @property
     45     def target(self):
     46         """
     47         The target for the rule. This should be overridden by
     48         subclasses.
     49         """
     50         raise NotImplementedError
     51 
     52     @property
     53     def tclass(self):
     54         """The object class for the rule."""
     55         return objclass.class_factory(self.policy, self.qpol_symbol.object_class(self.policy))
     56 
     57     @property
     58     def default(self):
     59         """
     60         The default for the rule. This should be overridden by
     61         subclasses.
     62         """
     63         raise NotImplementedError
     64 
     65     @property
     66     def conditional(self):
     67         """The conditional expression for this rule."""
     68         # Most rules cannot be conditional.
     69         raise exception.RuleNotConditional
     70 
     71     def statement(self):
     72         return str(self)
     73