Exemple #1
0
 def selectone(db, cmd):
     try:
         if db.execute(cmd) > 0:
             return OK(db.fetchone())
         else:
             return OK({})
     except Exception as e:
         return FAIL(e)
Exemple #2
0
 def select(db, cmd):
     try:
         if db.execute(cmd) > 0:
             return OK(db.fetchall())
         else:
             return OK([])
     except Exception as e:
         return FAIL(e)
Exemple #3
0
    def set_nas(self, vp=None):
        vp = vp if vp else self.p

        ok, res = self.required(["nasname", "shortname", "secret"])
        if not ok:
            return self.fail_required(res)

        nasname = vp.get("nasname")
        shortname = vp.get("shortname")
        secret = vp.get("secret")

        ok, res = self.get_nas({"nasname": nasname})
        if not ok:
            return FAIL(res)
        if len(res) > 0:
            return fail_duplicated("nasname")
Exemple #4
0
    def del_group(self, vp=None):
        vp = vp if vp else self.p

        ok, res = self.required(["group_id"])
        if not ok:
            return self.fail_required(res)

        group_id = vp.get("group_id")
        ok, res = self.get_groups()
        if not ok:
            return FAIL(res)
        if not len(res):
            return self.fail_unknown("group_id", group_id)

        sql = "DELETE FROM groups WHERE group_id = '{group_id}'".format(
            group_id=group_id)
        return DB.delete(sql)
Exemple #5
0
    def del_user(self, vp=None):
        vp = vp if vp else self.p

        ok, res = self.required(["user_id"])
        if not ok:
            return self.fail_required(res)

        user_id = vp.get("user_id")
        ok, res = self.get_users()
        if not ok:
            return FAIL(res)
        if not len(res):
            return self.fail_unknown("user_id", user_id)

        sql = "DELETE FROM users WHERE user_id = '{user_id}'".format(
            user_id=user_id)
        return DB.delete(sql)
Exemple #6
0
    def mod_user(self, vp=None):
        vp = vp if vp else self.p

        ok, res = self.required(["user_id", "username", "passwd"])
        if not ok:
            return self.fail_required(res)

        user_id = vp.get("user_id")
        ok, res = self.get_users()
        if not ok:
            return FAIL(res)
        if not len(res):
            return self.fail_unknown("user_id", user_id)

        user_id = vp.get("user_id")
        username = vp.get("username")
        passwd = vp.get("passwd")
        sql = """
            UPDATE users SET username='******', passwd='{passwd}'
            WHERE user_id='{user_id}'
        """.format(user_id=user_id, username=username, passwd=passwd)
        return DB.update(sql)
Exemple #7
0
    def mod_group(self, vp=None):
        vp = vp if vp else self.p

        ok, res = self.required(["group_id", "group_name", "parent_group_id"])
        if not ok:
            return self.fail_required(res)

        group_id = vp.get("group_id")
        ok, res = self.get_groups()
        if not ok:
            return FAIL(res)
        if not len(res):
            return self.fail_unknown("group_id", group_id)

        group_id = vp.get("group_id")
        group_name = vp.get("group_name")
        parent_group_id = vp.get("parent_group_id")
        sql = """
            UPDATE groups SET group_name='{group_name}', parent_group_id='{parent_group_id}'
            WHERE group_id='{group_id}'
        """.format(group_id=group_id,
                   group_name=group_name,
                   parent_group_id=parent_group_id)
        return DB.update(sql)
Exemple #8
0
 def update(db, cmd):
     try:
         db.execute(cmd)
         return OK()
     except Exception as e:
         return FAIL(e)
Exemple #9
0
 def callproc(db, procname, args=()):
     try:
         return OK(db.callproc(procname, args))
     except Exception as e:
         return FAIL(e)
Exemple #10
0
 def fail_message(self, msg):
     return FAIL("FAIL: {}".format(msg))
Exemple #11
0
 def fail_unknown(self, name, value):
     return FAIL("unknown {}: {}".format(name, value))
Exemple #12
0
 def fail_required(self, cause):
     return FAIL("required parameter: {}".format(cause))
Exemple #13
0
 def fail_duplicated(self, name):
     return FAIL("duplicate: {}".format(name))