Пример #1
0
def getxattr(_endpoint, filepath, userid, key):
    '''Get the extended attribute <key> using the given userid as access token. Do not raise exceptions'''
    tstart = time.time()
    reference = cs3spr.Reference(path=filepath)
    statInfo = ctx['cs3stub'].Stat(request=cs3sp.StatRequest(ref=reference),
                                   metadata=[('x-access-token', userid)])
    tend = time.time()
    if statInfo.status.code != cs3code.CODE_OK:
        ctx['log'].warning(
            'msg="Failed to stat" filepath="%s" key="%s" reason="%s"' %
            (filepath, key, statInfo.status.message))
        raise IOError(statInfo.status.message)
    try:
        xattrvalue = statInfo.info.arbitrary_metadata.metadata[key]
        if xattrvalue == '':
            raise KeyError
        ctx['log'].debug(
            'msg="Invoked stat for getxattr" filepath="%s" elapsedTimems="%.1f"'
            % (filepath, (tend - tstart) * 1000))
        return xattrvalue
    except KeyError:
        ctx['log'].info(
            'msg="Key not found in getxattr" filepath="%s" key="%s"' %
            (filepath, key))
        return None
Пример #2
0
    def stat(self, file_id, endpoint=None):
        """
        Stat a file and returns (size, mtime) as well as other extended info using the given userid as access token.
        Note that endpoint here means the storage id. Note that fileid can be either a path (which MUST begin with /)
        or an id (which MUST NOT start with a /).
        """
        time_start = time.time()
        ref = file_utils.get_reference(file_id, endpoint)
        stat_info = self.cs3_api.Stat(request=cs3sp.StatRequest(ref=ref),
                                      metadata=[('x-access-token',
                                                 self.auth.authenticate())])
        time_end = time.time()
        self.log.info('msg="Invoked stat" fileid="%s" elapsedTimems="%.1f"' %
                      (file_id, (time_end - time_start) * 1000))

        if stat_info.status.code == cs3code.CODE_OK:
            self.log.debug('msg="Stat result" data="%s"' % stat_info)
            return {
                'inode': {
                    'storage_id': stat_info.info.id.storage_id,
                    'opaque_id': stat_info.info.id.opaque_id
                },
                'filepath': stat_info.info.path,
                'userid': stat_info.info.owner.opaque_id,
                'size': stat_info.info.size,
                'mtime': stat_info.info.mtime.seconds,
                'type': stat_info.info.type,
                'mime_type': stat_info.info.mime_type,
                'idp': stat_info.info.owner.idp,
                'permissions': stat_info.info.permission_set
            }

        self.log.info('msg="Failed stat" fileid="%s" reason="%s"' %
                      (file_id, stat_info.status.message))
        raise FileNotFoundError(stat_info.status.message + ", file " + file_id)
Пример #3
0
 def _get_resource_info(self, endpoint, file_id):
     ref = FileUtils.get_reference(file_id, endpoint)
     token = self.get_token()
     stat_info = self.cs3_api.Stat(
         request=storage_provider.StatRequest(ref=ref),
         metadata=[('x-access-token', token)])
     return stat_info.info
