示例#1
0
    def __init__(self):
        """Function for intializing the class.

        Args:
            None

        Returns:
            None

        """
        # Read configuration into dictionary
        self.directories = general.config_directories()
        self.config = general.read_yaml_files(self.directories)
示例#2
0
    def __init__(self):
        """Function for intializing the class.

        Args:
            None

        Returns:
            None

        """
        # Read configuration into dictionary
        self.directory = ('%s/etc') % (general.root_directory())
        self.config = general.read_yaml_files([self.directory])
示例#3
0
    def __init__(self):
        """Function for intializing the class.

        Args:
            None

        Returns:
            None

        """
        # Initialize key variables
        directories = general.config_directories()
        self.config_dict = general.read_yaml_files(directories)
示例#4
0
    def test_read_yaml_files(self):
        """Test function read_yaml_files."""
        # Initialize key variables
        dict_1 = {
            'key1': 1,
            'key2': 2,
            'key3': 3,
            'key4': 4,
        }

        dict_2 = {
            'key6': 6,
            'key7': 7,
        }
        dict_3 = {}

        # Populate a third dictionary with contents of other dictionaries.
        for key in dict_1.keys():
            dict_3[key] = dict_1[key]

        for key in dict_2.keys():
            dict_3[key] = dict_2[key]

        # Create temp file with known data
        directory = tempfile.mkdtemp()
        filenames = {
            ('%s/file_1.yaml') % (directory): dict_1,
            ('%s/file_2.yaml') % (directory): dict_2
        }
        for filename, data_dict in filenames.items():
            with open(filename, 'w') as filehandle:
                yaml.dump(data_dict, filehandle, default_flow_style=False)

        # Get Results
        result = general.read_yaml_files([directory])

        # Clean up
        for key in result.keys():
            self.assertEqual(dict_3[key], result[key])
        filelist = [
            next_file for next_file in os.listdir(directory)
            if next_file.endswith('.yaml')
        ]
        for delete_file in filelist:
            delete_path = ('%s/%s') % (directory, delete_file)
            os.remove(delete_path)
        os.removedirs(directory)
示例#5
0
    def __init__(self, daemon_username):
        """Function for intializing the class.

        Args:
            daemon_username: Username to run scripts as

        Returns:
            None

        """
        # Initialize key variables
        valid_directories = []
        config = ("""\
main:
    log_directory:
    log_level: debug
    ingest_cache_directory:
    ingest_pool_size: 20
    listen_address: 0.0.0.0
    bind_port: 6000
    interval: 300
    memcached_hostname: localhost
    memcached_port: 11211
    sqlalchemy_pool_size: 10
    sqlalchemy_max_overflow: 10
    db_hostname: localhost
    db_username: infoset_ng
    db_password:
    db_name: infoset_ng
    username: {}
""").format(daemon_username)

        self.config_dict = yaml.safe_load(config)
        directory_dict = defaultdict(lambda: defaultdict(dict))

        # Read yaml files from configuration directory
        self.directories = general.config_directories()

        # Check each directory in sequence
        for config_directory in self.directories:
            # Check if config_directory exists
            if os.path.isdir(config_directory) is False:
                continue

            # Cycle through list of files in directory
            for filename in os.listdir(config_directory):
                # Examine all the '.yaml' files in directory
                if filename.endswith('.yaml'):
                    # YAML files found
                    valid_directories.append(config_directory)

        if bool(valid_directories) is True:
            directory_dict = general.read_yaml_files(valid_directories,
                                                     die=False)

        # Populate config_dict with any values found in directory_dict
        # Only if the directory has valid files in it.
        if bool(directory_dict) is True:
            for _main, data_dict in directory_dict.items():
                if _main != 'main':
                    log_message = (
                        'Invalid files found in configuration directory')
                    log.log2die_safe(1033, log_message)

                for key, value in data_dict.items():
                    if value is not None:
                        self.config_dict[_main][key] = value