<div dir="ltr">Default values in validation blocks behave like variables when there is no corresponding regex entry. So you'd get the best of both... </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 27, 2023 at 7:42 PM Richard Greenwood <<a href="mailto:richard.greenwood@gmail.com">richard.greenwood@gmail.com</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="ltr">I may be missing the point, but it seems like it would be useful to have variables in a MAP file. As I understand it, the CONFIG file is server-wide. If there are multiple MAP files for multiple projects on the same server they would all be sharing the same variables. Obviously the variables could be uniquely named for each project. But what about an include file that was used in multiple projects in which you wanted a variable that was set in the MAP file that included it? For example, a layer definition in an include file that was used in multiple projects in which you wanted to have a CONNECTION or DATA variable that was specific to the project. <div><br></div><div>Rich</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 27, 2023 at 2:52 AM Seth G 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><u></u><div><div>Hi Steve,<br></div><div><br></div><div>I like the idea of a VARIABLES block in the CONFIG file. I'm not sure a VALIDATION block would also be required - if a user can edit a CONFIG file they'd have to assume responsibility for any values set. <br></div><div>As a first step of processing the Mapfile any $varName in a VARIABLE block default variable value would be replaced by the values in the CONFIG file. This should require no changes to the Mapfile syntax. <br></div><div>I'd prefer to avoid using environment variables for values as these are very much platform and web server dependent. <br></div><div><br></div><div>Seth<br></div><div><br></div><div id="m_4710443260758707284m_2064194632341757569sig62266145"><div>--<br></div><div>web:<a href="https://geographika.net" target="_blank">https://geographika.net</a> & <a href="https://mapserverstudio.net" target="_blank">https://mapserverstudio.net</a><br></div><div>twitter: @geographika<br></div></div><div><br></div><div>On Tue, Dec 26, 2023, at 10:57 PM, Steve Lime via MapServer-dev wrote:<br></div><blockquote type="cite" id="m_4710443260758707284m_2064194632341757569qt"><div dir="ltr"><div>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:<br></div><div><br></div><div>  "variable_default" "some value"<br></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.<br></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.<br></div><div><br></div><div>--Steve<br></div></div><div><br></div><div><div dir="ltr">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 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>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><br></p><p><u></u> <u></u><br></p><p>  “dbhost_default” “some.database.host”<u></u><u></u><br></p><p>  “dbhost”                “^some\.database\.host$”<u></u><u></u><br></p><p><u></u> <u></u><br></p><p>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><br></p><p><u></u> <u></u><br></p><p>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><br></p><p><u></u> <u></u><br></p><p>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><br></p><p><u></u> <u></u><br></p><p>This warrants an RFC I think…<u></u><u></u><br></p><p><u></u> <u></u><br></p><p>--Steve<u></u><u></u><br></p><p><u></u> <u></u><br></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></p><div><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></div><div> <b>Sent:</b> Thursday, November 9, 2023 5:08 PM<br></div><div> <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></div><div> <b>Subject:</b> [MapServer-dev] Variables in mapfiles<u></u><u></u><br></div><p></p></div></div><p><span lang="FI"><u></u> <u></u></span><br></p><div><p><span lang="FI">Hi,<u></u><u></u></span><br></p><p><span lang="FI"><u></u> <u></u></span><br></p><p>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><br></p><p><u></u> <u></u><br></p><p>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><br></p><p>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><br></p><p><u></u> <u></u><br></p><p>CONFIG "PROJ_LIB" "/usr/local/share/proj"<u></u><u></u><br></p><p>                          I am on Windows and my proj is in some other place<u></u><u></u><br></p><p>WMS_ONLINERESOURCE <a href="http://odroid1:5001/" target="_blank">http://odroid1:5001/</a><u></u><u></u><br></p><p>wms_service_onlineresource <a href="http://odroid1:5001/" target="_blank">http://odroid1:5001/</a><u></u><u></u><br></p><p>                          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><br></p><p>DATA "./bug-report.xml"<u></u><u></u><br></p><p>                          I prefer to keep data in different place than mapfiles<u></u><u></u><br></p><p>DATA "./data-in-31287"<u></u><u></u><br></p><p>                          Same for this shapefile data<u></u><u></u><br></p><p><u></u> <u></u><br></p><p>What if we could write non-fixed paths and other items into the mapfile like<u></u><u></u><br></p><p><u></u> <u></u><br></p><p>CONFIG "PROJ_LIB" "%proj_lib%"<u></u><u></u><br></p><p>WMS_ONLINERESOURCE "%onlineresource_test%"<u></u><u></u><br></p><p>wms_service_onlineresource "%onlineresource_test%"<u></u><u></u><br></p><p>DATA "%datapath_test%/bug-report.xml"<u></u><u></u><br></p><p>DATA "%datapath_test%/data-in-31287"<u></u><u></u><br></p><p>….<u></u><u></u><br></p><p>MAPVARIABLES "map_variables.txt"<u></u><u></u><br></p><p>END # mapfile<u></u><u></u><br></p><p><u></u> <u></u><br></p><p>The contents of "map_variables.txt"<u></u><u></u><br></p><p><u></u> <u></u><br></p><p>//Some magic<u></u><u></u><br></p><p>proj_lib                                      [value]<u></u><u></u><br></p><p>onlineresource_test                [value]<u></u><u></u><br></p><p>onlineresource_qa                  [value]<u></u><u></u><br></p><p>onlineresourse_production   [value]<u></u><u></u><br></p><p>datapath_test                           [value]<u></u><u></u><br></p><p>datapath_qa                             [value]<u></u><u></u><br></p><p>datapath_production             [value]<u></u><u></u><br></p><p>symbolset_topomap               [value]<u></u><u></u><br></p><p>symbolset_citymap                 [value]<u></u><u></u><br></p><p>etc.<u></u><u></u><br></p><p><u></u> <u></u><br></p><p>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><br></p><p><u></u> <u></u><br></p><p>I admit that there are alternative scenarios via INCLUDE or config file or environmental variables.<u></u><u></u><br></p><p><u></u> <u></u><br></p><p>-Jukka Rahkonen-<u></u><u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p><p><u></u> <u></u><br></p></div></div></div><div>_______________________________________________<br></div><div> MapServer-dev mailing list<br></div><div> <a href="mailto:MapServer-dev@lists.osgeo.org" target="_blank">MapServer-dev@lists.osgeo.org</a><br></div><div> <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></div></blockquote></div><div>_______________________________________________<br></div><div>MapServer-dev mailing list<br></div><div><a href="mailto:MapServer-dev@lists.osgeo.org" target="_blank">MapServer-dev@lists.osgeo.org</a><br></div><div><a href="https://lists.osgeo.org/mailman/listinfo/mapserver-dev" target="_blank">https://lists.osgeo.org/mailman/listinfo/mapserver-dev</a><br></div><div><br></div></blockquote><div><br></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><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr">Richard W. Greenwood<br><a href="http://www.greenwoodmap.com" target="_blank">www.greenwoodmap.com</a></div></div>
</blockquote></div>