Esempio n. 1
0
    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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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')
            """
            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
Esempio n. 7
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')
            """
            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