Example #1
0
def get_public_settings():
    public_settings = {}

    # Processing a special extension WALDUR_CORE
    public_settings['WALDUR_CORE'] = {}
    extension_settings = settings.WALDUR_CORE
    for s in settings.WALDUR_CORE_PUBLIC_SETTINGS:
        try:
            public_settings['WALDUR_CORE'][s] = extension_settings[s]
        except KeyError:
            pass

    # Processing a others extensions
    for ext in WaldurExtension.get_extensions():
        settings_name = [
            x for x in dir(ext.Settings) if x.startswith('WALDUR_')
        ]
        if not settings_name:
            continue

        settings_name = settings_name[0]
        extension_settings = getattr(settings, settings_name, None)
        if extension_settings and extension_settings.get('ENABLED', True):
            public_settings[settings_name] = {}

            for s in ext.get_public_settings():
                try:
                    public_settings[settings_name][s] = extension_settings[s]
                except KeyError:
                    pass

    return public_settings
Example #2
0
def check_cleanup_executors(app_configs, **kwargs):
    errors = []

    for extension in WaldurExtension.get_extensions():
        cleanup_executor = extension.get_cleanup_executor()
        if not cleanup_executor:
            continue

        for model in cleanup_executor.pre_models:
            if not issubclass(model, Model):
                errors.append(
                    checks.Error(
                        'Invalid resource model is detected in project cleanup executor.',
                        obj=cleanup_executor,
                        id='waldur.E001',
                    ))

        for item in cleanup_executor.executors:
            if not is_valid_executor(item):
                errors.append(
                    checks.Error(
                        'Invalid resource executor is detected in project cleanup executor.',
                        obj=cleanup_executor,
                        id='waldur.E001',
                    ))

    return errors
Example #3
0
    def test_default_ordering_must_be_defined_for_all_viewsets(self):
        for ext in WaldurExtension.get_extensions():

            try:
                views = __import__(
                    ext.django_app() + '.views',
                    fromlist=['views'],
                )
            except ImportError:
                continue

            for v in dir(views):
                if 'ViewSet' not in v:
                    continue

                view = getattr(views, v)
                try:
                    queryset = view().get_queryset()
                except (AttributeError, AssertionError):
                    continue

                if not isinstance(queryset, QuerySet):
                    continue

                self.assertTrue(
                    queryset.ordered,
                    msg='default ordering for %s has not been defined.' % v,
                )
Example #4
0
def get_public_settings():
    public_settings = {}

    public_settings['WALDUR_DISABLED_EXTENSIONS'] = WALDUR_DISABLED_EXTENSIONS
    public_settings['FEATURES'] = get_feature_values()

    try:
        keys = WaldurConfiguration().Meta.public_settings
    except AttributeError:
        pass
    else:
        for s in keys:
            public_settings[s] = getattr(settings, s, None)

    for (settings_name, section) in WaldurConfiguration().__fields__.items():
        type_ = section.type_
        try:
            keys = type_.Meta.public_settings
        except AttributeError:
            continue
        extension_settings = getattr(settings, settings_name, None)
        if not extension_settings:
            continue
        public_settings[settings_name] = {}
        for s in keys:
            try:
                public_settings[settings_name][s] = extension_settings[s]
            except KeyError:
                pass

    # Processing a others extensions
    for ext in WaldurExtension.get_extensions():
        settings_name = [
            x for x in dir(ext.Settings) if x.startswith('WALDUR_')
        ]
        if not settings_name:
            continue

        settings_name = settings_name[0]
        extension_settings = getattr(settings, settings_name, None)
        if extension_settings and extension_settings.get('ENABLED', True):
            public_settings[settings_name] = {}

            for s in ext.get_public_settings():
                try:
                    public_settings[settings_name][s] = extension_settings[s]
                except KeyError:
                    pass

            for s, v in ext.get_dynamic_settings().items():
                public_settings[settings_name][s] = v

    return public_settings
Example #5
0
    def get_executors(cls):
        # Get cleanup executors from extensions
        executors = [
            extension.get_cleanup_executor()
            for extension in WaldurExtension.get_extensions()
        ]

        # Filter empty items from list because cleanup executor is optional
        executors = [executor for executor in executors if executor]

        # Apply topological sort with respect to dependencies between executors
        dependencies = {}
        for executor in executors:
            dependencies[executor] = set()
            if executor.related_executor:
                dependencies[executor.related_executor].add(executor)
        return stable_topological_sort(executors, dependencies)
Example #6
0
    def _get_installed_plugin_info(self):
        links = []

        for ext in WaldurExtension.get_extensions():
            app_config = self._get_app_config(ext.django_app())
            if not app_config:
                # App is not found
                continue

            name = self._get_app_name(app_config)
            version = self._get_app_version(app_config)

            links.append({
                'title': '%s %s' % (name, version),
                'url': 'http://docs.waldur.com/',
                'external': True,
                'attrs': {
                    'target': '_blank'
                },
            })

        # Order plugins by title
        links = sorted(links, key=lambda item: item['title'].lower())

        # Core is the most important component, therefore
        # it should be the the first item in the list
        links.insert(
            0, {
                'title': _('Waldur Core %s') % __version__,
                'url': 'http://docs.waldur.com/',
                'external': True,
                'attrs': {
                    'target': '_blank'
                },
            })

        return links
    50,
}

WALDUR_CORE_PUBLIC_SETTINGS = [
    'AUTHENTICATION_METHODS',
    'INVITATIONS_ENABLED',
    'ALLOW_SIGNUP_WITHOUT_INVITATION',
    'VALIDATE_INVITATION_EMAIL',
    'OWNER_CAN_MANAGE_CUSTOMER',
    'OWNERS_CAN_MANAGE_OWNERS',
    'COMPANY_TYPES',
    'NATIVE_NAME_ENABLED',
    'ONLY_STAFF_MANAGES_SERVICES',
]

for ext in WaldurExtension.get_extensions():
    INSTALLED_APPS += (ext.django_app(), )

    for name, task in ext.celery_tasks().items():
        if name in CELERY_BEAT_SCHEDULE:
            warnings.warn("Celery beat task %s from Waldur extension %s "
                          "is overlapping with primary tasks definition" %
                          (name, ext.django_app()))
        else:
            CELERY_BEAT_SCHEDULE[name] = task

    for key, val in ext.Settings.__dict__.items():
        if not key.startswith('_'):
            globals()[key] = val

    ext.update_settings(globals())