예제 #1
0
파일: project.py 프로젝트: zieglerm/TACTIC
    def get_db_resource_by_search_type(cls, search_type):
        if search_type.startswith('sthpw/'):
            # get the local db_resource
            from pyasm.security import Site
            site = Site.get_site()
            db_resource = None
            if site:
                db_resource = Site.get_db_resource(site, "sthpw")
            if not db_resource:
                db_resource = DbResource.get_default("sthpw")
            return db_resource


        project_code = cls.get_database_by_search_type(search_type)
        project = Project.get_by_code(project_code)
        if not project:
            raise Exception("Error: Project [%s] does not exist" % project_code)


        if search_type.startswith("salesforce/"):
            db_resource_code = "Salesforce"
            db_resource = DbResource.get_by_code(db_resource_code, project_code)
            return db_resource


        db_resource = project.get_project_db_resource()

        return db_resource
예제 #2
0
파일: project.py 프로젝트: hellios78/TACTIC
    def get_project_db_resource(my):
        # get the db resource for attached to this particular project.
        # Not the db_resource for "sthpw/project" for which
        # project.get_db_resource() does
        key = "Project:db_resource:%s" % my.get_code()
        resource = Container.get(key)
        if resource != None:
            return resource

        # the project defines the resource
        database = my.get_database_name()
        assert database

        if database == 'sthpw':
            # get if from the config
            db_resource_code = None
        else:
            db_resource_code = my.get_value("db_resource", no_exception=True)

        if not db_resource_code:
            # this could be any project, not just sthpw
            # already looked at cache, so set use_cache to False
            db_resource = DbResource.get_default(database, use_cache=False)
            Container.put(key, db_resource)
            return db_resource
        #elif isinstance(db_resource_code, DbResource):
        elif DbResource.is_instance(db_resource_code):
            db_resource = db_resource_code
            Container.put(key, db_resource)
            return db_resource

        db_resource_code = db_resource_code.strip()
        search = Search("sthpw/db_resource")
        search.add_filter("code", db_resource_code)
        db_resource_sobj = search.get_sobject()
        if not db_resource_sobj:
            raise TacticException("Database Resource [%s] does not exist" %
                                  db_resource_code)

        host = db_resource_sobj.get_value("host")
        vendor = db_resource_sobj.get_value("vendor")
        host = db_resource_sobj.get_value("host")
        port = db_resource_sobj.get_value("port")
        user = db_resource_sobj.get_value("login")
        password = db_resource_sobj.get_value("password")

        db_resource = DbResource(database=database,
                                 host=host,
                                 port=port,
                                 vendor=vendor,
                                 password=password)
        Container.put(key, db_resource)

        return db_resource
예제 #3
0
    def get_project_db_resource(my):
        # get the db resource for attached to this particular project.
        # Not the db_resource for "sthpw/project" for which
        # project.get_db_resource() does
        key = "Project:db_resource:%s" % my.get_code()
        resource = Container.get(key)
        if resource != None:
            return resource

        # the project defines the resource
        database = my.get_database_name()
        assert database

        if database == 'sthpw':
            # get if from the config
            db_resource_code = None
        else:
            db_resource_code = my.get_value("db_resource", no_exception=True)

        if not db_resource_code:
            # this could be any project, not just sthpw
            # already looked at cache, so set use_cache to False
            db_resource = DbResource.get_default(database, use_cache=False)
            Container.put(key, db_resource)
            return db_resource
        #elif isinstance(db_resource_code, DbResource):
        elif DbResource.is_instance(db_resource_code):   
            db_resource = db_resource_code
            Container.put(key, db_resource)
            return db_resource


        db_resource_code = db_resource_code.strip()
        search = Search("sthpw/db_resource")
        search.add_filter("code", db_resource_code)
        db_resource_sobj = search.get_sobject()
        if not db_resource_sobj:
            raise TacticException("Database Resource [%s] does not exist" % db_resource_code)


        host = db_resource_sobj.get_value("host")
        vendor = db_resource_sobj.get_value("vendor")
        host = db_resource_sobj.get_value("host")
        port = db_resource_sobj.get_value("port")
        user = db_resource_sobj.get_value("login")
        password = db_resource_sobj.get_value("password")
       
        db_resource = DbResource(database=database, host=host, port=port, vendor=vendor, password=password)
        Container.put(key, db_resource)

        return db_resource
