class Injector: def __init__(self, debug=False, config_dir=None): self.platform_config = PlatformConfig(config_dir=config_dir) if not logger.factory_instance: console = True if debug else False level = logging.DEBUG if debug else logging.INFO logger.init(level, console, join(self.platform_config.get_platform_log())) self.user_platform_config = PlatformUserConfig(self.platform_config.get_user_config()) self.log_aggregator = Aggregator(self.platform_config) self.platform_app_paths = AppPaths(PLATFORM_APP_NAME, self.platform_config) self.platform_app_paths.get_data_dir() self.versions = Versions(self.platform_config) self.redirect_service = RedirectService(self.user_platform_config, self.versions) self.port_config = PortConfig(self.platform_app_paths.get_data_dir()) self.nat_pmp_port_mapper = NatPmpPortMapper() self.upnp_port_mapper = UpnpPortMapper(UPnP()) self.port_mapper_factory = PortMapperFactory(self.nat_pmp_port_mapper, self.upnp_port_mapper) self.port_drill_factory = PortDrillFactory(self.user_platform_config, self.port_config, self.port_mapper_factory) self.device_info = DeviceInfo(self.user_platform_config, self.port_config) if self.platform_config.get_installer() == 'sam': self.sam = SamStub(self.platform_config, self.device_info) else: self.sam = Snap(self.platform_config, self.device_info) self.platform_cron = PlatformCron(self.platform_config) self.systemctl = Systemctl(self.platform_config) self.ldap_auth = LdapAuth(self.platform_config, self.systemctl) self.event_trigger = EventTrigger(self.sam, self.platform_config) self.nginx = Nginx(self.platform_config, self.systemctl, self.device_info) self.certbot_genetator = CertbotGenerator(self.platform_config, self.user_platform_config, self.device_info, self.sam) self.tls = CertificateGenerator(self.platform_config, self.user_platform_config, self.device_info, self.nginx, self.certbot_genetator) self.device = Device(self.platform_config, self.user_platform_config, self.redirect_service, self.port_drill_factory, self.sam, self.platform_cron, self.ldap_auth, self.event_trigger, self.tls, self.nginx) self.internal = Internal(self.platform_config, self.device, self.redirect_service, self.log_aggregator) self.path_checker = PathChecker(self.platform_config) self.lsblk = Lsblk(self.platform_config, self.path_checker) self.hardware = Hardware(self.platform_config, self.event_trigger, self.lsblk, self.path_checker, self.systemctl) self.network = Network() self.public = Public(self.platform_config, self.user_platform_config, self.device, self.device_info, self.sam, self.hardware, self.redirect_service, self.log_aggregator, self.certbot_genetator, self.port_mapper_factory, self.network, self.port_config) self.udev = Udev(self.platform_config) def get_app_paths(self, app_name): return AppPaths(app_name, self.platform_config) def get_app_setup(self, app_name): return AppSetup(app_name, self.get_app_paths(app_name), self.nginx, self.hardware, self.device_info, self.device, self.user_platform_config, self.systemctl)
def get_app_setup(app_name): injector = get_injector() app_paths = AppPaths(app_name, injector.platform_config) app_setup = AppSetup(app_name, app_paths, injector.nginx, injector.hardware, injector.info, injector.device, injector.user_platform_config, injector.systemctl) return app_setup
class Injector: def __init__(self, debug=False): self.platform_config = PlatformConfig() if not logger.factory_instance: console = True if debug else False level = logging.DEBUG if debug else logging.INFO logger.init(level, console, join(self.platform_config.get_platform_log())) self.user_platform_config = PlatformUserConfig(self.platform_config.get_user_config()) self.log_aggregator = Aggregator(self.platform_config) self.platform_app_paths = AppPaths(PLATFORM_APP_NAME, self.platform_config) self.platform_app_paths.get_data_dir() self.redirect_service = RedirectService(self.user_platform_config, platform_version) self.port_config = PortConfig(self.platform_app_paths.get_data_dir()) self.nat_pmp_port_mapper = NatPmpPortMapper() self.upnp_port_mapper = UpnpPortMapper(UPnP()) self.port_drill_factory = PortDrillFactory(self.user_platform_config, self.port_config, self.nat_pmp_port_mapper, self.upnp_port_mapper) self.info = DeviceInfo(self.user_platform_config, self.port_config) self.sam = SamStub(self.platform_config, self.info) self.platform_cron = PlatformCron(self.platform_config) self.ldap_auth = LdapAuth(self.platform_config) self.event_trigger = EventTrigger(self.sam) self.nginx = Nginx(self.platform_config) self.tls = Tls(self.platform_config, self.info, self.nginx) self.device = Device(self.platform_config, self.user_platform_config, self.redirect_service, self.port_drill_factory, self.sam, self.platform_cron, self.ldap_auth, self.event_trigger, self.tls) self.internal = Internal(self.platform_config, self.device, self.redirect_service, self.log_aggregator) self.path_checker = PathChecker(self.platform_config) self.lsblk = Lsblk(self.platform_config, self.path_checker) self.hardware = Hardware(self.platform_config, self.event_trigger, self.lsblk, self.path_checker) self.public = Public(self.platform_config, self.user_platform_config, self.device, self.info, self.sam, self.hardware, self.redirect_service, self.log_aggregator) self.udev = Udev(self.platform_config)
def get_app_paths(self, app_name): return AppPaths(app_name, self.platform_config)
def get_app_paths(app_name, config_path=None): config = get_injector().platform_config return AppPaths(app_name, config)
def __trigger_app_event(self, action): for app in self.sam.installed_all_apps(): app_id = app.app.id app_paths = AppPaths(app_id, self.platform_config) app_dir = app_paths.get_install_dir() run_hook_script(app_dir, action)
def get_app_paths(app_name): return AppPaths(app_name, PlatformConfig())
def __init__(self, platform_config): self.log = get_logger('ldap') self.config = platform_config self.app_paths = AppPaths('platform', platform_config)
class LdapAuth: def __init__(self, platform_config): self.log = get_logger('ldap') self.config = platform_config self.app_paths = AppPaths('platform', platform_config) def installed(self): data_dir = self.app_paths.get_data_dir() return os.path.isdir(join(data_dir, ldap_user_conf_dir)) def reset(self, user, password): data_dir = self.app_paths.get_data_dir() user_conf_dir = join(data_dir, ldap_user_conf_dir) fs.removepath(user_conf_dir) fs.makepath(user_conf_dir) fs.chownpath(user_conf_dir, platform_user) stop_service('platform-openldap') files = glob.glob('/opt/data/platform/openldap-data/*') for f in files: os.remove(f) init_script = '{0}/ldap/slapd.ldif'.format(self.config.config_dir()) ldap_root = '{0}/openldap'.format(self.config.app_dir()) check_output('{0}/sbin/slapadd -F {1} -b "cn=config" -l {2}'.format( ldap_root, user_conf_dir, init_script), shell=True) check_output('chown -R {0}. {1}'.format(platform_user, user_conf_dir), shell=True) start_service('platform-openldap') fd, filename = tempfile.mkstemp() util.transform_file( '{0}/ldap/init.ldif'.format(self.config.config_dir()), filename, { 'user': user, 'password': make_secret(password) }) self.__init_db(filename, ldap_root) check_output('echo "root:{0}" | chpasswd'.format(password), shell=True) def __init_db(self, filename, ldap_root): success = False for i in range(0, 3): try: check_output( '{0}/bin/ldapadd -Y EXTERNAL -H ldapi:/// -f {1}'.format( ldap_root, filename), shell=True) success = True break except Exception, e: self.log.warn(e.message) self.log.warn( "probably ldap is still starting, will retry {0}".format( i)) time.sleep(1) if not success: raise Exception("Unable to initialize ldap db")