Beispiel #1
0
    def _map_share(self, share, state=None):
        response = {
            "id": share.id.opaque_id,
            "storage_id": share.resource_id.storage_id,
            "opaque_id": share.resource_id.opaque_id,
            "name": share.name,
            "permissions": ShareUtils.map_permissions_to_role(share.permissions.permissions),
            "grantee": {
                "type": ShareUtils.map_grantee_type(share),
                "idp": share.grantee.id.idp,
                "opaque_id": share.grantee.id.opaque_id
            },
            "owner": {
                "idp": share.owner.idp,
                "opaque_id": share.owner.opaque_id
            },
            "creator": {
                "idp": share.creator.idp,
                "opaque_id": share.creator.opaque_id
            }
        }
        if state:
            response.update({"state": ShareUtils.map_state(state)})

        return response
 def create_ocm_share(self, grantee_opaque, idp, domain, endpoint,
                      file_path, grantee_type, role, reshare):
     opaque = cs3_types.Opaque(
         map={
             "permissions":
             cs3_types.OpaqueEntry(decoder="plain",
                                   value=str.encode(self._map_role(role))),
             "name":
             cs3_types.OpaqueEntry(decoder="plain",
                                   value=str.encode('my_resource_name'))
         })
     resource_id = storage_resources.ResourceId(storage_id=endpoint,
                                                opaque_id=file_path)
     user_id = identity_res.UserId(idp=idp, opaque_id=grantee_opaque)
     grantee_opaque = storage_resources.Grantee(
         type=ShareUtils.map_grantee(grantee_type), user_id=user_id)
     perms = sharing_res.SharePermissions(
         permissions=ShareUtils.get_resource_permissions(role),
         reshare=bool(reshare))
     grant = sharing_res.ShareGrant(permissions=perms,
                                    grantee=grantee_opaque)
     provider_info = self._get_provider_info(domain)
     request = ocm_api.CreateOCMShareRequest(
         opaque=opaque,
         resource_id=resource_id,
         grant=grant,
         recipient_mesh_provider=provider_info)
     response = self.ocm_share_api.CreateOCMShare(request=request,
                                                  metadata=self._token())
     if self._is_code_ok(response):
         self.log.info("OCM share created:\n" + response)
     else:
         self._handle_error(response, "Error creating OCM share")
     return self._map_share(response.share)
Beispiel #3
0
    def update_ocm_share(self, share_id, field, value):
        share_id_obj = sharing_res.ShareId(opaque_id=share_id)
        ref = sharing_res.ShareReference(id=share_id_obj)
        if field == 'permissions':
            request = ocm_api.UpdateOCMShareRequest(ref=ref,
                                                    field=ocm_api.UpdateOCMShareRequest.UpdateField(
                                                        permissions=sharing_res.SharePermissions(
                                                            permissions=ShareUtils.get_resource_permissions(value[0]),
                                                            reshare=bool(value[1]))
                                                    ))
        elif field == 'display_name':
            request = ocm_api.UpdateOCMShareRequest(ref=ref,
                                                    field=ocm_api.UpdateOCMShareRequest.UpdateField(
                                                        display_name=value
                                                    ))
        else:
            raise ValueError('Unknown field to update')

        response = self.ocm_share_api.UpdateOCMShare(request=request,
                                                     metadata=self._token())
        if self._is_code_ok(response):
            self.log.info("OCM share updated:\n" + response)
            return
        else:
            self._handle_error(response, "Error updating OCM share:")
Beispiel #4
0
    def update_received_ocm_share(self, share_id, field, value):
        share_id_obj = sharing_res.ShareId(opaque_id=share_id)
        ref = sharing_res.ShareReference(id=share_id_obj)
        if field == 'display_name':
            request = ocm_api.UpdateReceivedOCMShareRequest(ref=ref,
                                                            field=ocm_api.UpdateReceivedOCMShareRequest
                                                            .UpdateField(
                                                                display_name=value
                                                            ))
        elif field == 'state':
            request = ocm_api.UpdateReceivedOCMShareRequest(ref=ref,
                                                            field=ocm_api.UpdateReceivedOCMShareRequest
                                                            .UpdateField(
                                                                state=ShareUtils.map_state(value)
                                                            ))
        else:
            raise ValueError("Unknown field to update")

        response = self.ocm_share_api.UpdateReceivedOCMShare(request=request,
                                                             metadata=self._token())
        if self._is_code_ok(response):
            self.log.info("OCM received share updated:\n" + response)
            return
        else:
            self._handle_error(response, "Error updating OCM received share:")
        return response