Example #1
0
def bootstrap_options(settings, config):
    """
    Quickly bootstrap options that come in from a config file
    and convert options into Django settings that are
    required to even initialize the rest of the app.
    """
    if config is None:
        return
    from sentry.utils.yaml import safe_load
    try:
        with open(config, 'rb') as fp:
            options = safe_load(fp)
    except IOError:
        # Gracefully fail if yaml file doesn't exist
        return
    # First move options from settings into options
    for k, v in options_mapper.iteritems():
        if hasattr(settings, v):
            options[k] = getattr(settings, v)
    for k, v in options.iteritems():
        # Stuff everything else into SENTRY_OPTIONS
        # these will be validated later after bootstrapping
        settings.SENTRY_OPTIONS[k] = v
        # Escalate the few needed to actually get the app bootstrapped into settings
        if k in options_mapper:
            setattr(settings, options_mapper[k], v)
Example #2
0
def bootstrap_options(settings, config=None):
    """
    Quickly bootstrap options that come in from a config file
    and convert options into Django settings that are
    required to even initialize the rest of the app.
    """
    # Make sure our options have gotten registered
    from sentry.options import load_defaults
    load_defaults()

    options = {}
    if config is not None:
        # Attempt to load our config yaml file
        from sentry.utils.yaml import safe_load
        from yaml.parser import ParserError
        from yaml.scanner import ScannerError
        try:
            with open(config, 'rb') as fp:
                options = safe_load(fp)
        except IOError:
            # Gracefully fail if yaml file doesn't exist
            pass
        except (AttributeError, ParserError, ScannerError) as e:
            from .importer import ConfigurationError
            raise ConfigurationError('Malformed config.yml file: %s' % unicode(e))

        # Empty options file, so fail gracefully
        if options is None:
            options = {}
        # Options needs to be a dict
        elif not isinstance(options, dict):
            from .importer import ConfigurationError
            raise ConfigurationError('Malformed config.yml file')

    from sentry.conf.server import DEAD

    # First move options from settings into options
    for k, v in options_mapper.iteritems():
        if getattr(settings, v, DEAD) is not DEAD and k not in options:
            warnings.warn(
                DeprecatedSettingWarning(
                    options_mapper[k],
                    "SENTRY_OPTIONS['%s']" % k,
                )
            )
            options[k] = getattr(settings, v)

    # Stuff everything else into SENTRY_OPTIONS
    # these will be validated later after bootstrapping
    for k, v in options.iteritems():
        settings.SENTRY_OPTIONS[k] = v

    # Now go back through all of SENTRY_OPTIONS and promote
    # back into settings. This catches the case when values are defined
    # only in SENTRY_OPTIONS and no config.yml file
    for o in (settings.SENTRY_DEFAULT_OPTIONS, settings.SENTRY_OPTIONS):
        for k, v in o.iteritems():
            if k in options_mapper:
                # Escalate the few needed to actually get the app bootstrapped into settings
                setattr(settings, options_mapper[k], v)
Example #3
0
 def convert(self, value):
     if isinstance(value, six.string_types):
         try:
             value = safe_load(value)
         except (AttributeError, ParserError, ScannerError):
             return
     if isinstance(value, list):
         value = tuple(value)
     return value
Example #4
0
 def convert(self, value):
     if isinstance(value, basestring):
         try:
             value = safe_load(value)
         except (AttributeError, ParserError, ScannerError):
             return
     if isinstance(value, list):
         value = tuple(value)
     return value
Example #5
0
    def test_simple(self):
        with self.runner.isolated_filesystem():
            rv = self.invoke('config')
            assert rv.exit_code == 0, rv.output
            contents = os.listdir('config')
            assert set(contents) == {'sentry.conf.py', 'config.yml'}

            # Make sure the python file is valid
            ctx = {'__file__': 'sentry.conf.py'}
            execfile('config/sentry.conf.py', ctx)
            assert 'DEBUG' in ctx

            # Make sure the yaml file is valid
            from sentry.utils.yaml import safe_load
            with open('config/config.yml', 'rb') as fp:
                ctx = safe_load(fp)
            assert 'system.secret-key' in ctx
    def test_simple(self):
        with self.runner.isolated_filesystem():
            rv = self.invoke("config")
            assert rv.exit_code == 0, rv.output
            contents = os.listdir("config")
            assert set(contents) == {"sentry.conf.py", "config.yml"}

            # Make sure the python file is valid
            ctx = {"__file__": "sentry.conf.py"}
            with open("config/sentry.conf.py") as fp:
                exec(fp.read(), ctx)
            assert "DEBUG" in ctx

            # Make sure the yaml file is valid
            from sentry.utils.yaml import safe_load

            with open("config/config.yml", "rb") as fp:
                ctx = safe_load(fp)
            assert "system.secret-key" in ctx
