Example #1
0
    def streamUpload(self, params):
        nmodel = self.model('notification')
        note = nmodel.initProgress(self.getCurrentUser(), 'Docker stream demo')
        for i, chunk in enumerate(iterBody(), 1):
            nmodel.updateProgress(note, message='%d: %s' % (i, chunk))

        nmodel.updateProgress(
            note, state=ProgressState.SUCCESS,
            expires=datetime.datetime.utcnow() + datetime.timedelta(seconds=10))
Example #2
0
    def streamUpload(self, params):
        nmodel = self.model('notification')
        note = nmodel.initProgress(self.getCurrentUser(), 'Docker stream demo')
        for i, chunk in enumerate(iterBody(), 1):
            nmodel.updateProgress(note, message='%d: %s' % (i, chunk))

        nmodel.updateProgress(note,
                              state=ProgressState.SUCCESS,
                              expires=datetime.datetime.utcnow() +
                              datetime.timedelta(seconds=10))
Example #3
0
    def input_stream(self, item, delimiter):
        chunks = six.BytesIO()
        for chunk in iterBody(1):
            chunks.write(chunk)
            chunks.write(delimiter.encode('utf-8'))

        chunks.seek(0)
        contents = chunks.read()
        chunks.seek(0)
        Upload().uploadFromFile(
            chunks, len(contents), 'chunks', parentType='item', parent=item,
            user=getCurrentUser())
    def _extractZipPayload():
        # TODO: Move assetstore type to wholetale.
        assetstore = next((_ for _ in Assetstore().list() if _['type'] == 101),
                          None)
        if assetstore:
            adapter = assetstore_utilities.getAssetstoreAdapter(assetstore)
            tempDir = adapter.tempDir
        else:
            tempDir = None

        with tempfile.NamedTemporaryFile(dir=tempDir) as fp:
            for chunk in iterBody(2 * 1024**3):
                fp.write(chunk)
            fp.seek(0)
            if not zipfile.is_zipfile(fp):
                raise RestException("Provided file is not a zipfile")

            with zipfile.ZipFile(fp) as z:
                manifest_file = next(
                    (_ for _ in z.namelist() if _.endswith('manifest.json')),
                    None)
                if not manifest_file:
                    raise RestException(
                        "Provided file doesn't contain a Tale manifest")

                try:
                    manifest = json.loads(z.read(manifest_file).decode())
                    # TODO: is there a better check?
                    manifest['@id'].startswith('https://data.wholetale.org')
                except Exception as e:
                    raise RestException(
                        "Couldn't read manifest.json or not a Tale: {}".format(
                            str(e)))

                env_file = next(
                    (_
                     for _ in z.namelist() if _.endswith("environment.json")),
                    None)
                try:
                    environment = json.loads(z.read(env_file).decode())
                except Exception as e:
                    raise RestException(
                        "Couldn't read environment.json or not a Tale: {}".
                        format(str(e)))

                # Extract files to tmp on workspace assetstore
                temp_dir = tempfile.mkdtemp(dir=tempDir)
                # In theory malicious content like: abs path for a member, or relative path with
                # ../.. etc., is taken care of by zipfile.extractall, but in the end we're still
                # unzipping an untrusted content. What could possibly go wrong...?
                z.extractall(path=temp_dir)
        return temp_dir, manifest_file, manifest, environment
Example #5
0
 def inputStream(self, params):
     # Read body 5 bytes at a time so we can test chunking a small body
     strictLength = self.boolParam('strictLength', params, False)
     for chunk in iterBody(5, strictLength=strictLength):
         _chunks.append(chunk.decode())
     return _chunks
Example #6
0
 def inputStream(self, params):
     # Read body 5 bytes at a time so we can test chunking a small body
     strictLength = self.boolParam('strictLength', params, False)
     for chunk in iterBody(5, strictLength=strictLength):
         _chunks.append(chunk.decode())
     return _chunks