def get_by_name(db_host, db_user, db_passwd, username): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = ("SELECT `id`, `name`, dominated, `status`, " "created, modified, last_login " "FROM gods " "WHERE name = '{}'").format(username) return torch.query(conn, sql)
def get_tenant_db(db_host, db_user, db_passwd, tenant_id): conn = torch.connect(db_host, db_user, db_passwd, 'yeeoffice-management') sql = ("SELECT DISTINCT map.DatabaseName AS tenant_db " "FROM merchant m " "INNER JOIN merchantdbmapping map " "ON m.MerchantID = map.MerchantID " "WHERE m.MerchantKey = {}".format(tenant_id)) return torch.query(conn, sql)
def find_duplicate(host, user, passwd, env, env_read_host, env_write_host): conn = torch.connect(host, user, passwd, 'hephaestus') sql = ("SELECT `name`, read_host, user, " "CBC_DECRYPT(guid, secret, vector) AS passwd " "FROM islands " "WHERE `name` = '{}' " "OR read_host = '{}' " "OR write_host = '{}' ").format(env, env_read_host, env_write_host) return torch.query(conn, sql)
def get_detail(db_host, db_user, db_passwd, tenant_id): conn = torch.connect(db_host, db_user, db_passwd, 'yeeoffice-management') sql = ("SELECT " "e.TenantID, m.MerchantName, m.Created, " "DATE_FORMAT(e.ExpireDate, '%Y-%m-%d') AS ExpireDate, " "(SELECT DISTINCT map.DatabaseName AS tenant_db " "FROM merchantdbmapping map " "WHERE map.MerchantID = m.MerchantID " ") AS tenant_db " "FROM yeeoffice_enterprise e " "INNER JOIN merchant m ON e.TenantID = m.MerchantKey " "WHERE TenantID = {}".format(tenant_id)) return torch.query(conn, sql)
def list(db_host, db_user, db_passwd, curr_user_id=None): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') if curr_user_id: sql = ("SELECT `name` FROM islands i " "WHERE EXISTS(SELECT 1 " "FROM permission p " "WHERE i.name = p.island_name " "AND p.god_id = {} " "AND p.access_level >= 1) " "ORDER BY Created").format(curr_user_id) else: sql = "SELECT `name` FROM islands ORDER BY Created" return torch.query(conn, sql)
def get(host, user, passwd, env, curr_user_id=None): conn = torch.connect(host, user, passwd, 'hephaestus') if curr_user_id: sql = ("SELECT i.`name`, i.read_host, i.user, " "CBC_DECRYPT(i.guid, i.secret, i.vector) AS passwd " "FROM islands i " "WHERE `name` = '{}' " "AND EXISTS(SELECT 1 " "FROM permission p " "WHERE i.name = p.island_name " "AND p.god_id = {} " "AND p.access_level >= 1) ").format(env, curr_user_id) else: sql = ("SELECT `name`, read_host, user, " "write_host, " "CBC_DECRYPT(guid, secret, vector) AS passwd " "FROM islands " "WHERE `name` = '{}' ").format(env) return torch.query(conn, sql)
def list(db_host, db_user, db_passwd): conn = torch.connect(db_host, db_user, db_passwd, 'yeeoffice-management') sql = ("SELECT MerchantKey AS id, MerchantName AS `name` " "FROM merchant " "ORDER BY Created DESC") return torch.query(conn, sql)
def list(db_host, db_user, db_passwd): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = ("SELECT id, `name`, dominated FROM gods " "WHERE dominated = FALSE") return torch.query(conn, sql)
def find_duplicate(db_host, db_user, db_passwd, username): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = "SELECT `name` FROM gods WHERE `name` = '{}'".format(username) return torch.query(conn, sql)
def get_by_user(db_host, db_user, db_passwd, user_id): conn = torch.connect(db_host, db_user, db_passwd, 'hephaestus') sql = ("SELECT island_name, access_level " "FROM permission " "WHERE god_id = {}").format(user_id) return torch.query(conn, sql)