예제 #4
0
    def handle_not_logged_in(my, allow_change_admin=True):


        site_obj = Site.get()
        site_obj.set_site("default")

        DbResource.clear_cache()


        from pyasm.widget import WebLoginWdg, BottomWdg
        from tactic.ui.app import TitleTopWdg

        from pyasm.biz import Project
        from tactic.ui.panel import HashPanelWdg


        web = WebContainer.get_web()

        widget = Widget()

        top = TitleTopWdg()
        widget.add(top)
        body = top.get_body()
        body.add_gradient("background", "background", 5, -20)
        body.add_color("color", "color")


        reset_request = web.get_form_value('reset_request') =='true'
        if reset_request:
            from tactic.ui.widget import ResetPasswordWdg
            top.add(ResetPasswordWdg())
        else:
            reset_msg = web.get_form_value('reset_msg')
            if reset_msg:
                web.set_form_value(WebLoginWdg.LOGIN_MSG, reset_msg)


            sudo = Sudo()
            try:
                # get the project from the url because we are still 
                # in the admin project at this stage
                current_project = web.get_context_name()
                try:
                    if current_project != "default":
                        project = Project.get_by_code(current_project)
                        assert project
                except Exception, e:
                    web_wdg = None
                else:
예제 #5
0
    def get_tables_wdg(my):
        
        div = DivWdg()
        div.set_name("Tables")

        div.add("In order to fully register a database, you must bind it to a TACTIC project")
        div.add("<br/>")



        project_code = "mongodb"
        database = "test_database"

        db_resource = DbResource(
                server='localhost',
                vendor='MongoDb',
                database=database
        )


        try:
            connect = DbContainer.get(db_resource)
        except Exception, e:
            div.add("Could not connect")
            div.add_style("padding: 30px")
            div.add("<br/>"*2)
            div.add(str(e))
            return div
예제 #6
0
    def handle_not_logged_in(my, allow_change_admin=True):

        site_obj = Site.get()
        site_obj.set_site("default")

        DbResource.clear_cache()

        from pyasm.widget import WebLoginWdg, BottomWdg
        from tactic.ui.app import TitleTopWdg

        from pyasm.biz import Project
        from tactic.ui.panel import HashPanelWdg

        web = WebContainer.get_web()

        widget = Widget()

        top = TitleTopWdg()
        widget.add(top)
        body = top.get_body()
        body.add_gradient("background", "background", 5, -20)
        body.add_color("color", "color")

        reset_request = web.get_form_value('reset_request') == 'true'
        if reset_request:
            from tactic.ui.widget import ResetPasswordWdg
            top.add(ResetPasswordWdg())
        else:
            reset_msg = web.get_form_value('reset_msg')
            if reset_msg:
                web.set_form_value(WebLoginWdg.LOGIN_MSG, reset_msg)

            web_wdg = None
            #sudo = Sudo()
            try:
                # get the project from the url because we are still
                # in the admin project at this stage
                current_project = web.get_context_name()
                try:
                    if current_project != "default":
                        project = Project.get_by_code(current_project)
                        assert project
                except Exception, e:
                    pass
                else:
예제 #7
0
def execute(db_resource):

    # This works if there is a project set up already with the appropriate
    # db_resource.
    search_type = "table/foofoo?project=db2_test"
    search_type_obj = SearchType.get(search_type)
    search = Search(search_type)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)

    # or (note that there is no project here).  The two arguments
    # are sufficient to determine a search.  Here we want to just "casually"
    # connect to a separate database resource.
    table = 'foofoo'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("description")

    table = 'widget_config'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("config")

    db_resource = DbResource(vendor="MySQL", database="fifi", user="******")
    introspect = DbIntrospect()
    introspect.register("fifi", db_resource)
    table = 'cards'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("description")

    print "sqlite: transaction_log"
    db_resource = DbResource.get_by_code('sqlite', 'sthpw')
    introspect = DbIntrospect()
    introspect.register("sqlite", db_resource)
    search = db_resource.get_search("transaction_log")
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)

    print "mysql: fifi"
    db_resource = DbResource.get_by_code('mysql', 'fifi')
    introspect = DbIntrospect()
    introspect.register("fifi", db_resource)
    search = db_resource.get_search("cards")
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)

    print "mysql: fifi"
    search_type = "table/node0?project=db3_test"
    search = Search(search_type)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
