コード例 #1
0
    def maybe_download_provider_info(self, replace=False):
        """
        Download the provider.json info from the main domain.
        This SHOULD only be used once with the DOMAIN url.
        """
        # TODO handle pre-seeded providers?
        # or let client handle that? We could move them to bonafide.
        provider_json = self._get_provider_json_path()

        if is_file(provider_json) and not replace:
            return defer.succeed('provider_info_already_exists')

        folders, f = os.path.split(provider_json)
        mkdir_p(folders)

        uri = self._disco.get_provider_info_uri()
        met = self._disco.get_provider_info_method()

        def errback(failure):
            shutil.rmtree(folders)
            raise NetworkError(failure.getErrorMessage())

        d = httpRequest(self._http._agent,
                        uri,
                        method=met,
                        saveto=provider_json)
        d.addCallback(lambda _: self._load_provider_json())
        d.addErrback(errback)
        return d
コード例 #2
0
def main(reactor, *args):
    client = http.HTTPClient()
    fname = os.path.join(tmp, str(uuid.uuid4()))
    yield httpRequest(client._agent, URI, method='GET', saveto=fname)
    filesize = os.path.getsize(fname)
    assert filesize > 1
    # touch file to 5 minutes in the past
    past = int(os.path.getmtime(fname)) - 300
    print "PAST MTIME", past
    os.utime(fname, (past, past))
    assert os.path.getmtime(fname) == past
    yield httpRequest(client._agent, URI, method='GET', saveto=fname)
    # it was not modified
    current = os.path.getmtime(fname)
    print "CURRENT MTIME", current
    assert int(current) == past
    print 'OK'
    shutil.rmtree(tmp)
コード例 #3
0
    def maybe_download_services_config(self, ignored):

        # TODO --- currently, some providers (mail.bitmask.net) raise 401
        # UNAUTHENTICATED if we try to get the services
        # See: # https://leap.se/code/issues/7906

        def further_bootstrap_needs_auth(ignored):
            self.log.warn('Cannot download services config yet, need auth')
            pending_deferred = defer.Deferred()
            self.stuck_bootstrap = pending_deferred
            return defer.succeed('ok for now')

        uri, met, path = self._get_configs_download_params()
        d = httpRequest(self._http._agent, uri, method=met, saveto=path)
        d.addCallback(lambda _: self._load_provider_json())
        d.addCallback(
            lambda _: self._get_config_for_all_services(session=None))
        d.addErrback(further_bootstrap_needs_auth)
        return d
コード例 #4
0
ファイル: config.py プロジェクト: rrosajp/bitmask-dev
    def maybe_download_services_config(self, ignored):
        # TODO --- currently, some providers (mail.bitmask.net) raise 401
        # UNAUTHENTICATED if we try to get the services
        # See: # https://leap.se/code/issues/7906

        def first_bootstrap_done(ignored):
            try:
                self.first_bootstrap.callback('got config')
            except defer.AlreadyCalledError:
                pass

        uri, met, path = self._get_configs_download_params()
        d = httpRequest(self._http._agent, uri, method=met, saveto=path)
        d.addCallback(lambda _: self._load_provider_json())
        d.addCallback(
            lambda _: self._get_config_for_all_services(session=None))
        d.addCallback(first_bootstrap_done)
        d.addErrback(lambda _: 'ok for now')
        return d
コード例 #5
0
 def _fetch_provider_configs_unauthenticated(self, uri, path):
     self.log.info('Downloading config for %s...' % uri)
     return httpRequest(self._http._agent, uri, saveto=path)
コード例 #6
0
 def _request(self, *args, **kw):
     kw['token'] = self._token
     return httpRequest(*args, **kw)
コード例 #7
0
 def _http_request(self, *args, **kw):
     # XXX pass if-modified-since header
     return httpRequest(self._agent, *args, **kw)