Exemplo n.º 1
0
def setup_testing_db():
    cp = ConfigParser.ConfigParser()
    cp.read("../development.ini")
    config = {  "sqlalchemy.url":
                cp.get("app:main", "sqlalchemy.url", 0, {"here": normpath("%s/.." % dirname(abspath(__file__)))})
             }

    # Setup the SQLAlchemy database engine
    engine = engine_from_config(config, 'sqlalchemy.')
    model.init_model(engine)

    log.info("Create testing user accounts ...")
    random.seed("whatever")
    for i in range(0,100):
        sur_name = sur_names[random.randint(0, len(sur_names)-1)]
        given_name = given_names[random.randint(0, len(given_names)-1)]
        username = "******" % (sur_name, given_name)
        try:
            q = Session.query(model.DKUser)
            r = q.get(username)
            if not r:
                user = model.DKUser()
                user.username = username
                user.roles = ":".join(["", meta.ROLE_USER, ""])
                user.passwd = hashlib.md5("cpksecurity").hexdigest()
                user.master_email = "*****@*****.**" % username
                user.actived = True
                Session.add(user)
                Session.commit()
                log.info(" Account '%s' setup complete." % username)
            else:
                log.info("Account '%s' already setup." % username)
        except Exception, e:
            print e
Exemplo n.º 2
0
 def __call__(self, environ, start_response):
     """Invoke the Controller"""
     # WSGIController.__call__ dispatches to the Controller method
     # the request is routed to. This routing information is
     # available in environ['pylons.routes_dict']
     try:
         return WSGIController.__call__(self, environ, start_response)
     finally:
         Session.remove()
Exemplo n.º 3
0
 def __call__(self, environ, start_response):
     """Invoke the Controller"""
     # WSGIController.__call__ dispatches to the Controller method
     # the request is routed to. This routing information is
     # available in environ['pylons.routes_dict']
     try:
         return WSGIController.__call__(self, environ, start_response)
     finally:
         Session.remove()
Exemplo n.º 4
0
def setup_testing_db():
    cp = ConfigParser.ConfigParser()
    cp.read("../development.ini")
    config = {
        "sqlalchemy.url":
        cp.get("app:main", "sqlalchemy.url", 0,
               {"here": normpath("%s/.." % dirname(abspath(__file__)))})
    }

    # Setup the SQLAlchemy database engine
    engine = engine_from_config(config, 'sqlalchemy.')
    model.init_model(engine)

    log.info("Create testing user accounts ...")
    random.seed("whatever")
    for i in range(0, 100):
        sur_name = sur_names[random.randint(0, len(sur_names) - 1)]
        given_name = given_names[random.randint(0, len(given_names) - 1)]
        username = "******" % (sur_name, given_name)
        try:
            q = Session.query(model.DKUser)
            r = q.get(username)
            if not r:
                user = model.DKUser()
                user.username = username
                user.roles = ":".join(["", meta.ROLE_USER, ""])
                user.passwd = hashlib.md5("cpksecurity").hexdigest()
                user.master_email = "*****@*****.**" % username
                user.actived = True
                Session.add(user)
                Session.commit()
                log.info(" Account '%s' setup complete." % username)
            else:
                log.info("Account '%s' already setup." % username)
        except Exception, e:
            print e
Exemplo n.º 5
0
def init_model(engine):
    """Call me before using any of the tables or classes in the model"""
    Session.configure(bind=engine, autoflush=True, autocommit=False)
Exemplo n.º 6
0
def setup_app(command, conf, vars):
    """Place any commands to setup doorkeeper here"""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    log.info("Initialize database ...")
    Base.metadata.create_all(bind=Session.bind, checkfirst=True)

    #create default privileges
    log.info("Populate default privileges ...")
    log.info("nothing here...")
    log.info("Populate default privileges done.")

    #create default roles
    log.info("Populate default roles ...")
    q = Session.query(model.DKRole)
    if not q.all():
        records = [ model.DKRole(model.meta.ROLE_SYSADMIN),
                model.DKRole(model.meta.ROLE_USER),
        ]
        Session.add_all(records)
        Session.commit()
        log.info("Populate default roles done.")
    else:
        log.info("Roles already exist.")


    log.info("Populate default roles done.")

    #create default system parameters
    log.info("Populate default system parameters ...")
    q = Session.query(model.DKSystem)
    if not q.all():
        records = [ model.DKSystem("master_key_status", model.meta.SS_SERVICE_NO_KEY),
                model.DKSystem("service_key_gen_status", model.meta.SS_SERVICE_NOT_AVAIL),
                model.DKSystem("service_key_revoke_status", model.meta.SS_SERVICE_NOT_AVAIL),
        ]
        Session.add_all(records)
        Session.commit()
        log.info("Populate default system parameters done.")
    else:
        log.info("System parameters exists.")

    #create default admin account
    log.info("Create default admin account ...")
    q = Session.query(model.DKUser)
    r = q.get("sysadmin")
    if not r:
        user = model.DKUser()
        user.username = "******"
        user.roles = ":".join(["", model.meta.ROLE_SYSADMIN, ""])
        user.passwd = hashlib.md5("sysadmin").hexdigest()
        user.master_email = "*****@*****.**"
        user.actived = True
        Session.add(user)
        Session.commit()
        log.info("Admin account setup complete.")
    else:
        log.info("Admin account already setup.")
Exemplo n.º 7
0
def init_model(engine):
    """Call me before using any of the tables or classes in the model"""
    Session.configure(bind=engine, autoflush=True, autocommit=False)
Exemplo n.º 8
0
def setup_app(command, conf, vars):
    """Place any commands to setup doorkeeper here"""
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    log.info("Initialize database ...")
    Base.metadata.create_all(bind=Session.bind, checkfirst=True)

    #create default privileges
    log.info("Populate default privileges ...")
    log.info("nothing here...")
    log.info("Populate default privileges done.")

    #create default roles
    log.info("Populate default roles ...")
    q = Session.query(model.DKRole)
    if not q.all():
        records = [
            model.DKRole(model.meta.ROLE_SYSADMIN),
            model.DKRole(model.meta.ROLE_USER),
        ]
        Session.add_all(records)
        Session.commit()
        log.info("Populate default roles done.")
    else:
        log.info("Roles already exist.")

    log.info("Populate default roles done.")

    #create default system parameters
    log.info("Populate default system parameters ...")
    q = Session.query(model.DKSystem)
    if not q.all():
        records = [
            model.DKSystem("master_key_status", model.meta.SS_SERVICE_NO_KEY),
            model.DKSystem("service_key_gen_status",
                           model.meta.SS_SERVICE_NOT_AVAIL),
            model.DKSystem("service_key_revoke_status",
                           model.meta.SS_SERVICE_NOT_AVAIL),
        ]
        Session.add_all(records)
        Session.commit()
        log.info("Populate default system parameters done.")
    else:
        log.info("System parameters exists.")

    #create default admin account
    log.info("Create default admin account ...")
    q = Session.query(model.DKUser)
    r = q.get("sysadmin")
    if not r:
        user = model.DKUser()
        user.username = "******"
        user.roles = ":".join(["", model.meta.ROLE_SYSADMIN, ""])
        user.passwd = hashlib.md5("sysadmin").hexdigest()
        user.master_email = "*****@*****.**"
        user.actived = True
        Session.add(user)
        Session.commit()
        log.info("Admin account setup complete.")
    else:
        log.info("Admin account already setup.")