예제 #8
0
파일: project.py 프로젝트: nuxping/TACTIC
    def get_db_resource_by_search_type(cls, search_type):
        if search_type.startswith('sthpw/'):
            # get the local db_resource
            db_resource = DbResource.get_default('sthpw')
            return db_resource

        project_code = cls.get_database_by_search_type(search_type)
        project = Project.get_by_code(project_code)
        if not project:
            raise Exception("Error: Project [%s] does not exist" % project_code)
        db_resource = project.get_project_db_resource()
        return db_resource
예제 #9
0
    def get_db_resource_by_search_type(cls, search_type):
        if search_type.startswith('sthpw/'):
            # get the local db_resource
            db_resource = DbResource.get_default('sthpw')
            return db_resource

        project_code = cls.get_database_by_search_type(search_type)
        project = Project.get_by_code(project_code)
        if not project:
            raise Exception("Error: Project [%s] does not exist" % project_code)
        db_resource = project.get_project_db_resource()
        return db_resource
예제 #10
0
파일: project.py 프로젝트: blezek/TACTIC
    def get_db_resource_by_search_type(cls, search_type):
        if search_type.startswith('sthpw/'):
            # get the local db_resource
            db_resource = DbResource.get_default('sthpw')
            """
            host = Config.get_value("database", "host")
            vendor = Config.get_value("database", "vendor")
            port = Config.get_value("database", "port")
            user = Config.get_value("database", "user")
            password = DbPasswordUtil.get_password()
            db_resource = DbResource(database="sthpw", host=host, port=port, vendor=vendor, user=user, password=password)
            """
            return db_resource


        project_code = cls.get_database_by_search_type(search_type)
        project = Project.get_by_code(project_code)
        db_resource = project.get_project_db_resource()
        return db_resource
예제 #11
0
파일: project.py 프로젝트: hellios78/TACTIC
    def get_db_resource_by_search_type(cls, search_type):
        if search_type.startswith('sthpw/'):
            # get the local db_resource
            db_resource = DbResource.get_default('sthpw')
            """
            host = Config.get_value("database", "host")
            vendor = Config.get_value("database", "vendor")
            port = Config.get_value("database", "port")
            user = Config.get_value("database", "user")
            password = DbPasswordUtil.get_password()
            db_resource = DbResource(database="sthpw", host=host, port=port, vendor=vendor, user=user, password=password)
            """
            return db_resource

        project_code = cls.get_database_by_search_type(search_type)
        project = Project.get_by_code(project_code)
        if not project:
            raise Exception("Error: Project [%s] does not exist" %
                            project_code)
        db_resource = project.get_project_db_resource()
        return db_resource
예제 #12
0
    search = db_resource.get_search("cards")
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)

    print "mysql: fifi"
    search_type = "table/node0?project=db3_test"
    search = Search(search_type)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)


if __name__ == '__main__':

    from pyasm.security import Batch
    Batch(project_code="project")

    # register this resource
    db_resource = DbResource(vendor="MySQL",
                             host="localhost",
                             database="db2_test",
                             user="******")

    # auto register all of the tables there
    introspect = DbIntrospect()
    import time
    start = time.time()
    introspect.register("db2_test", db_resource)
    print "time: ", time.time() - start

    execute(db_resource)