Пример #4
0
def stat(endpoint, fileid, userid, versioninv=0):
    '''Stat a file and returns (size, mtime) as well as other extended info using the given userid as access token.
  Note that endpoint here means the storage id. Note that fileid can be either a path (which MUST begin with /),
  or an id (which MUST NOT start with a /).
  The versioninv flag is currently not supported, see CERNBOX-1216.'''
    if endpoint == 'default':
        raise IOError(
            'A CS3API-compatible storage endpoint must be identified by a storage UUID'
        )
    if versioninv == 1:
        ctx['log'].warning(
            'msg="Version-invariant Stat not yet supported, going for standard Stat"'
        )
    tstart = time.time()
    if fileid[0] == '/':
        # assume this is a filepath
        ref = cs3spr.Reference(path=fileid)
    else:
        # assume we have an opaque fileid
        ref = cs3spr.Reference(
            id=cs3spr.ResourceId(storage_id=endpoint, opaque_id=fileid))
    statInfo = ctx['cs3stub'].Stat(request=cs3sp.StatRequest(ref=ref),
                                   metadata=[('x-access-token', userid)])
    tend = time.time()
    ctx['log'].info('msg="Invoked stat" fileid="%s" elapsedTimems="%.1f"' %
                    (fileid, (tend - tstart) * 1000))
    if statInfo.status.code == cs3code.CODE_OK:
        ctx['log'].debug('msg="Stat result" data="%s"' % statInfo)
        # we base64-encode the inode so it can be used in a WOPISrc
        inode = urlsafe_b64encode(statInfo.info.id.opaque_id.encode())
        if statInfo.info.type == cs3spr.RESOURCE_TYPE_CONTAINER:
            raise IOError('Is a directory')
        elif statInfo.info.type not in (cs3spr.RESOURCE_TYPE_FILE,
                                        cs3spr.RESOURCE_TYPE_SYMLINK):
            ctx['log'].warning('msg="Stat: unexpected type" type="%d"' %
                               statInfo.info.type)
            raise IOError('Unexpected type %d' % statInfo.info.type)
        return {
            'inode': statInfo.info.id.storage_id + '-' + inode.decode(),
            'filepath': statInfo.info.path,
            'userid': statInfo.info.owner.opaque_id,
            'size': statInfo.info.size,
            'mtime': statInfo.info.mtime.seconds
        }
    ctx['log'].info('msg="Failed stat" fileid="%s" reason="%s"' %
                    (fileid, statInfo.status.message))
    raise IOError('No such file or directory' if statInfo.status.code ==
                  cs3code.CODE_NOT_FOUND else statInfo.status.message)
Пример #5
0
def stat(endpoint, fileid, userid, versioninv=0):
    '''Stat a file and returns (size, mtime) as well as other extended info using the given userid as access token.
  Note that endpoint here means the storage id. Note that fileid can be either a path (which MUST begin with /),
  or an id (which MUST NOT start with a /).
  The versioninv flag is currently not supported, see CERNBOX-1216.'''
    if endpoint == 'default':
        raise IOError(
            'A CS3API-compatible storage endpoint must be identified by a storage UUID'
        )
    if versioninv == 1:
        ctx['log'].warning(
            'msg="Version-invariant Stat not yet supported, going for standard Stat"'
        )
    tstart = time.time()
    if fileid[0] == '/':
        # assume this is a filepath
        ref = cs3spr.Reference(path=fileid)
    else:
        # assume we have an opaque fileid
        ref = cs3spr.Reference(
            id=cs3spr.ResourceId(storage_id=endpoint, opaque_id=fileid))
    statInfo = ctx['cs3stub'].Stat(request=cs3sp.StatRequest(ref=ref),
                                   metadata=[('x-access-token', userid)])
    tend = time.time()
    ctx['log'].info('msg="Invoked stat" fileid="%s" elapsedTimems="%.1f"' %
                    (fileid, (tend - tstart) * 1000))
    if statInfo.status.code == cs3code.CODE_OK:
        ctx['log'].debug('msg="Stat result" data="%s"' % statInfo)
        try:
            inode = int(statInfo.info.id.opaque_id)
        except ValueError:
            # the storage behind Reva provided a non-int file inode: let's hash it to really have an int
            inode = hash(statInfo.info.id.opaque_id)
        if S_ISDIR(statInfo.info.mode):
            raise IOError('Is a directory')
        return {
            'inode': statInfo.info.id.storage_id + '-' + str(inode),
            'filepath': statInfo.info.path,
            'userid': statInfo.info.owner.opaque_id,
            'size': statInfo.info.size,
            'mtime': statInfo.info.mtime.seconds
        }
    ctx['log'].info('msg="Failed stat" fileid="%s" reason="%s"' %
                    (fileid, statInfo.status.message))
    raise IOError('No such file or directory' if statInfo.status.code ==
                  cs3code.CODE_NOT_FOUND else statInfo.status.message)