def create(host, user, passwd, env, env_read_host, env_write_host, env_user, env_passwd): conn = torch.connect(host, user, passwd, 'hephaestus') guid = str(uuid.uuid4()) vector = secrets.token_bytes(16) sql = ("INSERT INTO islands" "(name, read_host, write_host, user, secret, guid, vector) " "VALUES(%s, %s, %s, %s, " "CBC_ENCRYPT(%s, %s, _binary %s), " "%s, _binary %s)") return torch.execute(conn, sql, (env, env_read_host, env_write_host, env_user, guid, env_passwd, vector, guid, vector))
def update_by_user(db_host, db_user, db_passwd, user_permisson, user_id): result = 0 for up in user_permisson: conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') if up['permission']: sql = ("INSERT INTO permission VALUES(" "%s, %s, %s, NOW()" ") ON DUPLICATE KEY UPDATE " "access_level = %s") params = (up['env'], user_id, up['permission'], up['permission']) else: sql = ("DELETE FROM permission " "WHERE island_name = %s AND god_id = %s") params = (up['env'], user_id) result += torch.execute(conn, sql, params) return result
def update(db_host, db_user, db_passwd, env, read_host, write_host, user, passwd): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') guid = str(uuid.uuid4()) vector = secrets.token_bytes(16) sql = ("UPDATE islands " "SET read_host = %s, " "write_host = %s, " "user = %s, " "secret = CBC_ENCRYPT(%s, %s, _binary %s), " "guid = %s, " "vector = _binary %s " "WHERE `name` = %s") return torch.execute(conn, sql, (read_host if read_host else None, write_host, user, guid, passwd, vector, guid, vector, env))
def create(db_host, db_user, db_passwd, username, passwd, permission_list): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = ("INSERT INTO gods(`name`, `secret`) " "VALUES(%s, SHA2(%s, 256))") result = torch.execute(conn, sql, (username, passwd)) # 添加用户 if result == 0: new_user = get_by_name(db_host, db_user, db_passwd, username) if new_user and new_user[0]['id']: # 添加用户权限 pl = [] user_id = new_user[0]['id'] for p in permission_list: if p['permission'] != 0: pl.append((p['env'], user_id, p['permission'])) conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = ("INSERT INTO permission(island_name, god_id, access_level) " "VALUES(%s, %s, %s)") return torch.execute_many(conn, sql, pl) else: return 1 else: return 1
def update_name(db_host, db_user, db_passwd, user_id, new_name): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = ("UPDATE gods SET name = %s " "WHERE id = %s") return torch.execute(conn, sql, (new_name, user_id))
def update_passwd(db_host, db_user, db_passwd, user_id, passwd): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = ("UPDATE gods SET secret = SHA2(%s, 256) " "WHERE id = %s") return torch.execute(conn, sql, (passwd, user_id))
def delete(db_host, db_user, db_passwd, user_id): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = ("DELETE FROM gods WHERE id = %s") return torch.execute(conn, sql, (user_id, ))
def update_user_status(db_host, db_user, db_passwd, user_status, user_id): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = ("UPDATE gods SET `status` = %s " "WHERE id = %s") return torch.execute(conn, sql, (user_status, user_id))
def update_name(db_host, db_user, db_passwd, env, new_env): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = "UPDATE islands SET `name` = %s WHERE `name` = %s" return torch.execute(conn, sql, (new_env, env))
def delete(db_host, db_user, db_passwd, env): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = "DELETE FROM islands WHERE `name` = %s" return torch.execute(conn, sql, (env, ))