def __init__(self, dictionary): self.stack = [] dictionary = dictionary.strip('/') package, dictionary = split(dictionary, '/') self._package = Module(package) self._dictionary = '/' + dictionary self._read_node(self._dictionary)
def policy(**kwargs): """Policy helper function Spawns a Policy() object with the rule set specified in the policy.json file. """ global _cached_compiled if _cached_compiled is None: override_file = g.app.path + '/policy.json' luxon = Module('luxon') policy = luxon.read('policy.json') try: policy = js.loads(policy) except JSONDecodeError as exception: raise JSONDecodeError("Invalid Luxon 'policy.json' %s" % exception) if is_file(override_file): with open(override_file, 'r') as override: override = override.read() try: override = js.loads(override) except JSONDecodeError as exception: raise JSONDecodeError("Invalid Override 'policy.json' %s" % exception) else: override = {} policy.update(override) _cached_compiled = compiler(policy) return Policy(_cached_compiled, **kwargs)
def __init__(self, name, path=None, ini=None, defaults=True): # Set Application Name self._name = name # Prepare configuration object self._config = Config() # Config Path self._config_path = ini # Attempt to determine application root. self._path = path = determine_app_root(name, path).rstrip('/') if defaults: self._config.read_dict(default_config) if ini is not False: if ini is None: if is_file(path + '/settings.ini'): self._config.load(path + '/settings.ini') self._config_path = path + '/settings.ini' else: luxon_config = Module('luxon').read('settings.ini') self._config.read_string(if_bytes_to_unicode(luxon_config)) else: self._config_path = ini if is_file(ini): self._config.load(ini) else: log.critical("Unable to load config '%s'" % ini) luxon_config = Module('luxon').read('settings.ini') self._config.read_string(if_bytes_to_unicode(luxon_config)) # When application is called directly from another directory, # still want to be able to detect the app_root by providing # __name__ = __main__, but allowing settings.ini to specify # a better name for the application. if self._config.has_section('application') and self.config.get( 'application', 'name') and name == "__main__": self._name = self.config.get('application', 'name') # Configure Logger. log.configure(self.config) # Load Templating Engine self._jinja = Environment(loader=TachyonicLoader(path)) self._jinja.globals['G'] = g self._jinja.globals['format_datetime'] = format_datetime self._jinja.globals['now'] = now self._jinja.globals['theme'] = Theme(self) # Set APP globally. g.app = self
def setup(args): """Setup Tachyonic Package with Luxon Creates relevant directories and copies relevant files Called when **-i** is used Args: args (parse_args object): arguments gathered from terminal """ path = args.path.rstrip('/') module = Module(args.pkg) no_install = ['luxon', 'psychokinetic'] if args.pkg in no_install: print("Your suppose to install luxon applications not '%s'" % args.pkg) exit() def copy(name, new_extension=None): if module.exists(name): module.copy(name, path + '/' + name, new_extension=new_extension) mkdir(path) if (module.exists('etc')): mkdir("/etc/tachyonic") module.copy('etc', '/etc/tachyonic', 'default') mkdir(joinpath(path, 'tmp')) copy('policy.json', 'default') copy('settings.ini', 'default') try: if exists(path + '/settings.ini'): chmod(path + '/settings.ini', 640) except PermissionError: pass copy('wsgi.py', 'default') copy('static') mkdir('%s/templates/%s' % (path, args.pkg), recursive=True)
def policy(self, req, resp): override_file = g.app.path + '/policy.json' luxon = Module('luxon') policy = luxon.read('policy.json') try: policy = js.loads(policy) except JSONDecodeError as exception: raise JSONDecodeError("Invalid Luxon 'policy.json' %s" % exception) if is_file(override_file): with open(override_file, 'r') as override: override = override.read() try: override = js.loads(override) except JSONDecodeError as exception: raise JSONDecodeError("Invalid Override 'policy.json' %s" % exception) else: override = {} policy.update(override) return render_template('photonic/policy.html', policy=policy, view="RBAC Policy Engine Rules")
class PackageLexer(object): __slots__ = ('_package', '_dictionary', 'stack') def __init__(self, dictionary): self.stack = [] dictionary = dictionary.strip('/') package, dictionary = split(dictionary, '/') self._package = Module(package) self._dictionary = '/' + dictionary self._read_node(self._dictionary) def _read_node(self, dictionary): node = None parentdir = self._dictionary.lstrip('/').split('/') parentdir = '/'.join(parentdir[0:-1]) if isinstance(dictionary, str): fname = None if os.path.isabs(dictionary): fname = dictionary else: fname = os.path.join(parentdir, dictionary) fd = self._package.file(fname) node = Node(fd, dictionary, parentdir) fd.close() else: node = Node(dictionary, '', parentdir) self.stack.append(node) def _cur_dir(self): if self.stack: return self.stack[-1].dir else: return self._dictionary def _get_include(self, line): line = line.split("#", 1)[0].strip() tokens = line.split() if tokens and tokens[0].upper() == '$INCLUDE': return " ".join(tokens[1:]) else: return None def line(self): if self.stack: return self.stack[-1].current else: return -1 def file(self): if self.stack: return self.stack[-1].name else: return '' def __iter__(self): return self def __next__(self): while self.stack: line = self.stack[-1].next() if line is None: self.stack.pop() else: line = line.decode('utf-8') inc = self._get_include(line) if inc: self._read_node(inc) else: return line raise StopIteration
def setup(req, resp): module = Module('calabiyau') mkdir("/var/tachyonic") mkdir("/etc/tachyonic") mkdir("/etc/tachyonic/freeradius") mkdir("/etc/tachyonic/freeradius/proxy") for i in range(6): module.copy('config/freeradius/acct%s.conf' % str(i + 1), '/etc/tachyonic/freeradius/acct%s.conf' % str(i + 1)) module.copy('config/freeradius/auth%s.conf' % str(i + 1), '/etc/tachyonic/freeradius/auth%s.conf' % str(i + 1)) module.copy('config/freeradius/clients', '/etc/tachyonic/freeradius/clients', 'default') module.copy('config/freeradius/log.conf', '/etc/tachyonic/freeradius/log.conf', 'default') module.copy('config/freeradius/dictionary', '/etc/tachyonic/freeradius/dictionary') module.copy('config/freeradius/mods-config', '/etc/tachyonic/freeradius/mods-config') module.copy('config/freeradius/modules', '/etc/tachyonic/freeradius/modules') module.copy('config/freeradius/policy', '/etc/tachyonic/freeradius/policy') module.copy('config/freeradius/proxy/proxy.conf', '/etc/tachyonic/freeradius/proxy/proxy.conf') module.copy('config/freeradius/proxy/radius.conf', '/etc/tachyonic/freeradius/proxy/radius.conf', 'default') module.copy('config/freeradius/proxy.conf', '/etc/tachyonic/freeradius/proxy.conf') module.copy('config/freeradius/python', '/etc/tachyonic/freeradius/python') module.copy('config/freeradius/servers.conf', '/etc/tachyonic/freeradius/servers.conf') module.copy('config/freeradius/sites', '/etc/tachyonic/freeradius/sites')
def setup(req, resp): module = Module('tradius') rm('/etc/freeradius/3.0', recursive=True) module.copy('freeradius', '/etc/freeradius/3.0')