Exemplo n.º 1
0
    def _send_hook(self, action, data):
        src_path = None
        if self.source_provider.NAME in IDENTIFIER_PATHS:
            src_path = self.json['source']['path'].identifier_path
        else:
            src_path = '/' + self.json['source']['path'].raw_path

        resp = yield from utils.send_signed_request(
            'PUT', self.callback_url, {
                'action': action,
                'source': {
                    'nid': self.json['source']['nid'],
                    'provider': self.source_provider.NAME,
                    'path': src_path,
                    'name': self.json['source']['path'].name,
                    'materialized': str(self.json['source']['path']),
                },
                'destination': dict(data, nid=self.json['destination']['nid']),
                'auth': self.auth['auth'],
                'time': time.time() + 60
            })

        if resp.status != 200:
            raise Exception('Callback was unsuccessful, got {}'.format(resp))
        logger.info(
            'Successfully sent callback for a {} request'.format(action))
Exemplo n.º 2
0
    def _send_hook(self, action):
        payload = {
            'action': action,
            'time': time.time() + 60,
            'auth': self.auth['auth'],
        }

        if action in ('move', 'copy'):
            payload.update({
                'source': {
                    'nid':
                    self.resource,
                    'name':
                    self.path.name,
                    'path':
                    self.path.identifier_path if self.provider.NAME
                    in IDENTIFIER_PATHS else self.path.path,
                    'provider':
                    self.provider.NAME,  # TODO rename to name
                    'materialized':
                    str(self.path),
                },
                'destination': {
                    'nid':
                    self.dest_resource,
                    'name':
                    self.dest_path.name,
                    'path':
                    self.dest_path.identifier_path if self.dest_provider.NAME
                    in IDENTIFIER_PATHS else self.dest_path.path,
                    'provider':
                    self.dest_provider.NAME,
                    'materialized':
                    str(self.dest_path),
                }
            })
        else:
            # This is adequate for everything but github
            # If extra can be included it will link to the given sha
            payload.update({
                'metadata': {
                    # Hack: OSF and box use identifiers to refer to files
                    'path':
                    self.path.identifier_path if self.provider.NAME
                    in IDENTIFIER_PATHS else self.path.path,
                    'name':
                    self.path.name,
                    'materialized':
                    str(self.path),
                }
            })

        resp = (yield from
                utils.send_signed_request('PUT', self.auth['callback_url'],
                                          payload))

        if resp.status != 200:
            raise Exception('Callback was unsuccessful, got {}'.format(resp))
        logger.info(
            'Successfully sent callback for a {} request'.format(action))
Exemplo n.º 3
0
def copy(src_bundle,
         dest_bundle,
         callback_url,
         auth,
         start_time=None,
         **kwargs):
    start_time = start_time or time.time()
    src_path, src_provider = src_bundle.pop('path'), utils.make_provider(
        **src_bundle.pop('provider'))
    dest_path, dest_provider = dest_bundle.pop('path'), utils.make_provider(
        **dest_bundle.pop('provider'))

    data = {
        'errors': [],
        'action':
        'copy',
        'source':
        dict(
            src_bundle, **{
                'path': src_path.path,
                'name': src_path.name,
                'materialized': str(src_path),
                'provider': src_provider.NAME,
            }),
        'destination':
        dict(
            dest_bundle, **{
                'path': dest_path.path,
                'name': dest_path.name,
                'materialized': str(dest_path),
                'provider': dest_provider.NAME,
            }),
        'auth':
        auth['auth'],
    }

    logger.info('Starting copying {!r}, {!r} to {!r}, {!r}'.format(
        src_path, src_provider, dest_path, dest_provider))

    try:
        metadata, created = yield from src_provider.copy(
            dest_provider, src_path, dest_path, **kwargs)
    except Exception as e:
        logger.error('Copy failed with error {!r}'.format(e))
        data.update({'errors': [e.__repr__()]})
        raise  # Ensure sentry sees this
    else:
        logger.info('Copy succeeded')
        data.update({'destination': dict(src_bundle, **metadata.serialized())})
    finally:
        resp = yield from utils.send_signed_request(
            'PUT', callback_url,
            dict(
                data, **{
                    'time': time.time() + 60,
                    'email': time.time() - start_time > settings.WAIT_TIMEOUT
                }))
        logger.info('Callback returned {!r}'.format(resp))

    return metadata, created
Exemplo n.º 4
0
    def _send_hook(self, action, data):
        src_path = None
        if self.source_provider.NAME in IDENTIFIER_PATHS:
            src_path = self.json['source']['path'].identifier_path
        else:
            src_path = '/' + self.json['source']['path'].raw_path

        resp = yield from utils.send_signed_request('PUT', self.callback_url, {
            'action': action,
            'source': {
                'nid': self.json['source']['nid'],
                'provider': self.source_provider.NAME,
                'path': src_path,
                'name': self.json['source']['path'].name,
                'materialized': str(self.json['source']['path']),
                'kind': self.json['source']['path'].kind,
            },
            'destination': dict(data, nid=self.json['destination']['nid']),
            'auth': self.auth['auth'],
            'time': time.time() + 60
        })

        if resp.status != 200:
            raise Exception('Callback was unsuccessful, got {}'.format(resp))
        logger.info('Successfully sent callback for a {} request'.format(action))
