Exemple #1
0
 def safe_path_join(self, root, *args):
     # full_path = os.path.realpath(os.path.join(root, *args))
     full_path = os.path.join(root, *args)
     if not full_path.startswith(os.path.realpath(root)):
         raise webapp.Forbidden(
             message="Path \"%s\" outside root directory." % (args))
     return full_path
Exemple #2
0
def assert_is_empty(generator, tname, iname):
    try:
        next(generator)
    except (StopIteration, SystemError):
        pass  # Everything is ok.
    else:
        raise webapp.Forbidden(
            message="Can't remove \"%s\" because it is an non-empty %s." %
            (iname, tname))
Exemple #3
0
    def PUT(self, ws_name, cs_name, format):
        """Modify coverage store <ds>."""
        
        ws = get_workspace(ws_name)
        data = get_data(name="coverageStore", 
                        mandatory=["name"], 
                        authorized=["name", "title", "abstract", "connectionParameters"])
        if cs_name != data.pop("name"):
            raise webapp.Forbidden("Can't change the name of a coverage store.")

        with webapp.mightNotFound("coverageStore", workspace=ws_name):
            ws.update_coveragestore(cs_name, data)
        ws.save()
Exemple #4
0
    def PUT(self, l_name, format):
        """Modify layer <l>."""

        mf = mra.get_available()

        data = get_data(name="layer", mandatory=[],
                        authorized=["name", "resource", "defaultStyle"])
        if l_name != data.get("name", l_name):
            raise webapp.Forbidden("Can't change the name of a layer.")

        l_enabled = True # TODO: => data.pop("enabled", True)

        mf = mra.get_available()
        with webapp.mightNotFound():
            layer = mf.get_layer(l_name)

        # update resource if changed
        href = data.get("resource", {}).get("href")
        if href:
            try:
                ws_name, st_type, st_name, r_type, r_name = mra.href_parse(href, 5)
            except ValueError:
                raise webapp.NotFound(message="resource \"%s\" was not found." % href)

            st_type, r_type = st_type[:-1], r_type[:-1] # Remove trailing s.

            ws = get_workspace(ws_name)
            with webapp.mightNotFound(r_type, workspace=ws_name):
                try:
                    model = ws.get_layermodel(r_type, st_name, r_name)
                except ValueError:
                    raise KeyError(r_type)

            if layer.get_mra_metadata("type") != r_type:
                raise webapp.BadRequest("Can't change a \"%s\" layer into a \"%s\"."
                                    % (layer.get_mra_metadata("type"), r_type))
        model.configure_layer(layer, l_enabled)

        # If we have a defaultStyle apply it.
        s_name = data.get("defaultStyle", {}).get("name")
        if s_name:
            with webapp.mightNotFound():
                style = mra.get_style(s_name)
            layer.add_style_sld(mf, s_name, style)
            
            # Remove the automatic default style.
            for s_name in layer.iter_styles():
                if s_name == tools.get_dflt_sld_name(layer.ms.type):
                    layer.remove_style(s_name)

        mf.save()
Exemple #5
0
    def PUT(self, ws_name, cs_name, c_name, format):
        """Modify coverage <c>."""
        
        ws = get_workspace(ws_name)

        data = get_data(name="coverage", mandatory=["name"], authorized=["name", "title", "abstract"])
        if c_name != data["name"]:
            raise webapp.Forbidden("Can't change the name of a coverage.")

        metadata = dict((k, v) for k, v in data.iteritems() if k in ["title", "abstract"])

        with webapp.mightNotFound("coverage", coveragestore=cs_name):
            ws.update_coveragemodel(c_name, cs_name, metadata)
        ws.save()
Exemple #6
0
    def PUT(self, ws_name, ds_name, ft_name, format):
        """Modify feature type <ft>."""

        ws = get_workspace(ws_name)

        data = get_data(name="featureType", mandatory=["name"], authorized=["name", "title", "abstract"])
        if ft_name != data["name"]:
            raise webapp.Forbidden("Can't change the name of a feature type.")

        metadata = dict((k, v) for k, v in data.iteritems() if k in ["title", "abstract"])

        with webapp.mightNotFound("featureType", datastore=ds_name):
            ws.update_featuretypemodel(ds_name, ft_name, metadata)
        ws.save()
Exemple #7
0
    def PUT(self, lg_name, format):
        """Modify layergroup <lg>."""

        mf = mra.get_available()

        with webapp.mightNotFound():
            lg = mf.get_layergroup(lg_name)

        data = get_data(name="layerGroup", mandatory=["name"], authorized=["name", "title", "abstract", "layers"])
        if lg_name != data.pop("name"):
            raise webapp.Forbidden("Can't change the name of a layergroup.")

        layers = data.pop("layers", [])
        if not isinstance(layers, list) or any(not isinstance(x, basestring) for x in layers):
            raise webapp.BadRequest("layers must be a list of layer names.")

        lg.clear()
        lg.add(*layers)

        mf.save()