Example #7
0
def bootstrap_options(settings, config):
    """
    Quickly bootstrap options that come in from a config file
    and convert options into Django settings that are
    required to even initialize the rest of the app.
    """
    if config is None:
        return
    from sentry.utils.yaml import safe_load
    from yaml.parser import ParserError
    from yaml.scanner import ScannerError

    try:
        with open(config, "rb") as fp:
            options = safe_load(fp)
    except IOError:
        # Gracefully fail if yaml file doesn't exist
        return
    except (AttributeError, ParserError, ScannerError) as e:
        from .importer import ConfigurationError

        raise ConfigurationError("Malformed config.yml file: %s" % unicode(e))
    # Empty options file, so fail gracefully
    if options is None:
        return
    # Options needs to be a dict
    if not isinstance(options, dict):
        from .importer import ConfigurationError

        raise ConfigurationError("Malformed config.yml file")
    # First move options from settings into options
    for k, v in options_mapper.iteritems():
        if hasattr(settings, v):
            options[k] = getattr(settings, v)
    for k, v in options.iteritems():
        # Stuff everything else into SENTRY_OPTIONS
        # these will be validated later after bootstrapping
        settings.SENTRY_OPTIONS[k] = v
        # Escalate the few needed to actually get the app bootstrapped into settings
        if k in options_mapper:
            setattr(settings, options_mapper[k], v)
Example #8
0
def bootstrap_options(settings, config):
    """
    Quickly bootstrap options that come in from a config file
    and convert options into Django settings that are
    required to even initialize the rest of the app.
    """
    if config is None:
        return
    from sentry.utils.yaml import safe_load
    from yaml.parser import ParserError
    from yaml.scanner import ScannerError
    try:
        with open(config, 'rb') as fp:
            options = safe_load(fp)
    except IOError:
        # Gracefully fail if yaml file doesn't exist
        return
    except (AttributeError, ParserError, ScannerError) as e:
        from .importer import ConfigurationError
        raise ConfigurationError('Malformed config.yml file: %s' % unicode(e))
    # Empty options file, so fail gracefully
    if options is None:
        return
    # Options needs to be a dict
    if not isinstance(options, dict):
        from .importer import ConfigurationError
        raise ConfigurationError('Malformed config.yml file')
    # First move options from settings into options
    for k, v in options_mapper.iteritems():
        if hasattr(settings, v):
            options[k] = getattr(settings, v)
    for k, v in options.iteritems():
        # Stuff everything else into SENTRY_OPTIONS
        # these will be validated later after bootstrapping
        settings.SENTRY_OPTIONS[k] = v
        # Escalate the few needed to actually get the app bootstrapped into settings
        if k in options_mapper:
            setattr(settings, options_mapper[k], v)
Example #9
0
def bootstrap_options(settings, config=None):
    """
    Quickly bootstrap options that come in from a config file
    and convert options into Django settings that are
    required to even initialize the rest of the app.
    """
    # Make sure our options have gotten registered
    from sentry.options import load_defaults

    load_defaults()

    options = {}
    if config is not None:
        # Attempt to load our config yaml file
        from sentry.utils.yaml import safe_load
        from yaml.parser import ParserError
        from yaml.scanner import ScannerError

        try:
            with open(config, "rb") as fp:
                options = safe_load(fp)
        except IOError:
            # Gracefully fail if yaml file doesn't exist
            pass
        except (AttributeError, ParserError, ScannerError) as e:
            from .importer import ConfigurationError

            raise ConfigurationError("Malformed config.yml file: %s" % six.text_type(e))

        # Empty options file, so fail gracefully
        if options is None:
            options = {}
        # Options needs to be a dict
        elif not isinstance(options, dict):
            from .importer import ConfigurationError

            raise ConfigurationError("Malformed config.yml file")

    from sentry.conf.server import DEAD

    # First move options from settings into options
    for k, v in six.iteritems(options_mapper):
        if getattr(settings, v, DEAD) is not DEAD and k not in options:
            warnings.warn(DeprecatedSettingWarning(options_mapper[k], "SENTRY_OPTIONS['%s']" % k))
            options[k] = getattr(settings, v)

    # Stuff everything else into SENTRY_OPTIONS
    # these will be validated later after bootstrapping
    for k, v in six.iteritems(options):
        settings.SENTRY_OPTIONS[k] = v

    # Now go back through all of SENTRY_OPTIONS and promote
    # back into settings. This catches the case when values are defined
    # only in SENTRY_OPTIONS and no config.yml file
    for o in (settings.SENTRY_DEFAULT_OPTIONS, settings.SENTRY_OPTIONS):
        for k, v in six.iteritems(o):
            if k in options_mapper:
                # Map the mail.backend aliases to something Django understands
                if k == "mail.backend":
                    try:
                        v = settings.SENTRY_EMAIL_BACKEND_ALIASES[v]
                    except KeyError:
                        pass
                # Escalate the few needed to actually get the app bootstrapped into settings
                setattr(settings, options_mapper[k], v)
Example #10
0
 def convert(self, value):
     try:
         return safe_load(value)
     except (AttributeError, ParserError, ScannerError):
         return
Example #11
0
 def convert(self, value):
     try:
         return safe_load(value)
     except (AttributeError, ParserError, ScannerError):
         return