def get(self, artifact_id, type_name=None, type_version=None, show_level=None, include_deleted=False): if show_level is None: show_level = ga.Showlevel.BASIC try: db_api_artifact = self.db_api.artifact_get(self.context, artifact_id, type_name, type_version, show_level) if db_api_artifact["state"] == 'deleted' and not include_deleted: raise exception.ArtifactNotFound(artifact_id) except (exception.ArtifactNotFound, exception.ArtifactForbidden): msg = _("No artifact found with ID %s") % artifact_id raise exception.ArtifactNotFound(msg) return serialization.deserialize_from_db(db_api_artifact, self.plugins)
def _get(context, artifact_id, session, type_name=None, type_version=None, show_level=ga.Showlevel.BASIC): values = dict(id=artifact_id) if type_name is not None: values['type_name'] = type_name if type_version is not None: values['type_version'] = type_version _set_version_fields(values) try: if show_level == ga.Showlevel.NONE: query = ( session.query(models.Artifact). options(joinedload(models.Artifact.tags)). filter_by(**values)) else: query = ( session.query(models.Artifact). options(joinedload(models.Artifact.properties)). options(joinedload(models.Artifact.tags)). options(joinedload(models.Artifact.blobs). joinedload(models.ArtifactBlob.locations)). filter_by(**values)) artifact = query.one() except orm.exc.NoResultFound: LOG.warn(_LW("Artifact with id=%s not found") % artifact_id) raise exception.ArtifactNotFound(id=artifact_id) if not _check_visibility(context, artifact): LOG.warn(_LW("Artifact with id=%s is not accessible") % artifact_id) raise exception.ArtifactForbidden(id=artifact_id) return artifact
def remove(self, artifact): try: self.db_api.artifact_delete(self.context, artifact.id, artifact.type_name, artifact.type_version) except (exception.NotFound, exception.Forbidden): msg = _("No artifact found with ID %s") % artifact.id raise exception.ArtifactNotFound(msg)
def publish(self, artifact): try: artifact_changed = (self.db_api.artifact_publish( self.context, artifact.id, artifact.type_name, artifact.type_version)) return serialization.deserialize_from_db(artifact_changed, self.plugins) except (exception.NotFound, exception.Forbidden): msg = _("No artifact found with ID %s") % artifact.id raise exception.ArtifactNotFound(msg)
def save(self, artifact): artifact_values = serialization.serialize_for_db(artifact) try: db_api_artifact = self.db_api.artifact_update( self.context, artifact_values, artifact.id, artifact.type_name, artifact.type_version) except (exception.ArtifactNotFound, exception.ArtifactForbidden): msg = _("No artifact found with ID %s") % artifact.id raise exception.ArtifactNotFound(msg) return serialization.deserialize_from_db(db_api_artifact, self.plugins)
def _get_latest_version(self, req, name, type_name, type_version=None, state='creating'): artifact_repo = self.gateway.get_artifact_repo(req.context) filters = dict(name={"value": name}, type_name={"value": type_name}, state={"value": state}) if type_version is not None: filters["type_version"] = {"value": type_version} result = artifact_repo.list(filters=filters, show_level=Showlevel.NONE, sort_keys=['version']) if len(result): return result[0].version msg = "No artifacts have been found" raise exception.ArtifactNotFound(message=msg)