예제 #13
0
def execute(db_resource):

    # This works if there is a project set up already with the appropriate
    # db_resource.
    search_type = "table/foofoo?project=db2_test"
    search_type_obj = SearchType.get(search_type)
    search = Search(search_type)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)


    # or (note that there is no project here).  The two arguments
    # are sufficient to determine a search.  Here we want to just "casually"
    # connect to a separate database resource.
    table = 'foofoo'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("description")


    table = 'widget_config'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("config")



    db_resource = DbResource(vendor="MySQL", database="fifi", user="******")
    introspect = DbIntrospect()
    introspect.register("fifi", db_resource)
    table = 'cards'
    search = db_resource.get_search(table)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
    for sobject in sobjects:
        print sobject.get_code(), sobject.get_value("description")


    print "sqlite: transaction_log"
    db_resource = DbResource.get_by_code('sqlite','sthpw')
    introspect = DbIntrospect()
    introspect.register("sqlite", db_resource)
    search = db_resource.get_search("transaction_log")
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)



    print "mysql: fifi"
    db_resource = DbResource.get_by_code('mysql','fifi')
    introspect = DbIntrospect()
    introspect.register("fifi", db_resource)
    search = db_resource.get_search("cards")
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)


    print "mysql: fifi"
    search_type = "table/node0?project=db3_test"
    search = Search(search_type)
    sobjects = search.get_sobjects()
    print "length: ", len(sobjects)
예제 #14
0
    def get_tables_wdg(self):

        div = DivWdg()
        div.set_name("Tables")

        div.add(
            "In order to fully register a database, you must bind it to a TACTIC project"
        )
        div.add("<br/>")

        project_code = "mongodb"
        database = "test_database"

        db_resource = DbResource(server='localhost',
                                 vendor='MongoDb',
                                 database=database)

        try:
            connect = DbContainer.get(db_resource)
        except Exception as e:
            div.add("Could not connect")
            div.add_style("padding: 30px")
            div.add("<br/>" * 2)
            div.add(str(e))
            return div

        # Bind project to this resource
        database_text = TextWdg("database")
        div.add("Database: ")
        div.add(database_text)

        div.add("<br/>" * 2)

        project_text = TextWdg("project")
        div.add("Project Code: ")
        div.add(project_text)

        div.add("<br/>")
        div.add("<hr/>")

        # connect and introspect the tables in this database
        tables = connect.get_tables()

        table = Table()
        div.add(table)
        table.set_max_width()

        for table_name in tables:
            table.add_row()
            search_type = "table/%s?project=%s" % (table_name, project_code)

            td = table.add_cell()
            icon = IconWdg("View Table", IconWdg.FOLDER_GO)
            td.add(icon)
            icon.add_behavior({
                'type':
                'click_up',
                'search_type':
                search_type,
                'cbjs_action':
                '''
                var class_name = 'tactic.ui.panel.ViewPanelWdg';
                var kwargs = {
                    search_type: bvr.search_type
                }
                spt.panel.load_popup("table", class_name, kwargs);
                '''
            })

            td = table.add_cell()
            td.add(table_name)

            td = table.add_cell()
            search = Search(search_type)
            count = search.get_count()
            td.add(" %s item/s" % count)

            columns = search.get_columns()
            td = table.add_cell()
            td.add(columns)

            # search_type
            td = table.add_cell()
            text = TextWdg("search_type")
            td.add(text)
            new_search_type = "%s/%s" % (project_code, table_name)
            text.set_value(new_search_type)

        register_div = DivWdg()
        div.add(register_div)
        register_div.add_style("padding: 20px")

        button = ActionButtonWdg(title="Register")
        register_div.add(button)

        return div
