Esempio n. 1
0
 def test_load_yaml_with_tabs(self):
     try:
         f = self.yaml_file("hello:\n\t- world")
         load_yaml_file(f)
     except YAMLError as ex:
         assert 'line 2' in str(ex)
     else:
         assert False, 'expected YAMLError'
Esempio n. 2
0
 def test_load_yaml_with_tabs(self):
     try:
         f = self.yaml_file("hello:\n\t- world")
         load_yaml_file(f)
     except YAMLError as ex:
         assert "line 2" in str(ex)
     else:
         assert False, "expected YAMLError"
Esempio n. 3
0
def crypto_yaml_command(args):
    parser = optparse.OptionParser(
        "usage: %prog ctypto-yaml [options] original.yaml crypto.yaml")
    parser.add_option("-k",
                      "--key",
                      dest="secretKey",
                      default='bNZbj7T285uHoOI5LtZ1H9nJC_prd0hmcFVnok3B4Gs=',
                      help="Provide the secret key.")
    options, args = parser.parse_args(args)

    if len(args) != 3:
        parser.print_help()
        print("\nERROR: Crypto configuration required.")
        sys.exit(1)

    key = options.secretKey
    original_conf = args[1]
    crypto_conf = args[2]
    conf_base_dir = os.path.abspath(os.path.dirname(original_conf))
    original_conf_file = os.path.normpath(
        os.path.join(conf_base_dir, os.path.basename(original_conf)))
    crypto_conf_file = os.path.normpath(
        os.path.join(conf_base_dir, os.path.basename(crypto_conf)))
    data = load_yaml_file(original_conf_file)

    # with open(crypto_conf_file, 'wb') as outfile:
    #     outfile.close()
    # os.chmod(crypto_conf_file, 0o400)

    crypto_yaml = CryptoYAML(crypto_conf_file, key)
    crypto_yaml.data = data
    crypto_yaml.write()
Esempio n. 4
0
def load_config(config, config_file=None, config_dict=None, clear_existing=False):
    if clear_existing:
        for key in config.keys():
            del config[key]

    if config_dict is None:
        config_dict = load_yaml_file(config_file)

    defaults = _to_options_map(config_dict)

    if defaults:
        for key, value in defaults.iteritems():
            if key in config and hasattr(config[key], 'update'):
                config[key].update(value)
            else:
                config[key] = value
Esempio n. 5
0
def load_seed_tasks_conf(seed_conf_filename, mapproxy_conf):
    try:
        conf = load_yaml_file(seed_conf_filename)
    except YAMLError as ex:
        raise SeedConfigurationError(ex)

    if 'views' in conf:
        # TODO: deprecate old config
        seed_conf = LegacySeedingConfiguration(conf, mapproxy_conf=mapproxy_conf)
    else:
        errors, informal_only = validate_seed_conf(conf)
        for error in errors:
            log.warn(error)
        if not informal_only:
            raise SeedConfigurationError('invalid configuration')
        seed_conf = SeedingConfiguration(conf, mapproxy_conf=mapproxy_conf)
    return seed_conf
Esempio n. 6
0
def load_seed_tasks_conf(seed_conf_filename, mapproxy_conf):
    try:
        conf = load_yaml_file(seed_conf_filename)
    except YAMLError as ex:
        raise SeedConfigurationError(ex)

    if 'views' in conf:
        # TODO: deprecate old config
        seed_conf = LegacySeedingConfiguration(conf, mapproxy_conf=mapproxy_conf)
    else:
        errors, informal_only = validate_seed_conf(conf)
        for error in errors:
            log.warn(error)
        if not informal_only:
            raise SeedConfigurationError('invalid configuration')
        seed_conf = SeedingConfiguration(conf, mapproxy_conf=mapproxy_conf)
    return seed_conf
Esempio n. 7
0
def load_seed_tasks_conf(seed_conf_filename, mapproxy_conf):
    try:
        conf = load_yaml_file(seed_conf_filename)
    except YAMLError, ex:
        raise SeedConfigurationError(ex)
Esempio n. 8
0
def load_seed_tasks_conf(seed_conf_filename, mapproxy_conf):
    try:
        conf = load_yaml_file(seed_conf_filename)
    except YAMLError, ex:
        raise SeedConfigurationError(ex)
Esempio n. 9
0
 def test_load_yaml_file_filename(self):
     f = self.yaml_file("hello:\n - 1\n - 2")
     assert isinstance(f, string_type)
     doc = load_yaml_file(f)
     assert doc == {"hello": [1, 2]}
Esempio n. 10
0
 def test_load_yaml_file(self):
     f = self.yaml_file("hello:\n - 1\n - 2")
     doc = load_yaml_file(open(f))
     assert doc == {"hello": [1, 2]}
Esempio n. 11
0
 def test_load_yaml_file_filename(self):
     f = self.yaml_file("hello:\n - 1\n - 2")
     assert isinstance(f, string_type)
     doc = load_yaml_file(f)
     eq_(doc, {'hello': [1, 2]})
Esempio n. 12
0
 def test_load_yaml_file(self):
     f = self.yaml_file("hello:\n - 1\n - 2")
     doc = load_yaml_file(open(f))
     eq_(doc, {'hello': [1, 2]})
Esempio n. 13
0
 def test_load_yaml_with_tabs(self):
     try:
         f = self.yaml_file("hello:\n\t- world")
         load_yaml_file(f)
     except YAMLError, ex:
         assert 'line 2' in str(ex)
Esempio n. 14
0
 def test_load_yaml_file_filename(self):
     f = self.yaml_file("hello:\n - 1\n - 2")
     assert isinstance(f, basestring)
     doc = load_yaml_file(f)
     eq_(doc, {'hello': [1, 2]})