def show_type_schema(cls, context, type_name): policy.authorize("artifact:type_list", {}, context) schemas = cls._get_schemas(cls.registry) if type_name not in schemas: msg = _("Artifact type %s does not exist") % type_name raise exception.NotFound(message=msg) return schemas[type_name]
def delete_external_blob(self, context, type_name, artifact_id, field_name, blob_key=None): """Delete artifact blob with external location. :param context: user context :param type_name: name of artifact type :param artifact_id: id of artifact with the blob to delete :param field_name: name of blob or blob dict field :param blob_key: if field_name is blob dict it specifies key in this dictionary """ af = self._show_artifact(context, type_name, artifact_id) action_name = 'artifact:delete_blob' policy.authorize(action_name, af.to_dict(), context) blob_name = self._generate_blob_name(field_name, blob_key) blob = self._get_blob_info(af, field_name, blob_key) if blob is None: msg = _("Blob %s wasn't found for artifact") % blob_name raise exception.NotFound(message=msg) if not blob['external']: msg = _("Blob %s is not external") % blob_name raise exception.Forbidden(message=msg) af = self._save_blob_info(context, af, field_name, blob_key, None) Notifier.notify(context, action_name, af) return af.to_dict()
def show_type_schemas(self, context, type_name=None): policy.authorize("artifact:type_list", {}, context) if type_name is None: return self.schemas if type_name not in self.schemas: msg = _("Artifact type %s does not exist") % type_name raise exception.NotFound(message=msg) return self.schemas[type_name]
def get_blob_data(context, uri, session): """Download blob data from database.""" blob_data_id = uri[6:] try: blob_data = session.query( models.ArtifactBlobData).filter_by(id=blob_data_id).one() except orm.exc.NoResultFound: msg = _("Cannot find a blob data with id %s.") % blob_data_id raise exception.NotFound(msg) return blob_data.data
def delete_lock(context, lock_id, session): try: session.query(models.ArtifactLock).filter_by(id=lock_id).delete() except orm.exc.NoResultFound: msg = _("Cannot delete a lock with id %s.") % lock_id raise exception.NotFound(msg)
def download_blob(self, context, type_name, artifact_id, field_name, blob_key=None): """Download binary data from Glare Artifact. :param context: user context :param type_name: name of artifact type :param artifact_id: id of the artifact to be updated :param field_name: name of blob or blob dict field :param blob_key: if field_name is blob dict it specifies key in this dict :return: file iterator for requested file """ download_from_any_artifact = False if policy.authorize("artifact:download_from_any_artifact", {}, context, do_raise=False): download_from_any_artifact = True af = self._show_artifact(context, type_name, artifact_id, read_only=True, get_any_artifact=download_from_any_artifact) if not download_from_any_artifact: policy.authorize("artifact:download", af.to_dict(), context) blob_name = self._generate_blob_name(field_name, blob_key) if af.status == 'deleted': msg = _("Cannot download data when artifact is deleted") raise exception.Forbidden(message=msg) blob = self._get_blob_info(af, field_name, blob_key) if blob is None: msg = _("No data found for blob %s") % blob_name raise exception.NotFound(message=msg) if blob['status'] != 'active': msg = _("%s is not ready for download") % blob_name raise exception.Conflict(message=msg) af.pre_download_hook(context, af, field_name, blob_key) meta = { 'md5': blob.get('md5'), 'sha1': blob.get('sha1'), 'sha256': blob.get('sha256'), 'external': blob.get('external') } if blob['external']: data = {'url': blob['url']} else: data = store_api.load_from_store(uri=blob['url'], context=context) meta['size'] = blob.get('size') meta['content_type'] = blob.get('content_type') try: # call download hook in the end data = af.post_download_hook(context, af, field_name, blob_key, data) except exception.GlareException: raise except Exception as e: raise exception.BadRequest(message=str(e)) return data, meta