<div dir="ltr"><div>+1</div><div><br></div><div>..Tom<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Dec 26, 2023 at 8:02 PM Michael Smith via MapServer-dev <<a href="mailto:mapserver-dev@lists.osgeo.org">mapserver-dev@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">I like it. Having more runtime config is always useful. <div><br id="m_-5459093615219721519lineBreakAtBeginningOfSignature"><div dir="ltr">Michael Smith</div><div dir="ltr"><br><blockquote type="cite">On Dec 26, 2023, at 4:57 PM, Steve Lime via MapServer-dev <<a href="mailto:mapserver-dev@lists.osgeo.org" target="_blank">mapserver-dev@lists.osgeo.org</a>> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="ltr">As a follow up. My previous message was inaccurate and kind of dumb on my part. You only have to set a default value with no validation block for things to basically function as a variable with runtime subs. MapServer will not try to do a substitution if a validation expression is not set and will automatically fall back to the default value. So, you just need:<div><br></div><div> "variable_default" "some value"</div><div><br></div><div>in a validation block and then you'd reference "%variable%" in supported locations. Passing variable= in the request will have no effect.</div><div><br></div><div>If we allowed "some value" to reference an environment variable (maybe with a leading $ in the default value) then I could see where that might be a pretty useful way to externalize some configuration information. We might consider adding a VALIDATION block to the config file as well.</div><div><br></div><div>--Steve</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 17, 2023 at 3:37 PM Lime, Steve D (MNIT) via MapServer-dev <<a href="mailto:mapserver-dev@lists.osgeo.org" target="_blank">mapserver-dev@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>
<div lang="EN-US">
<div>
<p class="MsoNormal">Hi Jukka: Yeah, this is a potential area for improvement. We’ve be using a couple of strategies where I work. One being includes plus runtime subs so you can embed replacement strings as necessary, similar to your examples. The environment
file gets included in a validation block and you set both a default and validation patterns for each value:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"> “dbhost_default” “some.database.host”<u></u><u></u></p>
<p class="MsoNormal"> “dbhost” “^some\.database\.host$”<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">So dbhost can only be the one value. I feels cleaner just write things the way you suggest. However, it feels wrong to have to set a value twice – and is potentially error prone in a bad way. Plus, there’s no connection to the environment.
I’m not a huge fan.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">The other approach is using a pre-processor to essentially compile a mapfile into a final version. We’re using YAML + mappyfile to create an environment-specific version of the mapfile. The YAML definition can consist of constants plus
references to environment variables. There is loads of potential here but deployment in different environments requires a compilation step plus a working Python environment.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">So, I can see value in a VARIABLES block or reference to a file. Could also do that at the config file level instead. Beyond loading the hash somehow, one would need a method to apply the variables in a limited fashion, probably while the
mapfile is being parsed. So, load the DATA value and then apply variables or something like that.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">This warrants an RFC I think…<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">--Steve<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div style="border-width:1pt medium medium;border-style:solid none none;border-color:rgb(225,225,225) currentcolor currentcolor;padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> MapServer-dev <<a href="mailto:mapserver-dev-bounces@lists.osgeo.org" target="_blank">mapserver-dev-bounces@lists.osgeo.org</a>>
<b>On Behalf Of </b>Rahkonen Jukka via MapServer-dev<br>
<b>Sent:</b> Thursday, November 9, 2023 5:08 PM<br>
<b>To:</b> '<a href="mailto:mapserver-dev@lists.osgeo.org" target="_blank">mapserver-dev@lists.osgeo.org</a>' <<a href="mailto:mapserver-dev@lists.osgeo.org" target="_blank">mapserver-dev@lists.osgeo.org</a>><br>
<b>Subject:</b> [MapServer-dev] Variables in mapfiles<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><span lang="FI"><u></u> <u></u></span></p>
<div>
<p class="MsoNormal"><span lang="FI">Hi,<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="FI"><u></u> <u></u></span></p>
<p class="MsoNormal">When I was reading the old bug reports in the OSGeo code sprint this 20 years old one
<a href="https://github.com/MapServer/MapServer/issues/408" target="_blank">https://github.com/MapServer/MapServer/issues/408</a> from year 2003 did not feel rotten at all. And the last comment
<a href="https://github.com/MapServer/MapServer/issues/408#issuecomment-1065080140" target="_blank">
https://github.com/MapServer/MapServer/issues/408#issuecomment-1065080140</a> has received 5 thumbs up within 1 year which shows great user activity by our standards.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I think that environmental variables may be too strong tool for this purpose. For example, are those who write mapfiles allowed to set env variables in managed environments? Maybe something similar to SYMBOLSET and INCLUDE would be easier
to use.<u></u><u></u></p>
<p class="MsoNormal">As an example, I found a pretty good bug report that includes a mapfile and data, but for testing the mapfile on my Windows machine I need to make a few edits.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">CONFIG "PROJ_LIB" "/usr/local/share/proj"<u></u><u></u></p>
<p class="MsoNormal"> I am on Windows and my proj is in some other place<u></u><u></u></p>
<p class="MsoNormal">WMS_ONLINERESOURCE <a href="http://odroid1:5001/" target="_blank">http://odroid1:5001/</a><u></u><u></u></p>
<p class="MsoNormal">wms_service_onlineresource <a href="http://odroid1:5001/" target="_blank">http://odroid1:5001/</a><u></u><u></u></p>
<p class="MsoNormal"> I don’t understand the difference between those two, but anyway I run Mapserver at
<a href="http://localhost:8060/..." target="_blank">http://localhost:8060/...</a><u></u><u></u></p>
<p class="MsoNormal">DATA "./bug-report.xml"<u></u><u></u></p>
<p class="MsoNormal"> I prefer to keep data in different place than mapfiles<u></u><u></u></p>
<p class="MsoNormal">DATA "./data-in-31287"<u></u><u></u></p>
<p class="MsoNormal"> Same for this shapefile data<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">What if we could write non-fixed paths and other items into the mapfile like<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">CONFIG "PROJ_LIB" "%proj_lib%"<u></u><u></u></p>
<p class="MsoNormal">WMS_ONLINERESOURCE "%onlineresource_test%"<u></u><u></u></p>
<p class="MsoNormal">wms_service_onlineresource "%onlineresource_test%"<u></u><u></u></p>
<p class="MsoNormal">DATA "%datapath_test%/bug-report.xml"<u></u><u></u></p>
<p class="MsoNormal">DATA "%datapath_test%/data-in-31287"<u></u><u></u></p>
<p class="MsoNormal">….<u></u><u></u></p>
<p class="MsoNormal">MAPVARIABLES "map_variables.txt"<u></u><u></u></p>
<p class="MsoNormal">END # mapfile<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">The contents of "map_variables.txt"<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">//Some magic<u></u><u></u></p>
<p class="MsoNormal">proj_lib [value]<u></u><u></u></p>
<p class="MsoNormal">onlineresource_test [value]<u></u><u></u></p>
<p class="MsoNormal">onlineresource_qa [value]<u></u><u></u></p>
<p class="MsoNormal">onlineresourse_production [value]<u></u><u></u></p>
<p class="MsoNormal">datapath_test [value]<u></u><u></u></p>
<p class="MsoNormal">datapath_qa [value]<u></u><u></u></p>
<p class="MsoNormal">datapath_production [value]<u></u><u></u></p>
<p class="MsoNormal">symbolset_topomap [value]<u></u><u></u></p>
<p class="MsoNormal">symbolset_citymap [value]<u></u><u></u></p>
<p class="MsoNormal">etc.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">A difference to INCLUDE is that while the whole include file is slipped inside the mapfile the variable file could be a dictionary. That would allow forwarding the mapfile from test to qa to production easily. And when the IP address of
test servers change an edit in one place would be enough. It would still be possible to use separate "map_variables_testing.txt" for testing if it feels better.
<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I admit that there are alternative scenarios via INCLUDE or config file or environmental variables.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">-Jukka Rahkonen-<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
_______________________________________________<br>
MapServer-dev mailing list<br>
<a href="mailto:MapServer-dev@lists.osgeo.org" target="_blank">MapServer-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/mapserver-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/mapserver-dev</a><br>
</div></blockquote></div>
<span>_______________________________________________</span><br><span>MapServer-dev mailing list</span><br><span><a href="mailto:MapServer-dev@lists.osgeo.org" target="_blank">MapServer-dev@lists.osgeo.org</a></span><br><span><a href="https://lists.osgeo.org/mailman/listinfo/mapserver-dev" target="_blank">https://lists.osgeo.org/mailman/listinfo/mapserver-dev</a></span><br></div></blockquote></div></div>_______________________________________________<br>
MapServer-dev mailing list<br>
<a href="mailto:MapServer-dev@lists.osgeo.org" target="_blank">MapServer-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/mapserver-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/mapserver-dev</a><br>
</blockquote></div></div>