def create_app(config): app = App(config) app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {'/public': config['public_path']}) return app
def setUp(self): warnings.simplefilter("ignore", category=ResourceWarning) warnings.simplefilter("ignore", category=UserWarning) self.rule_id = None self.policies = None self.App = App() self.docker_helper = DockerHelper() self.policy_loader = PolicyLoader()
def main(): try: api_key = argv[1] except IndexError: print("Please pass in an API key for the Open Weather API.") exit(0) app = App(api_key) app.run()
def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.app = App() self.pack() # Window settings self.parent.title("UFTRS Accounting System") self.parent.geometry("360x500") self.initUI()
def setUp(self): warnings.simplefilter("ignore", category=ResourceWarning) warnings.simplefilter("ignore", category=UserWarning) warnings.simplefilter("ignore", category=DeprecationWarning) self.rule_id = None self.policies = None self.App = App() self.kubernetes_helper = KubernetesHelper(namespace=self.namespace, in_cluster=self.in_cluster) self.policy_loader = PolicyLoader()
def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.app = App() self.pack() self.showDeleted = BooleanVar() self.showDeleted.set(0) self.initUI()
def __init__(self,parent): Frame.__init__(self,parent) self.parent = parent self.app = App() self.pack() # Window settings self.parent.title("UFTRS Accounting System") self.parent.geometry("360x500") self.initUI()
def main(opts: Namespace) -> int: config: ApplicationConfig = load_config(opts.config) app = App(config) app.setup_routes() try: app.run_app() return 0 except Exception: return 1
def main(): app = App() try: # exec mysqldump filepath = Mysqldump(app).run() # exec sendmail (parallel) if app.config.use_sendmail: Sendmail(app, filepath).run() # exec webdav (parallel) if app.config.use_storage: Storage(app, filepath).run() except SystemExit: app.logger.critical('error found, process terminated') except Exception as e: app.logger.error(e) finally: sys.exit()
def __init__(self,parent): Frame.__init__(self,parent) self.parent = parent self.app = App() self.pack() # Window settings self.parent.title("UFTRS Program") self.parent.geometry("360x400") #self.parent.state("zoomed") menubar = Menu(self.parent) self.parent.config(menu=menubar) self.logInEntries = [] self.createEntries = [] self.changePasswordEntries = [] self.resetPasswordEntries = [] if User.listUsers()==[]: print "NO USERS YET" self.initUI_FirstRun() else: self.initUI()
def __init__(self): self._app = App(Printer())
class TestE2EKubernetes(unittest.TestCase): namespace = "default" in_cluster = False def setUp(self): warnings.simplefilter("ignore", category=ResourceWarning) warnings.simplefilter("ignore", category=UserWarning) warnings.simplefilter("ignore", category=DeprecationWarning) self.rule_id = None self.policies = None self.App = App() self.kubernetes_helper = KubernetesHelper(namespace=self.namespace, in_cluster=self.in_cluster) self.policy_loader = PolicyLoader() def tearDown(self): if self.rule_id: self.App.delete_rule(self.rule_id) if self.policies: os.remove(self.policies) def test_open_signal(self): print("") dir = tempfile.TemporaryDirectory(prefix="e2e-temp-folder") dirname = dir.name filename = f"{dirname}/secret" test_id = str(uuid.uuid4())[:4] desc = f"e2e test rule {test_id}" data = None with Step(msg=f"check rule({test_id}) creation", emoji=":straight_ruler:"): self.rule_id = self.App.create_cws_rule( desc, "rule for e2e testing", f"e2e_{test_id}", f'open.file.path == "{filename}"', ) with Step(msg="check policies download", emoji=":file_folder:"): self.policies = self.App.download_policies() data = self.policy_loader.load(self.policies) self.assertIsNotNone(data, msg="unable to load policy") with Step(msg="check rule presence in policies", emoji=":bullseye:"): rule = self.policy_loader.get_rule_by_desc(desc) self.assertIsNotNone(rule, msg="unable to find e2e rule") with Step(msg="select pod", emoji=":man_running:"): self.kubernetes_helper.select_pod_name("app=datadog-agent") with Step(msg="check security-agent start", emoji=":customs:"): wait_agent_log("security-agent", self.kubernetes_helper, SECURITY_START_LOG) with Step(msg="check system-probe start", emoji=":customs:"): wait_agent_log("system-probe", self.kubernetes_helper, SYS_PROBE_START_LOG) with Step(msg="wait for host tags(~2m)", emoji=":alarm_clock:"): time.sleep(3 * 60) with Step(msg="upload policies", emoji=":down_arrow:"): self.kubernetes_helper.cp_to_agent( "system-probe", self.policies, "/tmp/runtime-security.d/default.policy") with Step(msg="restart system-probe", emoji=":rocket:"): self.kubernetes_helper.kill_agent("system-probe", "-HUP") time.sleep(60) with Step(msg="check agent event", emoji=":check_mark_button:"): os.system(f"touch {filename}") rule_id = rule["id"] wait_agent_log( "system-probe", self.kubernetes_helper, f"Sending event message for rule `{rule_id}`", ) with Step(msg="check app event", emoji=":chart_increasing_with_yen:"): rule_id = rule["id"] event = self.App.wait_app_log(f"rule_id:{rule_id}") attributes = event["data"][0]["attributes"] self.assertIn("tag1", attributes["tags"], "unable to find tag") self.assertIn("tag2", attributes["tags"], "unable to find tag") with Step(msg="check app signal", emoji=":1st_place_medal:"): rule_id = rule["id"] tag = f"rule_id:{rule_id}" signal = self.App.wait_app_signal(tag) attributes = signal["data"][0]["attributes"] self.assertIn(tag, attributes["tags"], "unable to find rule_id tag") self.assertEqual( rule["id"], attributes["attributes"]["agent"]["rule_id"], "unable to find rule_id tag attribute", ) print(emoji.emojize(":heart_on_fire:"), flush=True)
class DropDownEditor(Frame,object): def __init__(self,parent): Frame.__init__(self,parent) self.parent = parent self.app = App() self.pack() # Window settings self.parent.title("UFTRS Accounting System") self.parent.geometry("360x500") self.initUI() def initUI(self): # Create identifier drop down menu self.identifierSelector = AutocompleteBox(self.parent, label="Select a drop-down menu to edit",toolTip = "placeholder") self.identifierSelector.initDropDown(self.app.listDropDownIdentifiers()) self.identifierSelector.comboBox.bind('<<ComboboxSelected>>', self.handleIdentifierSelect) self.identifierSelector.pack() Label(self.parent).pack() # Create listbox widget listFrame = Frame(self.parent) scrollBar = Scrollbar(listFrame,orient=VERTICAL) self.optionsListBox = Listbox(listFrame, selectmode=SINGLE ,yscrollcommand=scrollBar.set) scrollBar.config(command=self.optionsListBox.yview) scrollBar.pack(side=RIGHT,fill=Y) self.optionsListBox.pack(side=LEFT,fill=BOTH,expand=1) listFrame.pack(fill=BOTH,expand=1) deleteButton = Button(self.parent, text="Delete selection entry", command=self.handleDeleteButton) deleteButton.pack() Label(self.parent, text="OR").pack() Label(self.parent, text="Add a new entry").pack() self.newOptionEntry = Entry(self.parent) self.newOptionEntry.pack() addButton = Button(self.parent, text="Add entry", command=self.handleAddButton) addButton.pack() def refreshList(self): identifier = self.identifierSelector.text options = self.app.listOptions(identifier) self.optionsListBox.delete(0, END) for option in options: self.optionsListBox.insert(END, option) def handleIdentifierSelect(self, *args): self.refreshList() def handleDeleteButton(self): selectedItems = self.optionsListBox.curselection() if len(selectedItems)==0: return isLastItem = False if int(selectedItems[0]) == self.optionsListBox.size()-1: isLastItem = True # Delete entry selectedEntry = self.optionsListBox.get(selectedItems[0]) identifier = self.identifierSelector.text self.app.removeOption(identifier, selectedEntry) self.refreshList() # Select another entry if isLastItem: size = self.optionsListBox.size() self.optionsListBox.select_set(size - 1) else: self.optionsListBox.select_set(selectedItems[0]) def handleAddButton(self): identifier = self.identifierSelector.text newEntry = self.newOptionEntry.get() if newEntry=="" or identifier=="": return self.app.addOption(identifier, newEntry) self.refreshList()
from lib.app import App from lib.printer import Printer from controllers.hello import Hello from controllers.help import Help app = App(Printer()) commands = {"help": Help, "hello": Hello} app.register_commands(commands)
class TestE2EDocker(unittest.TestCase): def setUp(self): warnings.simplefilter("ignore", category=ResourceWarning) warnings.simplefilter("ignore", category=UserWarning) self.rule_id = None self.policies = None self.App = App() self.docker_helper = DockerHelper() self.policy_loader = PolicyLoader() def tearDown(self): if self.rule_id: self.App.delete_rule(self.rule_id) if self.policies: os.remove(self.policies) self.docker_helper.close() def test_open_signal(self): print("") dir = tempfile.TemporaryDirectory(prefix="e2e-temp-folder") dirname = dir.name filename = f"{dirname}/secret" test_id = str(uuid.uuid4())[:4] desc = f"e2e test rule {test_id}" data = None with Step(msg=f"check rule({test_id}) creation", emoji=":straight_ruler:"): self.rule_id = self.App.create_cws_rule( desc, "rule for e2e testing", f"e2e_{test_id}", f'open.file.path == "{filename}"', ) with Step(msg="check policies download", emoji=":file_folder:"): self.policies = self.App.download_policies() data = self.policy_loader.load(self.policies) self.assertIsNotNone(data, msg="unable to load policy") with Step(msg="check rule presence in policies", emoji=":bullseye:"): rule = self.policy_loader.get_rule_by_desc(desc) self.assertIsNotNone(rule, msg="unable to find e2e rule") with Step(msg="check agent start", emoji=":man_running:"): image = os.getenv("DD_AGENT_IMAGE") hostname = f"host_{test_id}" self.datadog_agent_config = gen_datadog_agent_config( hostname=hostname, log_level="DEBUG", tags=["tag1", "tag2"]) self.system_probe_config = gen_system_probe_config( log_level="TRACE", log_patterns=["module.APIServer.*"]) self.container = self.docker_helper.start_agent( image, self.policies, datadog_agent_config=self.datadog_agent_config, system_probe_config=self.system_probe_config, ) self.assertIsNotNone(self.container, msg="unable to start container") self.docker_helper.wait_agent_container() wait_agent_log("security-agent", self.docker_helper, SECURITY_START_LOG) wait_agent_log("system-probe", self.docker_helper, SYS_PROBE_START_LOG) with Step(msg="wait for host tags(~2m)", emoji=":alarm_clock:"): time.sleep(3 * 60) with Step(msg="check agent event", emoji=":check_mark_button:"): os.system(f"touch {filename}") rule_id = rule["id"] wait_agent_log( "system-probe", self.docker_helper, f"Sending event message for rule `{rule_id}`", ) with Step(msg="check app event", emoji=":chart_increasing_with_yen:"): rule_id = rule["id"] event = self.App.wait_app_log(f"rule_id:{rule_id}") attributes = event["data"][0]["attributes"] self.assertIn("tag1", attributes["tags"], "unable to find tag") self.assertIn("tag2", attributes["tags"], "unable to find tag") with Step(msg="check app signal", emoji=":1st_place_medal:"): rule_id = rule["id"] tag = f"rule_id:{rule_id}" signal = self.App.wait_app_signal(tag) attributes = signal["data"][0]["attributes"] self.assertIn(tag, attributes["tags"], "unable to find rule_id tag") self.assertEqual( rule["id"], attributes["attributes"]["agent"]["rule_id"], "unable to find rule_id tag attribute", )
maintainer=__maintainer__, email=__email__)) config = configparser.RawConfigParser() with open(args.config, 'r', encoding='utf-8') as f: config.read_file(f) try: config.hostlist = [(server.strip(), int(port)) for server, port in [ s.split(':') for s in re.split(r'\s+|\s*,\s*', config.get('Database', 'servers')) ]] except ValueError: sys.exit('Invalid servers in configuration file "{}", ' 'expecting something like: ' 'server1.local:9000,server2.local:9000 ...'.format( args.config)) siri = SiriDBClient(username=config.get('Database', 'user'), password=config.get('Database', 'password'), dbname=config.get('Database', 'dbname'), hostlist=config.hostlist, keepalive=True) app = App(config=config, siri=siri, debug_mode=args.debug) app.start() # bye sys.exit(0)
if __name__ == "__main__": import sys, os, inspect from lib.app import App root_path = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) exit_code = App.instance().run(root_path) or 0 exit(exit_code) else: raise ImportError("Run this file directly, don't import it!")
class DropDownEditor(Frame, object): def __init__(self, parent): Frame.__init__(self, parent) self.parent = parent self.app = App() self.pack() # Window settings self.parent.title("UFTRS Accounting System") self.parent.geometry("360x500") self.initUI() def initUI(self): # Create identifier drop down menu self.identifierSelector = AutocompleteBox( self.parent, label="Select a drop-down menu to edit", toolTip="placeholder") self.identifierSelector.initDropDown( self.app.listDropDownIdentifiers()) self.identifierSelector.comboBox.bind('<<ComboboxSelected>>', self.handleIdentifierSelect) self.identifierSelector.pack() Label(self.parent).pack() # Create listbox widget listFrame = Frame(self.parent) scrollBar = Scrollbar(listFrame, orient=VERTICAL) self.optionsListBox = Listbox(listFrame, selectmode=SINGLE, yscrollcommand=scrollBar.set) scrollBar.config(command=self.optionsListBox.yview) scrollBar.pack(side=RIGHT, fill=Y) self.optionsListBox.pack(side=LEFT, fill=BOTH, expand=1) listFrame.pack(fill=BOTH, expand=1) deleteButton = Button(self.parent, text="Delete selection entry", command=self.handleDeleteButton) deleteButton.pack() Label(self.parent, text="OR").pack() Label(self.parent, text="Add a new entry").pack() self.newOptionEntry = Entry(self.parent) self.newOptionEntry.pack() addButton = Button(self.parent, text="Add entry", command=self.handleAddButton) addButton.pack() def refreshList(self): identifier = self.identifierSelector.text options = self.app.listOptions(identifier) self.optionsListBox.delete(0, END) for option in options: self.optionsListBox.insert(END, option) def handleIdentifierSelect(self, *args): self.refreshList() def handleDeleteButton(self): selectedItems = self.optionsListBox.curselection() if len(selectedItems) == 0: return isLastItem = False if int(selectedItems[0]) == self.optionsListBox.size() - 1: isLastItem = True # Delete entry selectedEntry = self.optionsListBox.get(selectedItems[0]) identifier = self.identifierSelector.text self.app.removeOption(identifier, selectedEntry) self.refreshList() # Select another entry if isLastItem: size = self.optionsListBox.size() self.optionsListBox.select_set(size - 1) else: self.optionsListBox.select_set(selectedItems[0]) def handleAddButton(self): identifier = self.identifierSelector.text newEntry = self.newOptionEntry.get() if newEntry == "" or identifier == "": return self.app.addOption(identifier, newEntry) self.refreshList()
parser = argparse.ArgumentParser() parser.add_argument('-i', '--invert', action='store_true', default=False, help="invert screen") parser.add_argument('-f', '--fullscreen', action='store_true', default=False, help="enable full screen") parser.add_argument('-p', '--performance', action='store_true', default=False, help="enable performance mode") parser.add_argument('-d', '--debug', action='store_true', default=False, help="enable debug mode") parser.add_argument('-r', '--dryrun', action='store', type=int, default=-1, help="dryrun testing, time in seconds") args = parser.parse_args() app = App(args=args) app.start()
from lib.app import App app = App() app2 = App() count = 0 def tst(req): # print(req["user"]) global count count += 1 req.user = "******" req.send( bytes("<html><head><title>Title goes here.</title></head>", "utf-8")) req.send(bytes("<body><p>This is test no %d.</p>" % count, "utf-8")) req.send(bytes("<p>You accessed path: %s</p>" % req.path, "utf-8")) req.send(bytes("</body></html>", "utf-8")) print(req.user) def logger(req): print("logging middleware is here.") app.use(logger) app.get("/demo", tst) app.listen(9000)
from lib.app import App app = App() def bootstrap(env): return app.run( action=env.get('REQUEST_METHOD'), path=env.get('REQUEST_URI') )
# -*- coding: utf8 -*- # License avaiavle at zalivator_license.txt in "licenses" directory from lib.app import App # ====================================================================== app = App() app.execute('default')