def get_usedby(self, source, parser, downloader, list_or_file_path, property_validate=True):
        """

        :param source:
        :param parser:
        :param downloader:
        :param list_or_file_path:
        :param property_validate: for `root` packages we need check property, bad if we find packages from `lock` file,
        we can skip validate part
        :return:
        """
        _auth_type = source.args['auth_type'].lower() if 'auth_type' in source.args else 'simple'
        _art_auth_etc = {}
        if 'auth' in source.args:
            self.search_auth(list_or_file_path, source)
            if _auth_type == 'simple':
                _art_auth_etc['auth'] = HTTPBasicAuth(*tuple(source.args['auth']))
                session.auth = _art_auth_etc['auth']
                # elif _auth_type == 'cert':
                #     _art_auth_etc['cert'] = os.path.realpath(os.path.expanduser(source.args['auth']))
        if 'auth' not in _art_auth_etc:
            msg = 'You have to set auth parameter for sources with artifactory-aql adapter'
            # self._log.error(msg)
            raise CrosspmException(
                CROSSPM_ERRORCODE_ADAPTER_ERROR,
                msg
            )

        if 'verify' in source.args:
            _art_auth_etc['verify'] = source.args['verify'].lower in ['true', 'yes', '1']
        else:
            _art_auth_etc['verify'] = False

        _secret_variables = self._config.secret_variables
        _pkg_name_col = self._config.name_column
        _packages_found = OrderedDict()
        _pkg_name_old = ""

        for _paths in parser.get_paths(list_or_file_path, source):
            _packages = []
            _params_found = {}
            _params_found_raw = {}
            last_error = ''
            _pkg_name = _paths['params'][_pkg_name_col]
            if _pkg_name != _pkg_name_old:
                _pkg_name_old = _pkg_name
                self._log.info(
                    '{}: {}'.format(_pkg_name,
                                    {k: v for k, v in _paths['params'].items() if
                                     (k not in (_pkg_name_col, 'repo') and k not in _secret_variables)
                                     }
                                    )
                )
            for _sub_paths in _paths['paths']:
                _tmp_params = dict(_paths['params'])
                self._log.info('repo: {}'.format(_sub_paths['repo']))
                _tmp_params['repo'] = _sub_paths['repo']
                try:
                    _artifactory_server = _tmp_params['server']
                    _search_repo = _tmp_params['repo']

                    # TODO: Попробовать использовать lru_cache для кеширования кучи запросов
                    _aql_query_url = '{}/api/search/aql'.format(_artifactory_server)
                    _aql_query_dict = {
                        "repo": {
                            "$eq": _search_repo,
                        },
                    }
                    _usedby_aql = parser.get_usedby_aql(_tmp_params)
                    if _usedby_aql is None:
                        continue
                    _aql_query_dict.update(_usedby_aql)
                    query = 'items.find({query_dict}).include("*", "property")'.format(
                        query_dict=json.dumps(_aql_query_dict))
                    session.auth = _art_auth_etc['auth']
                    r = session.post(_aql_query_url, data=query, verify=_art_auth_etc['verify'])
                    r.raise_for_status()

                    _found_paths = r.json()
                    for _found in _found_paths['results']:
                        _repo_path = "{artifactory}/{repo}/{path}/{file_name}".format(
                            artifactory=_artifactory_server,
                            repo=_found['repo'],
                            path=_found['path'],
                            file_name=_found['name'])
                        _repo_path = ArtifactoryPath(_repo_path, **_art_auth_etc)
                        _found_properties = {x['key']: x.get('value', '') for x in _found['properties']}

                        _matched, _params, _params_raw = parser.validate_path(str(_repo_path), _tmp_params)
                        _params_found[_repo_path] = {k: v for k, v in _params.items()}
                        _params_found_raw[_repo_path] = {k: v for k, v in _params_raw.items()}
                        _params = _tmp_params
                        _packages += [_repo_path]
                        _params_found[_repo_path].update({k: v for k, v in _params.items()})
                        _params_found[_repo_path]['filename'] = str(_repo_path.name)

                        _params_raw = _params_found_raw.get(_repo_path, {})
                        params_found = {}

                        # TODO: Проставление params брать из config.yaml usedby
                        params = parser.get_params_from_properties(_found_properties)
                        params.update(parser.get_params_from_path(str(_repo_path)))
                        _package = Package(params[_pkg_name_col], _repo_path, params, downloader, self,
                                           parser,
                                           params_found, _params_raw)

                        _package.find_usedby(None, property_validate=False)
                        _packages_found[str(_repo_path)] = _package
                        # _package.find_dependencies(_deps_file, property_validate=False)
                        _mark = 'chosen'
                        self._log.info('  {}: {}'.format(_mark, str(_repo_path)))
                except RuntimeError as e:
                    try:
                        err = json.loads(e.args[0])
                    except Exception:
                        err = {}
                    if isinstance(err, dict):
                        # Check errors
                        # :e.args[0]: {
                        #                 "errors" : [ {
                        #                     "status" : 404,
                        #                     "message" : "Not Found"
                        #                  } ]
                        #             }
                        for error in err.get('errors', []):
                            err_status = error.get('status', -1)
                            err_msg = error.get('message', '')
                            if err_status == 401:
                                msg = 'Authentication error[{}]{}'.format(err_status,
                                                                          (': {}'.format(
                                                                              err_msg)) if err_msg else '')
                            elif err_status == 404:
                                msg = last_error
                            else:
                                msg = 'Error[{}]{}'.format(err_status,
                                                           (': {}'.format(err_msg)) if err_msg else '')
                            if last_error != msg:
                                self._log.error(msg)
                            last_error = msg

        return _packages_found