예제 #15
0
    def handle_not_logged_in(self, allow_change_admin=True):

        site_obj = Site.get()
        site_obj.set_site("default")

        DbResource.clear_cache()

        from pyasm.widget import WebLoginWdg, BottomWdg
        from tactic.ui.app import TitleTopWdg

        from pyasm.biz import Project
        from tactic.ui.panel import HashPanelWdg

        web = WebContainer.get_web()

        widget = Widget()

        top = TitleTopWdg()
        widget.add(top)
        body = top.get_body()
        #body.add_gradient("background", "background", 5, -20)
        body.add_color("background", "background")
        body.add_color("color", "color")

        reset_request = web.get_form_value('reset_request') == 'true'
        if reset_request:
            from tactic.ui.widget import ResetPasswordWdg
            top.add(ResetPasswordWdg())
        else:
            reset_msg = web.get_form_value('reset_msg')
            if reset_msg:
                web.set_form_value(WebLoginWdg.LOGIN_MSG, reset_msg)

            web_wdg = None
            sudo = Sudo()
            try:
                # get the project from the url because we are still
                # in the admin project at this stage
                current_project = web.get_context_name()
                try:
                    if current_project != "default":
                        project = Project.get_by_code(current_project)
                        assert project
                except Exception as e:
                    pass
                else:

                    # custom global site login widget
                    if not current_project or current_project == "default":
                        current_project = Project.get_default_project()
                    if current_project and current_project != "default":
                        try:
                            Project.set_project(current_project)
                        except SecurityException as e:
                            print(e)
                            if 'is not permitted to view project' not in e.__str__(
                            ):
                                raise

                        if not web_wdg:
                            web_wdg = site_obj.get_login_wdg()

                        if web_wdg:
                            if not isinstance(web_wdg, basestring):
                                web_wdg = web_wdg.get_buffer_display()
                            top.add(web_wdg)
                    else:
                        web_wdg = None

                # display default web login
                if not web_wdg:
                    # get login screen from Site
                    link = "/%s" % "/".join(self.hash)
                    web_wdg = site_obj.get_login_wdg(link)
                    if not web_wdg:
                        # else get the default one
                        web_wdg = WebLoginWdg(
                            allow_change_admin=allow_change_admin)

                    top.add(web_wdg)

            finally:
                # sudo out of scope here
                sudo.exit()
                pass

        # create a web app and run it through the pipeline
        web_app = WebApp()
        web_app.get_display(widget)
        return
예제 #16
0
파일: app_server.py 프로젝트: mincau/TACTIC
    def handle_not_logged_in(self, allow_change_admin=True):


        site_obj = Site.get()
        site_obj.set_site("default")

        DbResource.clear_cache()


        from pyasm.widget import WebLoginWdg, BottomWdg
        from tactic.ui.app import TitleTopWdg

        from pyasm.biz import Project
        from tactic.ui.panel import HashPanelWdg


        web = WebContainer.get_web()

        widget = Widget()

        top = TitleTopWdg()
        widget.add(top)
        body = top.get_body()
        #body.add_gradient("background", "background", 5, -20)
        body.add_color("background", "background")
        body.add_color("color", "color")


        reset_request = web.get_form_value('reset_request') =='true'
        if reset_request:
            from tactic.ui.widget import ResetPasswordWdg
            top.add(ResetPasswordWdg())
        else:
            reset_msg = web.get_form_value('reset_msg')
            if reset_msg:
                web.set_form_value(WebLoginWdg.LOGIN_MSG, reset_msg)

            web_wdg = None
            sudo = Sudo()
            try:
                # get the project from the url because we are still 
                # in the admin project at this stage
                current_project = web.get_context_name()
                try:
                    if current_project != "default":
                        project = Project.get_by_code(current_project)
                        assert project
                except Exception as e:
                    pass
                else:

                    # custom global site login widget
                    if not current_project or current_project == "default":
                        current_project = Project.get_default_project()
                    if current_project and current_project != "default":
                        try:
                            Project.set_project(current_project)
                        except SecurityException as e:
                            print(e)
                            if 'is not permitted to view project' not in e.__str__():
                                raise


                        if not web_wdg:
                            web_wdg = site_obj.get_login_wdg()

                        if web_wdg:
                            if not isinstance(web_wdg, basestring):
                                web_wdg = web_wdg.get_buffer_display()
                            top.add(web_wdg)
                    else:
                        web_wdg = None

                # display default web login
                if not web_wdg:
                    # get login screen from Site
                    link = "/%s" % "/".join(self.hash)
                    web_wdg = site_obj.get_login_wdg(link)
                    if not web_wdg:
                        # else get the default one
                        web_wdg = WebLoginWdg(allow_change_admin=allow_change_admin)
                    
                    top.add(web_wdg)

            finally:
                # sudo out of scope here
                sudo.exit()
                pass


        # create a web app and run it through the pipeline
        web_app = WebApp()
        web_app.get_display(widget)
        return