# Path: sam/models/security/rule_template.py
# def get_all():
# def abs_rule_path(path):
# def get_definition(path, cache={}):
#     def __init__(self, path, yml):
#     def import_yml(self, data):
#     def load_exposed(yml):
#     def load_inclusions(self, yml):
#     def load_action_defaults(yml):
#     def get_exposed(self):
#     def get_action_defaults(self):
#     def get_inclusions(self):
# class RuleTemplate(object):


from datetime import datetime
from sam import errors, common
from sam.pages import base
from sam.models.security import rule, rules, rule_template, ruling_process
import re
import web

    def perform_get_command(self, request):
        r_model = rules.Rules(common.db, self.page.user.viewing)
        response = r_model.get_all_rules()
        return response

    def encode_get_response(self, response):
        encoded = {}
        all_rules = []
        for rule in response:
            all_rules.append({
                'id': rule.id,
                'name': rule.get_name(),
                'desc': rule.get_desc(),
                'template': rule.get_def_name(),
                'type': rule.get_type(),
                'active': rule.is_active()
            })
        encoded['all'] = all_rules
        return encoded


class RulesNew(base.HeadlessPost):
    # ----------- GET ------------
    def decode_get_request(self, data):
        # no options for this request
        return None

    def get_proper_name(self, path):
        try:

# Path: sam/models/security/rule_template.py
# def get_all():
# def abs_rule_path(path):
# def get_definition(path, cache={}):
#     def __init__(self, path, yml):
#     def import_yml(self, data):
#     def load_exposed(yml):
#     def load_inclusions(self, yml):
#     def load_action_defaults(yml):
#     def get_exposed(self):
#     def get_action_defaults(self):
#     def get_inclusions(self):
# class RuleTemplate(object):


# Path: sam/pages/rules.py
from datetime import datetime
from sam import errors, common
from sam.pages import base
from sam.models.security import rule, rules, rule_template, ruling_process
import re
import web


    def perform_get_command(self, request):
        r_model = rules.Rules(common.db, self.page.user.viewing)
        response = r_model.get_all_rules()
        return response

    def encode_get_response(self, response):
        encoded = {}
        all_rules = []
        for rule in response:
            all_rules.append({
                'id': rule.id,
                'name': rule.get_name(),
                'desc': rule.get_desc(),
                'template': rule.get_def_name(),
                'type': rule.get_type(),
                'active': rule.is_active()
            })
        encoded['all'] = all_rules
        return encoded


class RulesNew(base.HeadlessPost):
    # ----------- GET ------------
    def decode_get_request(self, data):
        # no options for this request
        return None

    def get_proper_name(self, path):
        try:

            rule = rule_template.get_definition(path)