def get_usedby ( self , source , parser , downloader , list_or_file_path , property_validate = True ) : _auth_type = source . args [ 'auth_type' ] . lower ( ) if 'auth_type' in source . args else 'simple' _art_auth_etc = { } if 'auth' in source . args : self . search_auth ( list_or_file_path , source ) if _auth_type == 'simple' : _art_auth_etc [ 'auth' ] = HTTPBasicAuth ( * tuple ( source . args [ 'auth' ] ) ) session . auth = _art_auth_etc [ 'auth' ] if 'auth' not in _art_auth_etc : msg = 'You have to set auth parameter for sources with artifactory-aql adapter' raise CrosspmException ( CROSSPM_ERRORCODE_ADAPTER_ERROR , msg ) if 'verify' in source . args : _art_auth_etc [ 'verify' ] = source . args [ 'verify' ] . lower in [ 'true' , 'yes' , '1' ] else : _art_auth_etc [ 'verify' ] = False _secret_variables = self . _config . secret_variables _pkg_name_col = self . _config . name_column _packages_found = OrderedDict ( ) _pkg_name_old = "" for _paths in parser . get_paths ( list_or_file_path , source ) : _packages = [ ] _params_found = { } _params_found_raw = { } last_error = '' _pkg_name = _paths [ 'params' ] [ _pkg_name_col ] if _pkg_name != _pkg_name_old : _pkg_name_old = _pkg_name self . _log . info ( '{}: {}' . format ( _pkg_name , { k : v for k , v in _paths [ 'params' ] . items ( ) if ( k not in ( _pkg_name_col , 'repo' ) and k not in _secret_variables ) } ) ) for _sub_paths in _paths [ 'paths' ] : _tmp_params = dict ( _paths [ 'params' ] ) self . _log . info ( 'repo: {}' . format ( _sub_paths [ 'repo' ] ) ) _tmp_params [ 'repo' ] = _sub_paths [ 'repo' ] try : _artifactory_server = _tmp_params [ 'server' ] _search_repo = _tmp_params [ 'repo' ] _aql_query_url = '{}/api/search/aql' . format ( _artifactory_server ) _aql_query_dict = { "repo" : { "$eq" : _search_repo , } , } _usedby_aql = parser . get_usedby_aql ( _tmp_params ) if _usedby_aql is None : continue _aql_query_dict . update ( _usedby_aql ) query = 'items.find({query_dict}).include("*", "property")' . format ( query_dict = json . dumps ( _aql_query_dict ) ) session . auth = _art_auth_etc [ 'auth' ] r = session . post ( _aql_query_url , data = query , verify = _art_auth_etc [ 'verify' ] ) r . raise_for_status ( ) _found_paths = r . json ( ) for _found in _found_paths [ 'results' ] : _repo_path = "{artifactory}/{repo}/{path}/{file_name}" . format ( artifactory = _artifactory_server , repo = _found [ 'repo' ] , path = _found [ 'path' ] , file_name = _found [ 'name' ] ) _repo_path = ArtifactoryPath ( _repo_path , ** _art_auth_etc ) _found_properties = { x [ 'key' ] : x . get ( 'value' , '' ) for x in _found [ 'properties' ] } _matched , _params , _params_raw = parser . validate_path ( str ( _repo_path ) , _tmp_params ) _params_found [ _repo_path ] = { k : v for k , v in _params . items ( ) } _params_found_raw [ _repo_path ] = { k : v for k , v in _params_raw . items ( ) } _params = _tmp_params _packages += [ _repo_path ] _params_found [ _repo_path ] . update ( { k : v for k , v in _params . items ( ) } ) _params_found [ _repo_path ] [ 'filename' ] = str ( _repo_path . name ) _params_raw = _params_found_raw . get ( _repo_path , { } ) params_found = { } params = parser . get_params_from_properties ( _found_properties ) params . update ( parser . get_params_from_path ( str ( _repo_path ) ) ) _package = Package ( params [ _pkg_name_col ] , _repo_path , params , downloader , self , parser , params_found , _params_raw ) _package . find_usedby ( None , property_validate = False ) _packages_found [ str ( _repo_path ) ] = _package _mark = 'chosen' self . _log . info ( '  {}: {}' . format ( _mark , str ( _repo_path ) ) ) except RuntimeError as e : try : err = json . loads ( e . args [ 0 ] ) except Exception : err = { } if isinstance ( err , dict ) : for error in err . get ( 'errors' , [ ] ) : err_status = error . get ( 'status' , - 1 ) err_msg = error . get ( 'message' , '' ) if err_status == 401 : msg = 'Authentication error[{}]{}' . format ( err_status , ( ': {}' . format ( err_msg ) ) if err_msg else '' ) elif err_status == 404 : msg = last_error else : msg = 'Error[{}]{}' . format ( err_status , ( ': {}' . format ( err_msg ) ) if err_msg else '' ) if last_error != msg : self . _log . error ( msg ) last_error = msg return _packages_found
:param source:
        :param parser:
        :param downloader:
        :param list_or_file_path:
        :param property_validate: for `root` packages we need check property, bad if we find packages from `lock` file,
        we can skip validate part
        :return: