def secure_supertenant(username: str = "okapi_admin", password: str = "admin"): tenant = "supertenant" permissions = [ "okapi.all", "okapi.proxy.pull.modules.post", "perms.all", "login.all", "users.all" ] module_list = ['permissions', 'users', 'login'] o = OkapiClient() modules = [m["id"] for m in o.get_modules() if m["name"] in module_list] res = o.enable_modules(modules, tenant) # print(res) userServices = UserService(tenant) log.info("Create user record.") user = userServices.create_user( username, password, permissions=permissions) authtoken = [m["id"] for m in o.get_modules() if m["name"] == "authtoken"][0] res = o.enable_module(authtoken, tenant) # print(res) login_supertenant(username, password) print("Successfully secured Okapi.")
def print_okapi_all(): pp = pprint.PrettyPrinter(indent=2) okapi = OkapiClient() print("# Env") pp.pprint(okapi.get_env()) print("# Nodes") pp.pprint(okapi.get_nodes()) print("# Modules") pp.pprint(okapi.get_modules()) print("# Deployed Modules") pp.pprint(okapi.get_deployed_modules()) print("# Tenants") pp.pprint(okapi.get_tenants())
def add_modules(modules: list): added_modules = [] okapi = OkapiClient() def add_requirements(name, mod): log.debug("Add requirements for %s", name) for require in mod.get_requires(): log.debug("find %s", require) for module in modules: name = module.get_modId() if require in module.get_provides(): log.debug("Found in %s", name) if not name in added_modules: log.debug("Prepare %s", name) add_requirements(name, module) log.info("Add %s", name) okapi.add_module(module) added_modules.append(name) else: log.debug("%s already added", name) for module in modules: name = module.get_modId() if not name in added_modules: log.debug("Prepare %s", name) add_requirements(name, module) log.info("Add %s", name) okapi.add_module(module) added_modules.append(name) else: log.debug("%s already added", name) success = True added_modules = [m["id"] for m in okapi.get_modules()] for module in modules: name = module.get_modId() if not name in added_modules: log.error("Can not add modul %s", name) success = False return success