Пример #1
0
    def __init__(self, cliargs=None):
        # config file handling
        self.config_dir, self.config_file = self.find_config_file()
        try:
            self.data = load_and_merge(file_path=self.config_file, defaults=self.DEFAULTS)

            # set up names of CLI common contexts
            #self.contexts = {}
            #self.contexts['docker_cli'] = None
            #self.contexts['anchore_allimages'] = None

            self.cliargs = {}
            if cliargs:
                # store CLI arguments
                self.cliargs = cliargs

            #update relative to data dir if not an absolute path
            if not os.path.isabs(self.data['image_data_store']):
                self.data['image_data_store'] = os.path.join(self.data['anchore_data_dir'], self.data['image_data_store'])

            if not os.path.exists(self.data['image_data_store']):
                os.makedirs(self.data['image_data_store'])

        except Exception as err:
            self.data = None
            import traceback
            traceback.print_exc()
            raise err
Пример #2
0
    def __init__(self, cliargs=None):
        # config file handling
        self.config_dir, self.config_file = self.find_config_file()
        try:
            self.data = load_and_merge(file_path=self.config_file,
                                       defaults=self.DEFAULTS)

            # set up names of CLI common contexts
            #self.contexts = {}
            #self.contexts['docker_cli'] = None
            #self.contexts['anchore_allimages'] = None

            self.cliargs = {}
            if cliargs:
                # store CLI arguments
                self.cliargs = cliargs

            #update relative to data dir if not an absolute path
            if not os.path.isabs(self.data['image_data_store']):
                self.data['image_data_store'] = os.path.join(
                    self.data['anchore_data_dir'],
                    self.data['image_data_store'])

            if not os.path.exists(self.data['image_data_store']):
                os.makedirs(self.data['image_data_store'])

        except Exception as err:
            self.data = None
            import traceback
            traceback.print_exc()
            raise err
Пример #3
0
    def __init__(self, cliargs=None):
        # config file handling

        # handle override of the default .anchore location
        if os.getenv('ANCHOREDATADIR'):
            self.DEFAULT_ANCHORE_DATA_DIR = os.getenv('ANCHOREDATADIR')
            self.DEFAULT_CONFIG_DIR = os.path.join(self.DEFAULT_ANCHORE_DATA_DIR, 'conf')
            self.DEFAULT_CONFIG_FILE = os.path.join(self.DEFAULT_CONFIG_DIR, 'config.yaml')
            self.DEFAULT_TMP_DIR = os.path.join(self.DEFAULT_ANCHORE_DATA_DIR, 'anchoretmp')
            self.DEFAULTS['tmpdir'] = self.DEFAULT_TMP_DIR
            self.DEFAULTS['anchore_data_dir'] = self.DEFAULT_ANCHORE_DATA_DIR

        self.config_dir, self.config_file = self.find_config_file()
        try:
            self.data = load_and_merge(file_path=self.config_file, defaults=self.DEFAULTS)

            self.cliargs = {}
            if cliargs:
                # store CLI arguments
                self.cliargs = cliargs

            if not os.path.exists(self.data['anchore_data_dir']):
                os.makedirs(self.data['anchore_data_dir'])

            if not os.path.exists(self.data['tmpdir']):
                os.makedirs(self.data['tmpdir'])

            #update relative to data dir if not an absolute path
            if not os.path.isabs(self.data['image_data_store']):
                self.data['image_data_store'] = os.path.join(self.data['anchore_data_dir'], self.data['image_data_store'])

            if not os.path.exists(self.data['image_data_store']):
                os.makedirs(self.data['image_data_store'])

            if not os.path.isabs(self.data['feeds_dir']):
                self.data['feeds_dir'] = os.path.join(self.data['anchore_data_dir'], self.data['feeds_dir'])

            if not os.path.isabs(self.data['user_scripts_dir']):
                self.data['user_scripts_dir'] = os.path.join(self.data['anchore_data_dir'], self.data['user_scripts_dir'])
            
            if not os.path.exists(self.data['user_scripts_dir']):
                os.makedirs(self.data['user_scripts_dir'])
                for d in ['analyzers', 'gates', 'queries', 'multi-queries', 'shell-utils']:
                    os.makedirs(os.path.join(self.data['user_scripts_dir'], d))

            dc = filecmp.dircmp(os.path.join(self.data['scripts_dir'], 'shell-utils'), os.path.join(self.data['user_scripts_dir'], 'shell-utils'))
            for f in dc.left_only + dc.diff_files:
                try:
                    shutil.copy(os.path.join(self.data['scripts_dir'], 'shell-utils', f), os.path.join(self.data['user_scripts_dir'], 'shell-utils', f))
                except Exception as err:
                    raise err
            
        except Exception as err:
            self.data = None
            import traceback
            traceback.print_exc()
            raise err
Пример #4
0
    def __init__(self, cliargs=None):
        # config file handling
        self.config_dir, self.config_file = self.find_config_file()
        try:
            self.data = load_and_merge(file_path=self.config_file, defaults=self.DEFAULTS)

            self.cliargs = {}
            if cliargs:
                # store CLI arguments
                self.cliargs = cliargs

            #update relative to data dir if not an absolute path
            if not os.path.isabs(self.data['image_data_store']):
                self.data['image_data_store'] = os.path.join(self.data['anchore_data_dir'], self.data['image_data_store'])

            if not os.path.exists(self.data['image_data_store']):
                os.makedirs(self.data['image_data_store'])

            if not os.path.isabs(self.data['user_scripts_dir']):
                self.data['user_scripts_dir'] = os.path.join(self.data['anchore_data_dir'], self.data['user_scripts_dir'])
            
            if not os.path.exists(self.data['user_scripts_dir']):
                os.makedirs(self.data['user_scripts_dir'])
                for d in ['analyzers', 'gates', 'queries', 'multi-queries', 'shell-utils']:
                    os.makedirs(os.path.join(self.data['user_scripts_dir'], d))

            dc = filecmp.dircmp(os.path.join(self.data['scripts_dir'], 'shell-utils'), os.path.join(self.data['user_scripts_dir'], 'shell-utils'))
            for f in dc.left_only + dc.diff_files:
                try:
                    shutil.copy(os.path.join(self.data['scripts_dir'], 'shell-utils', f), os.path.join(self.data['user_scripts_dir'], 'shell-utils', f))
                except Exception as err:
                    raise err
            
        except Exception as err:
            self.data = None
            import traceback
            traceback.print_exc()
            raise err
Пример #5
0
    def __init__(self, cliargs=None):
        # config file handling

        # handle override of the default .anchore location
        if os.getenv('ANCHOREDATADIR'):
            self.DEFAULT_ANCHORE_DATA_DIR = os.getenv('ANCHOREDATADIR')
            self.DEFAULT_CONFIG_DIR = os.path.join(self.DEFAULT_ANCHORE_DATA_DIR, 'conf')
            self.DEFAULT_CONFIG_FILE = os.path.join(self.DEFAULT_CONFIG_DIR, 'config.yaml')
            self.DEFAULT_TMP_DIR = os.path.join(self.DEFAULT_ANCHORE_DATA_DIR, 'anchoretmp')
            self.DEFAULTS['tmpdir'] = self.DEFAULT_TMP_DIR
            self.DEFAULTS['anchore_data_dir'] = self.DEFAULT_ANCHORE_DATA_DIR

        self.config_dir, self.config_file = self.find_config_file()
        try:
            self.data = load_and_merge(file_path=self.config_file, defaults=self.DEFAULTS)

            self.cliargs = {}
            if cliargs:
                # store CLI arguments
                self.cliargs = cliargs

            if 'config_overrides' in self.cliargs and self.cliargs['config_overrides']:
                for override_key in self.cliargs['config_overrides']:
                    if override_key in self.data:
                        self.data[override_key] = self.cliargs['config_overrides'][override_key]

            if not os.path.exists(self.data['anchore_data_dir']):
                os.makedirs(self.data['anchore_data_dir'])

            if not os.path.exists(self.data['tmpdir']):
                os.makedirs(self.data['tmpdir'])

            #update relative to data dir if not an absolute path
            if not os.path.isabs(self.data['image_data_store']):
                self.data['image_data_store'] = os.path.join(self.data['anchore_data_dir'], self.data['image_data_store'])

            if not os.path.exists(self.data['image_data_store']):
                os.makedirs(self.data['image_data_store'])

            if not os.path.isabs(self.data['feeds_dir']):
                self.data['feeds_dir'] = os.path.join(self.data['anchore_data_dir'], self.data['feeds_dir'])

            if not os.path.isabs(self.data['policy_dir']):
                self.data['policy_dir'] = os.path.join(self.data['anchore_data_dir'], self.data['policy_dir'])

            if not os.path.isabs(self.data['user_scripts_dir']):
                self.data['user_scripts_dir'] = os.path.join(self.data['anchore_data_dir'], self.data['user_scripts_dir'])
            
            if not os.path.exists(self.data['user_scripts_dir']):
                os.makedirs(self.data['user_scripts_dir'])
        
            for d in ['analyzers', 'gates', 'queries', 'multi-queries', 'shell-utils']:
                thedir = os.path.join(self.data['user_scripts_dir'], d)
                if not os.path.exists(thedir):
                    os.makedirs(thedir)

            dc = filecmp.dircmp(os.path.join(self.data['scripts_dir'], 'shell-utils'), os.path.join(self.data['user_scripts_dir'], 'shell-utils'))
            for f in dc.left_only + dc.diff_files:
                try:
                    shutil.copy(os.path.join(self.data['scripts_dir'], 'shell-utils', f), os.path.join(self.data['user_scripts_dir'], 'shell-utils', f))
                except Exception as err:
                    raise err
            
        except Exception as err:
            self.data = None
            import traceback
            traceback.print_exc()
            raise err