def libraries_io_project_url(cls, ecosystem, name): """Construct url to endpoint, which gets information about a project and it's versions.""" if ecosystem.is_backed_by(EcosystemBackend.npm): # quote '/' (but not '@') in scoped package name, e.g. in '@slicemenice/item-layouter' name = quote(name, safe='@') url = '{api}/{platform}/{name}'. \ format(api=cls.LIBRARIES_IO_API, platform=ecosystem.backend.name, name=name) if not cls.LIBRARIES_IO_TOKEN or cls.LIBRARIES_IO_TOKEN == 'not-set': raise F8AConfigurationException( "LIBRARIES_IO_TOKEN has not been set.") if cls.LIBRARIES_IO_TOKEN != 'no-token': url += '?api_key=' + cls.LIBRARIES_IO_TOKEN else: # 'no-token' value forces the API call to not use ANY token. # It works, but if abused, they can ban your IP, so use with caution. logger.warning( "Libraries.io API calls will be without an API key. " "It'll work, but if you're going to analyse more packages, " "please set the LIBRARIES_IO_TOKEN to your private token.") return url
def select_random_github_token(cls): """Select and test either no token or randomly chosen. :return: token and headers dictionary """ token = cls._decide_token_usage() headers = {} if token: headers.update({'Authorization': 'token {token}'.format(token=token)}) if cls._rate_limit_exceeded(headers): logger.error("No Github API token provided (GITHUB_TOKEN env variable), " "and rate limit exceeded! " "Ending now to not wait endlessly") raise F8AConfigurationException("Limit for unauthorized GitHub access exceeded.") return token, headers
def libraries_io_project_url(cls, ecosystem, name): """Construct url to endpoint, which gets information about a project and it's versions.""" url = '{api}/{platform}/{name}'. \ format(api=cls.LIBRARIES_IO_API, platform=ecosystem, name=name) if not cls.LIBRARIES_IO_TOKEN or cls.LIBRARIES_IO_TOKEN == 'not-set': raise F8AConfigurationException("LIBRARIES_IO_TOKEN has not been set.") # 'no-token' value forces the API call to not use ANY token. # It works, but if abused, they can ban your IP, so use with caution. if cls.LIBRARIES_IO_TOKEN != 'no-token': logger.warning("Libraries.io API calls will be without an API key." "It'll work, but if you're going to analyse more packages," "please set the LIBRARIES_IO_TOKEN to your private token.") url += '?api_key=' + cls.LIBRARIES_IO_TOKEN return url