Exemplo n.º 5
0
 def _send_hook(self, action, metadata):
     return (yield from utils.send_signed_request('PUT', self.payload['callback_url'], {
         'action': action,
         'metadata': metadata,
         'auth': self.payload['auth'],
         'provider': self.arguments['provider'],
         'time': time.time() + 60
     }))
Exemplo n.º 6
0
 def _send_hook(self, action, metadata):
     return (yield from utils.send_signed_request(
         'PUT', self.payload['callback_url'], {
             'action': action,
             'metadata': metadata,
             'auth': self.payload['auth'],
             'provider': self.arguments['provider'],
             'time': time.time() + 60
         }))
Exemplo n.º 7
0
 def _send_hook(self, action, metadata):
     resp = yield from utils.send_signed_request('PUT', self.payload['callback_url'], {
         'action': action,
         'metadata': metadata,
         'auth': self.payload['auth'],
         'provider': self.arguments['provider'],
         'time': time.time() + 60
     })
     if resp.status != 200:
         raise Exception('Callback was unsuccessful, got {}'.format(resp))
     logger.info('Successfully sent callback for a {} request'.format(action))
Exemplo n.º 8
0
    def _send_hook(self, action):
        payload = {
            "action": action,
            "time": time.time() + 60,
            "auth": self.auth["auth"],
            "provider": self.provider.NAME,
        }

        if action in ("move", "copy"):
            payload.update(
                {
                    "source": {
                        "nid": self.resource,
                        "kind": self.path.kind,
                        "name": self.path.name,
                        "path": self.path.identifier_path if self.provider.NAME in IDENTIFIER_PATHS else self.path.path,
                        "provider": self.provider.NAME,  # TODO rename to name
                        "materialized": str(self.path),
                    },
                    "destination": {
                        "nid": self.dest_resource,
                        "kind": self.dest_path.kind,
                        "name": self.dest_path.name,
                        "path": self.dest_path.identifier_path
                        if self.dest_provider.NAME in IDENTIFIER_PATHS
                        else self.dest_path.path,
                        "provider": self.dest_provider.NAME,
                        "materialized": str(self.dest_path),
                    },
                }
            )
        else:
            # This is adequate for everything but github
            # If extra can be included it will link to the given sha
            payload.update(
                {
                    "metadata": {
                        # Hack: OSF and box use identifiers to refer to files
                        "path": self.path.identifier_path if self.provider.NAME in IDENTIFIER_PATHS else self.path.path,
                        "name": self.path.name,
                        "materialized": str(self.path),
                        "provider": self.provider.NAME,
                    }
                }
            )

        resp = (yield from utils.send_signed_request("PUT", self.auth["callback_url"], payload))

        if resp.status != 200:
            data = yield from resp.read()
            raise Exception("Callback was unsuccessful, got {}, {}".format(resp, data.decode("utf-8")))
        logger.info("Successfully sent callback for a {} request".format(action))
Exemplo n.º 9
0
 def _send_hook(self, action, metadata):
     resp = yield from utils.send_signed_request(
         'PUT', self.payload['callback_url'], {
             'action': action,
             'metadata': metadata,
             'auth': self.payload['auth'],
             'provider': self.arguments['provider'],
             'time': time.time() + 60
         })
     if resp.status != 200:
         raise Exception('Callback was unsuccessful, got {}'.format(resp))
     logger.info(
         'Successfully sent callback for a {} request'.format(action))
Exemplo n.º 10
0
 def _send_hook(self, action, data):
     return (yield from utils.send_signed_request('PUT', self.callback_url, {
         'action': action,
         'source': {
             'nid': self.json['source']['nid'],
             'provider': self.source_provider.NAME,
             'path': self.json['source']['path'].path,
             'name': self.json['source']['path'].name,
             'materialized': str(self.json['source']['path']),
         },
         'destination': dict(data, nid=self.json['destination']['nid']),
         'auth': self.auth['auth'],
         'time': time.time() + 60
     }))
Exemplo n.º 11
0
    def _send_hook(self, action):
        payload = {
            'action': action,
            'time': time.time() + 60,
            'auth': self.auth['auth'],
            'provider': self.provider.NAME,
        }

        callback_url = None
        if action in ('move', 'copy'):
            payload.update({
                'source': {
                    'nid': self.resource,
                    'kind': self.path.kind,
                    'name': self.path.name,
                    'path': self.path.identifier_path if self.provider.NAME in IDENTIFIER_PATHS else '/' + self.path.raw_path,
                    'provider': self.provider.NAME,  # TODO rename to name
                    'materialized': str(self.path),
                },
                'destination': {
                    'nid': self.dest_resource,
                    'kind': self.dest_meta.kind,
                    'name': self.dest_meta.name,
                    'path': self.dest_meta.path,
                    'provider': self.dest_provider.NAME,
                    'materialized': self.dest_meta.materialized_path,
                }
            })
            callback_url = self.dest_auth['callback_url']
        else:
            # This is adequate for everything but github
            # If extra can be included it will link to the given sha
            payload_path = self.target_path or self.path
            payload.update({
                'metadata': {
                    # Hack: OSF and box use identifiers to refer to files
                    'path': payload_path.identifier_path if self.provider.NAME in IDENTIFIER_PATHS else '/' + payload_path.raw_path,
                    'name': payload_path.name,
                    'materialized': str(payload_path),
                    'provider': self.provider.NAME,
                }
            })
            callback_url = self.auth['callback_url']

        resp = (yield from utils.send_signed_request('PUT', callback_url, payload))

        if resp.status != 200:
            data = yield from resp.read()
            raise Exception('Callback was unsuccessful, got {}, {}'.format(resp, data.decode('utf-8')))
        logger.info('Successfully sent callback for a {} request'.format(action))
