예제 #1
0
    def __init__(self, package_name, package_metadata, temporal_fs_manager,
                 generator_dir):

        if not package_name:
            raise ValueError('package_name cannot be null or empty')
        if not package_metadata:
            raise ValueError('package_metadata cannot be null or empty')

        self.temporal_fs_manager = temporal_fs_manager
        self.package_name = package_name
        self.content_folder = os.path.join(generator_dir, 'content')
        self.package_content_path = None
        self.reusable_content = None

        self.source_url = package_metadata.get('source-url')
        if not validators.url(self.source_url) and not giturlparse.parse(
                self.source_url).valid:
            raise ConfigurationException(
                f'{self.package_name} source-url is not a valid URL')
        self.package_version = package_metadata.get('version')
        if not self.package_version:
            raise ConfigurationException(
                f'{self.package_name} version is empty')

        if not os.path.exists(generator_dir):
            os.mkdir(self.files_folder)
        if not os.path.exists(self.content_folder):
            os.mkdir(self.content_folder)
예제 #2
0
 def __get_patch_tuple(patch_path):
     if not patch_path:
         raise ConfigurationException('A patch without path is present')
     split_path = patch_path.strip().split('|')
     if not split_path or len(split_path) != 2:
         raise ConfigurationException(
             f'{patch_path} is not a valid patch path')
     return split_path[0], split_path[1]
예제 #3
0
    def load(self):
        self.pk_key = self.__load_key_from_file(self.pk_path,
                                                self.pk_passphrase)
        if not self.pk_key:
            raise ConfigurationException(
                'Cannot read the selected SSH private key')

        self.pub_key = self.__load_key_from_file(self.pub_path)
        if not self.pub_key:
            raise ConfigurationException(
                'Cannot read the selected SSH public key')
예제 #4
0
 def __init__(self, config_dict):
     try:
         self.cluster_name = config_dict.get('cluster-name', None)
         if not self.cluster_name:
             raise ConfigurationException(
                 'Cluster name is null or empty in configuration')
         elif not re.match(r'[\w\-. ]+$', self.cluster_name) or len(
                 self.cluster_name) < 5 or len(self.cluster_name) > 100:
             raise ConfigurationException(
                 'Cluster name is contains invalid chars, is less than 5 characters or exceeds 100'
             )
     except KeyError as key_error:
         raise ConfigurationException(
             f'Global settings {key_error.args[0]} is null or empty'
         ) from key_error
def load_configuration():
    config = confuse.Configuration('torrent-processor', __name__)

    for cfg in mandatory_config_values:
        if not config[cfg].exists():
            raise ConfigurationException(
                'ERROR_CONFIG - Configuration value "' + cfg + '" not found.')

    try:
        config['downloader'].keys()[0]
    except Exception as e:
        raise ConfigurationException(
            'ERROR_CONFIG - Configuration value "downloader" is invalid. - ' +
            str(e))

    return config
예제 #6
0
 def __parse_configuration(self):
     if self.json_path:
         try:
             with open(self.json_path, 'r') as json_file:
                 return json.load(json_file)
         except ValueError:
             raise ConfigurationException(
                 'Cannot load generator configuration')
예제 #7
0
 def validate_patches(self):
     for patch in self.patches:
         patch_path = patch.get('path', None)
         file, path = self.__get_patch_tuple(patch_path)
         if os.path.isabs(path) or file.startswith(
                 '/') or ':' in file or '\\' in file:
             raise ConfigurationException(
                 f'Patch {patch_path} start seems to be invalid')
         if os.path.exists(os.path.join(self.target_dir, patch_path)):
             raise ConfigurationException(
                 f'Patch {patch_path} points to a non existing file')
         if not path or not self.dpath_regex.match(path):
             raise ConfigurationException(
                 f'Patch {patch_path} dpath {path} is invalid')
         if 'value' not in patch:
             raise ConfigurationException(
                 f'Patch {patch_path} has no patching value')
예제 #8
0
 def __init__(self, config_dict, packages):
     if 'terraform' in config_dict:
         try:
             self.infra_config = config_dict['terraform']['infra-config']
             self.package_name = config_dict['terraform']['package']
             self.package_manager = packages[
                 self.
                 package_name] if self.package_name in packages else None
             if not self.package_manager:
                 raise ConfigurationException(
                     'Terraform configuration has an invalid package association'
                 )
         except KeyError as key_error:
             raise ConfigurationException(
                 f'Terraform {key_error.args[0]} is null or empty'
             ) from key_error
     else:
         raise ConfigurationException(
             'No Terraform configuration found in generator configuration')
예제 #9
0
    def __get_config_path(generator_directory):
        current_dir_path = os.path.join(os.getcwd(), 'k8s-config.json')
        if os.path.isfile(current_dir_path):
            return current_dir_path

        user_path = os.path.join(generator_directory, 'k8s-config.json')
        if os.path.isfile(user_path):
            return user_path

        raise ConfigurationException('No json configuration file present')
예제 #10
0
 def __init__(self, config_dict, packages):
     if 'kubespray' in config_dict:
         try:
             self.remote_user = config_dict['kubespray'].get('remote-user')
             self.patches = config_dict['kubespray'].get('patches', [])
             self.package_name = config_dict['kubespray']['package']
             self.package_manager = packages[
                 self.
                 package_name] if self.package_name in packages else None
             if not self.package_manager:
                 raise ConfigurationException(
                     'Kubespray configuration has an invalid package association'
                 )
         except KeyError as key_error:
             raise ConfigurationException(
                 f'Terraform {key_error.args[0]} is null or empty'
             ) from key_error
     else:
         raise ConfigurationException(
             'No Kubespray configuration found in generator configuration')
예제 #11
0
 def __prepare_packages(self, configuration):
     packages_config_node = configuration.get('packages')
     if packages_config_node:
         for package_name, package_node in packages_config_node.items():
             if package_name not in self.packages:
                 package_manager = PackageManager(package_name,
                                                  package_node,
                                                  self.temporal_fs,
                                                  self.generator_dir)
                 package_manager.prepare_content()
                 self.packages[package_name] = package_manager
             else:
                 raise ConfigurationException(
                     f'Package {package_name} is duplicated inside configuration'
                 )