def get_role_authority(conn): pair = {'sso_admin': ['AUTH_TEST']} data = [] for k in pair: role = db2.unique(conn, 'select role_key from sso_roles where name = ?', k) for v in pair[k]: auth = db2.unique(conn, 'select authority_key from authorities where code = ?', v) data.append((role['ROLE_KEY'], auth['AUTHORITY_KEY'])) for el in data: yield el
def get_menus(conn, app): pair = {'welcome_menu': 'welcomePage'} for k in pair: resource_name = pair[k] resource = db2.unique(conn, 'select resource_key from resources where name = ? and app = ?', resource_name, app) yield ('welcome_menu', None, resource['RESOURCE_KEY'])
def sso_roles(conn): tenant_key = db2.unique(conn, 'select * from SSO_TENANTS where name = ?', 'default')['TENANT_KEY'] roles = db2.query(conn, ''' select * from roles ''') for role in roles: yield(role['ROLE_KEY'], role['NAME'], 1, role['DESC'], tenant_key, datetime.datetime.now())
def sso_users(conn): tenant_key = db2.unique(conn, 'select * from SSO_TENANTS where name = ?', 'default')['TENANT_KEY'] users = db2.query(conn, ''' select * from users ''') for user in users: yield (user['USER_KEY'], user['PASSWORD'], user['USER_NAME'], user['USER_NAME'], tenant_key, user['CREATE_TS'], user['MODIFY_TS'])
def get_authority_resource(conn, app): authorities = ['AUTH_TEST'] for auth in authorities: auth = db2.unique(conn, 'select authority_key from authorities where code = ?', auth) for resource_key in db2.query(conn, 'select resource_key from resources'): yield (auth['AUTHORITY_KEY'], resource_key['RESOURCE_KEY'])
def get_user(conn, name): return db2.unique(conn, 'select * from sso_users where user_name = ?', name)
def get_role(conn, name): return db2.unique(conn, 'select * from sso_roles where name = ?', name)
def get_tenant(conn, name): return db2.unique(conn, 'select * from SSO_TENANTS where name = ?', name)