Exemplo n.º 12
0
 def _send_hook(self, action, data):
     return (yield from utils.send_signed_request(
         'PUT', self.callback_url, {
             'action': action,
             'source': {
                 'nid': self.json['source']['nid'],
                 'provider': self.source_provider.NAME,
                 'path': self.json['source']['path'].path,
                 'name': self.json['source']['path'].name,
                 'materialized': str(self.json['source']['path']),
             },
             'destination': dict(data, nid=self.json['destination']['nid']),
             'auth': self.auth['auth'],
             'time': time.time() + 60
         }))
Exemplo n.º 13
0
def copy(src_bundle, dest_bundle, callback_url, auth, start_time=None, **kwargs):
    start_time = start_time or time.time()
    src_path, src_provider = src_bundle.pop('path'), utils.make_provider(**src_bundle.pop('provider'))
    dest_path, dest_provider = dest_bundle.pop('path'), utils.make_provider(**dest_bundle.pop('provider'))

    data = {
        'errors': [],
        'action': 'copy',
        'source': dict(src_bundle, **{
            'path': src_path.identifier_path if src_provider.NAME in IDENTIFIER_PATHS else '/' + src_path.raw_path,
            'name': src_path.name,
            'materialized': str(src_path),
            'provider': src_provider.NAME,
            'kind': src_path.kind,
        }),
        'destination': dict(dest_bundle, **{
            'path': dest_path.identifier_path if dest_provider.NAME in IDENTIFIER_PATHS else '/' + dest_path.raw_path,
            'name': dest_path.name,
            'materialized': str(dest_path),
            'provider': dest_provider.NAME,
            'kind': dest_path.kind,
        }),
        'auth': auth['auth'],
    }

    logger.info('Starting copying {!r}, {!r} to {!r}, {!r}'.format(src_path, src_provider, dest_path, dest_provider))

    try:
        metadata, created = yield from src_provider.copy(dest_provider, src_path, dest_path, **kwargs)
    except Exception as e:
        logger.error('Copy failed with error {!r}'.format(e))
        data.update({'errors': [e.__repr__()]})
        raise  # Ensure sentry sees this
    else:
        logger.info('Copy succeeded')
        data.update({'destination': dict(src_bundle, **metadata.serialized())})
    finally:
        resp = yield from utils.send_signed_request('PUT', callback_url, dict(data, **{
            'time': time.time() + 60,
            'email': time.time() - start_time > settings.WAIT_TIMEOUT
        }))
        logger.info('Callback returned {!r}'.format(resp))
        if resp.status // 100 != 2:
            raise Exception('Callback failed with {!r}'.format(resp)) from sys.exc_info()[1]

    return metadata, created
Exemplo n.º 14
0
def move(src_bundle, dest_bundle, callback_url, auth, start_time=None, **kwargs):
    start_time = start_time or time.time()
    src_path, src_provider = src_bundle.pop('path'), utils.make_provider(**src_bundle.pop('provider'))
    dest_path, dest_provider = dest_bundle.pop('path'), utils.make_provider(**dest_bundle.pop('provider'))

    data = {
        'errors': [],
        'action': 'move',
        'source': dict(src_bundle, **{
            'path': src_path.path,
            'name': src_path.name,
            'materialized': str(src_path),
            'provider': src_provider.NAME,
        }),
        'destination': dict(dest_bundle, **{
            'path': dest_path.path,
            'name': dest_path.name,
            'materialized': str(dest_path),
            'provider': dest_provider.NAME,
        }),
        'auth': auth['auth'],
    }

    logger.info('Starting moving {!r}, {!r} to {!r}, {!r}'.format(src_path, src_provider, dest_path, dest_provider))

    try:
        metadata, created = yield from src_provider.move(dest_provider, src_path, dest_path, **kwargs)
    except Exception as e:
        logger.error('Move failed with error {!r}'.format(e))
        data.update({'errors': [e.__repr__()]})
        raise  # Ensure sentry sees this
    else:
        logger.info('Move succeeded')
        data.update({'destination': dict(src_bundle, **metadata.serialized())})
    finally:
        resp = yield from utils.send_signed_request('PUT', callback_url, dict(data, **{
            'time': time.time() + 60,
            'email': time.time() - start_time > settings.WAIT_TIMEOUT
        }))
        logger.info('Callback returned {!r}'.format(resp))

    return metadata, created