py-qgis-server 1.9.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py_qgis_server-1.9.8.dist-info/METADATA +223 -0
- py_qgis_server-1.9.8.dist-info/RECORD +67 -0
- py_qgis_server-1.9.8.dist-info/WHEEL +4 -0
- py_qgis_server-1.9.8.dist-info/entry_points.txt +15 -0
- pyqgisserver/__init__.py +0 -0
- pyqgisserver/build.manifest +4 -0
- pyqgisserver/config.py +343 -0
- pyqgisserver/config.yml +454 -0
- pyqgisserver/handlers/__init__.py +9 -0
- pyqgisserver/handlers/asynchandler.py +224 -0
- pyqgisserver/handlers/basehandler.py +175 -0
- pyqgisserver/handlers/landingpage.py +80 -0
- pyqgisserver/handlers/oapihandler.py +63 -0
- pyqgisserver/handlers/owshandler.py +80 -0
- pyqgisserver/handlers/statushandler.py +88 -0
- pyqgisserver/logger.py +131 -0
- pyqgisserver/management/__init__.py +0 -0
- pyqgisserver/management/apis/__init__.py +16 -0
- pyqgisserver/management/apis/cache.py +54 -0
- pyqgisserver/management/apis/handler.py +258 -0
- pyqgisserver/management/apis/plugins.py +62 -0
- pyqgisserver/management/server.py +225 -0
- pyqgisserver/middleware.py +84 -0
- pyqgisserver/monitor.py +32 -0
- pyqgisserver/monitors/amqp.py +135 -0
- pyqgisserver/monitors/base.py +33 -0
- pyqgisserver/monitors/test.py +44 -0
- pyqgisserver/plugins.py +167 -0
- pyqgisserver/py.typed +0 -0
- pyqgisserver/qgscache/__init__.py +1 -0
- pyqgisserver/qgscache/cachemanager.py +552 -0
- pyqgisserver/qgscache/handlers/__init__.py +13 -0
- pyqgisserver/qgscache/handlers/file_handler.py +88 -0
- pyqgisserver/qgscache/handlers/postgres_handler.py +160 -0
- pyqgisserver/qgscache/handlers/proto.py +27 -0
- pyqgisserver/qgscache/observer.py +210 -0
- pyqgisserver/qgscache/observers/ban.py +62 -0
- pyqgisserver/qgscache/observers/test.py +27 -0
- pyqgisserver/qgscache/types.py +18 -0
- pyqgisserver/qgspool.py +302 -0
- pyqgisserver/qgsworker.py +639 -0
- pyqgisserver/runtime.py +331 -0
- pyqgisserver/server.py +171 -0
- pyqgisserver/stats.py +34 -0
- pyqgisserver/tests.py +207 -0
- pyqgisserver/utils/__init__.py +0 -0
- pyqgisserver/utils/decorators.py +86 -0
- pyqgisserver/utils/lru.py +124 -0
- pyqgisserver/utils/qgis.py +190 -0
- pyqgisserver/utils/stats.py +30 -0
- pyqgisserver/version.py +30 -0
- pyqgisserver/zeromq/__init__.py +0 -0
- pyqgisserver/zeromq/broker.py +208 -0
- pyqgisserver/zeromq/client.py +267 -0
- pyqgisserver/zeromq/messages.py +27 -0
- pyqgisserver/zeromq/pool.py +138 -0
- pyqgisserver/zeromq/supervisor.py +174 -0
- pyqgisserver/zeromq/utils.py +10 -0
- pyqgisserver/zeromq/worker.py +272 -0
- pyqgisservercontrib/__init__.py +0 -0
- pyqgisservercontrib/core/__init__.py +0 -0
- pyqgisservercontrib/core/componentmanager.py +170 -0
- pyqgisservercontrib/core/filters.py +96 -0
- pyqgisservercontrib/core/watchfiles.py +56 -0
- pyqgisservercontrib/middlewares/__init__.py +0 -0
- pyqgisservercontrib/middlewares/request_logger.py +66 -0
- pyqgisservercontrib/py.typed +0 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: py-qgis-server
|
|
3
|
+
Version: 1.9.8
|
|
4
|
+
Summary: Py-Qgis-Server is an OWS/OGC server built on top of QGIS Server implementation
|
|
5
|
+
Author: 3Liz
|
|
6
|
+
Author-email: 3Liz <david.marteau@3liz.com>
|
|
7
|
+
Classifier: Environment :: Web Environment
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
18
|
+
Requires-Dist: tornado>=5
|
|
19
|
+
Requires-Dist: pyzmq>=17
|
|
20
|
+
Requires-Dist: pyyaml
|
|
21
|
+
Requires-Dist: typing-extensions
|
|
22
|
+
Requires-Dist: psutil
|
|
23
|
+
Maintainer: David Marteau
|
|
24
|
+
Maintainer-email: David Marteau <david.marteau@3liz.com>
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Project-URL: Homepage, https://github.com/3liz/py-qgis-server
|
|
27
|
+
Project-URL: Repository, https://github.com/3liz/py-qgis-server.git
|
|
28
|
+
Project-URL: Documentation, https://docs.3liz.org/py-qgis-server
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# QGIS embedded WMS/WFS/WCS asynchronous scalable server
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
> [!NOTE]
|
|
35
|
+
> Check [QJazz](https://github.com/3liz/qjazz) the new platform for QGIS embedded services.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
[](https://pypi.org/project/py-qgis-server/)
|
|
39
|
+
[](https://pypi.org/project/py-qgis-server/)
|
|
40
|
+
[](https://pypi.org/project/py-qgis-server/)
|
|
41
|
+
[](https://hub.docker.com/r/3liz/qgis-map-server/tags)
|
|
42
|
+
|
|
43
|
+
## Description
|
|
44
|
+
|
|
45
|
+
This is an asynchronous HTTP QGIS server written in python on top of the [tornado](http://www.tornadoweb.org/en/stable/) framework and the
|
|
46
|
+
0MQ messaging framework for distributing requests workers.
|
|
47
|
+
|
|
48
|
+
It is based on the QGIS 3 server API for efficiently passing requests/responses using 0MQ messaging framework to workers.
|
|
49
|
+
|
|
50
|
+
The server may run as a self-contained single service or as a proxy server with an arbitrary number of workers running
|
|
51
|
+
remotely or locally. Independent workers connect automatically to the front-end proxy with no need of special configuration
|
|
52
|
+
on the proxy side. Thus, this is ideal for auto-scaling configuration for use with container orchestrator as Rancher, Swarm or Kubernetes.
|
|
53
|
+
|
|
54
|
+
The server is aimed at solving some real situations encountered in production environment: zero conf scalability, handle long-running request situation, auto restart...
|
|
55
|
+
|
|
56
|
+
Py-Qgis-server is constantly tested against QGIS release and ltr version.
|
|
57
|
+
See the QGIS [roadmap](https://www.qgis.org/en/site/getinvolved/development/roadmap.html#release-schedule).
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
|
|
61
|
+
- Multiples workers
|
|
62
|
+
- Fair queuing request dispatching
|
|
63
|
+
- Timeout for long-running/stalled requests
|
|
64
|
+
- Full support of qgis server plugins
|
|
65
|
+
- Auto-restart trigger for workers
|
|
66
|
+
- Support streamed/chunked responses
|
|
67
|
+
- SSL support
|
|
68
|
+
- Support for access control extensions
|
|
69
|
+
- Support for Qgis project stored in postgres database
|
|
70
|
+
- Support adding new projects cache handlers as python extension
|
|
71
|
+
- Preloading of Qgis projects in static cache
|
|
72
|
+
- WFS3 support
|
|
73
|
+
- Control exposition of [Qgis API](https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/server.html#custom-apis)
|
|
74
|
+
- Management API (experimental)
|
|
75
|
+
|
|
76
|
+
## Requirements:
|
|
77
|
+
|
|
78
|
+
- OS: Unix/Posix variants (Linux or OSX) (Windows not officially supported)
|
|
79
|
+
- Python >= 3.10
|
|
80
|
+
- Qgis >= 3.34
|
|
81
|
+
- Some python knowledge about python virtualenv and package installation.
|
|
82
|
+
- libzmq >= 4.0.1 and pyzmq >= 17
|
|
83
|
+
|
|
84
|
+
## Documentation:
|
|
85
|
+
|
|
86
|
+
Latest documentation is available on [docs.3liz.org](https://docs.3liz.org/py-qgis-server/)
|
|
87
|
+
|
|
88
|
+
## Installation
|
|
89
|
+
|
|
90
|
+
### From Pypi
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install py-qgis-server
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### From docker
|
|
97
|
+
|
|
98
|
+
Docker is the recommended way to deploy py-qgis-server as it ensure a working environment for
|
|
99
|
+
running py-qgis-server
|
|
100
|
+
|
|
101
|
+
Follow the readme in the [docker/](./docker) folder.
|
|
102
|
+
|
|
103
|
+
### From source
|
|
104
|
+
|
|
105
|
+
Install in development mode
|
|
106
|
+
```bash
|
|
107
|
+
pip install -e .
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Running the server
|
|
111
|
+
|
|
112
|
+
The server does not run as a daemon by itself, there are several ways to run a command as a daemon.
|
|
113
|
+
|
|
114
|
+
For example:
|
|
115
|
+
|
|
116
|
+
* Use Supervisor http://supervisord.org/. Will gives you full control over logs and server status notifications.
|
|
117
|
+
* Use the `daemon` command.
|
|
118
|
+
* Use systemd
|
|
119
|
+
* ...
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
### Running the server
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
usage: qgisserver [-h] [-d] [-c [PATH]]
|
|
126
|
+
[--version] [-p PORT] [-b IP] [-w NUM] [-j NUM] [-u SETUID]
|
|
127
|
+
[--rootdir PATH] [--proxy] [--timeout SECONDS]
|
|
128
|
+
|
|
129
|
+
qgis/HTTP/0MQ scalable server
|
|
130
|
+
|
|
131
|
+
optional arguments:
|
|
132
|
+
-h, --help show this help message and exit
|
|
133
|
+
-d, --debug debug mode
|
|
134
|
+
-c [PATH], --config [PATH]
|
|
135
|
+
Configuration file
|
|
136
|
+
--version Return version number and exit
|
|
137
|
+
-p PORT, --port PORT http port
|
|
138
|
+
-b IP, --bind IP Interface to bind to
|
|
139
|
+
-w NUM, --workers NUM
|
|
140
|
+
Num workers
|
|
141
|
+
-j NUM, --jobs NUM Num server instances
|
|
142
|
+
-u SETUID, --setuid SETUID
|
|
143
|
+
uid to switch to
|
|
144
|
+
--rootdir PATH Path to qgis projects
|
|
145
|
+
--proxy Run only as proxy
|
|
146
|
+
--timeout SECONDS Set client timeout in seconds
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
By default, the command will run server instances with workers and use unix sockets to communicate. This can
|
|
150
|
+
be used to run the server as a single command.
|
|
151
|
+
|
|
152
|
+
#### Running proxy and workers separately
|
|
153
|
+
|
|
154
|
+
If the `--proxy` option the server will act as a proxy server to talk to independent qgis workers.
|
|
155
|
+
|
|
156
|
+
Qgis workers can be run using the command:
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
qgisserver-worker --host=localhost --rootdir=path/to/projects
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
### Requests to OWS services
|
|
164
|
+
|
|
165
|
+
The OWS requests use the following format: `/ows/?<ows_query_params>`
|
|
166
|
+
|
|
167
|
+
Example:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
http://myserver:8080/ows/?SERVICE=WFS&VERSION=1.1.0&REQUEST=GetCapabilities&MAP=<qgis_project_spec>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Requests to WFS3 OAPI
|
|
174
|
+
|
|
175
|
+
The requests use the following format: `/wfs3/<wfs3_api_endpoint>?MAP=<qgis_project_spec>`
|
|
176
|
+
|
|
177
|
+
Example:
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
http://myserver:8080/wfs3/collections.html?MAP=<qgis_project_spec>
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Accessing the Qgis landing page and other qgis API
|
|
184
|
+
|
|
185
|
+
By default, the landing page is not enabled, see the
|
|
186
|
+
[documentation](https://docs.3liz.org/py-qgis-server/configuration.html#api-enabled-landing-page) on how to enable the landing page.
|
|
187
|
+
|
|
188
|
+
Qgis api may be exposed on demand by [configuring the api endpoints](https://docs.3liz.org/py-qgis-server/qgisapi.html)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
#### Using with lizmap
|
|
192
|
+
|
|
193
|
+
In order to use the server with lizmap, you must set the following configuration
|
|
194
|
+
in your `lizmapConfig.ini.php`:
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
[services]
|
|
198
|
+
wmsServerURL="http://my.domain:<port>/ows/"
|
|
199
|
+
...
|
|
200
|
+
|
|
201
|
+
; Use relative path
|
|
202
|
+
relativeWMSPath=true
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Configuration
|
|
206
|
+
|
|
207
|
+
The configuration can be done either as configuration .ini file in or as environment variables.
|
|
208
|
+
|
|
209
|
+
The precedences of the configuration parameters is the following (from lowest to highest)
|
|
210
|
+
|
|
211
|
+
- Defaults values
|
|
212
|
+
- Environment variables
|
|
213
|
+
- Config file
|
|
214
|
+
- Command line options
|
|
215
|
+
|
|
216
|
+
#### Configuration parameters
|
|
217
|
+
|
|
218
|
+
Please look at [the documentation](https://docs.3liz.org/py-qgis-server/index.html) for configuration options
|
|
219
|
+
|
|
220
|
+
## Logging
|
|
221
|
+
|
|
222
|
+
By default, the server log on stdout/stderr and you have to configure redirection and log rotation
|
|
223
|
+
on your infrastructure environment
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
pyqgisserver/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
pyqgisserver/build.manifest,sha256=RR5fytzJ_n9xrt1o7uH-RkLao_CgSZDi-LxE-YHSuP8,72
|
|
3
|
+
pyqgisserver/config.py,sha256=s1nWy50r7TsfzHQX4bvZIGgGH6Avzi7qt5_435hb7rY,13240
|
|
4
|
+
pyqgisserver/config.yml,sha256=loUtXxU4cWMUYrEWeLhXOh1Y0tOQc0gy9FXm6ZvRg20,13910
|
|
5
|
+
pyqgisserver/handlers/__init__.py,sha256=e4QQaCfMTXpRIvcUIXfKCyQNbmMuJnQvikpBsGHaQ3U,313
|
|
6
|
+
pyqgisserver/handlers/asynchandler.py,sha256=AluQ7HVsZkulmx6kHnWQy3128a46WkNEUohtyBmtzdo,7196
|
|
7
|
+
pyqgisserver/handlers/basehandler.py,sha256=rqS6uxDUVr-RVc-chEmGnER1N9Lmn9ZTogTvtI_2794,6084
|
|
8
|
+
pyqgisserver/handlers/landingpage.py,sha256=KsKuMslT6Uvy0pID8BuJCPnaFP4zoy4nIw-lsayBgGU,2169
|
|
9
|
+
pyqgisserver/handlers/oapihandler.py,sha256=q93oOA2jqyUgFLtjf3XQOveYm1lulwBjGOzcU7_IvU8,1595
|
|
10
|
+
pyqgisserver/handlers/owshandler.py,sha256=JNwKQA2tpu-6dlmIQFSVecESppcRHwWOcIWOp9BSWYg,2417
|
|
11
|
+
pyqgisserver/handlers/statushandler.py,sha256=M1ND5AkcM6yyOAVUke7syOAfa6U6q4zHYxu7JvgzBvI,2558
|
|
12
|
+
pyqgisserver/logger.py,sha256=okzlYrcs2O1779K5nVWVMJ4G4LKTrz8h3Pb3d1P6vFQ,3833
|
|
13
|
+
pyqgisserver/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
pyqgisserver/management/apis/__init__.py,sha256=PbFaoW8AFEQqP6CUINpgAUWVbG-CTuualpKEtxm-sc4,440
|
|
15
|
+
pyqgisserver/management/apis/cache.py,sha256=u65Rr5yiXNMKkbnW-5XFmK-LuWVK43bWYUKP3Ozx4yo,1448
|
|
16
|
+
pyqgisserver/management/apis/handler.py,sha256=TnFblHnrf1fDiE6y0Dg5C8iou9vqtFqKWN6uJ7lPMHQ,7173
|
|
17
|
+
pyqgisserver/management/apis/plugins.py,sha256=1PC3AjLueenYLpq_z_T90-xVLBXl9IQBGam0oUt3UBQ,2041
|
|
18
|
+
pyqgisserver/management/server.py,sha256=unnIHSt8Fk0NPQ4xkWifrwTFPAzYGKK2fDO8rVdefjM,6455
|
|
19
|
+
pyqgisserver/middleware.py,sha256=cLm5V7ZKOKEHB74pjeRnD5RkjDQm4bOVJkGjCglXHBY,2780
|
|
20
|
+
pyqgisserver/monitor.py,sha256=msGnwPCdSiy7CAdav4tGA7AR5ie5QDQnHm695fGkkpI,885
|
|
21
|
+
pyqgisserver/monitors/amqp.py,sha256=y45gZ6UpuTgc3E3zTn6LXEsHNgXfoAIhjSx7MNt6yaE,4409
|
|
22
|
+
pyqgisserver/monitors/base.py,sha256=0qfI_qjrU2ayBIsCdXxg39uawYjGSZJTtIr0SRD3leg,839
|
|
23
|
+
pyqgisserver/monitors/test.py,sha256=gl4g0znQtUNMQuk68j0E-Gi7_PHVGdB5CI3McBgIDVw,892
|
|
24
|
+
pyqgisserver/plugins.py,sha256=lXAz-HujLJFuHxeelX0ryy-fahpdMdoC438zsiXAnTQ,5061
|
|
25
|
+
pyqgisserver/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
|
+
pyqgisserver/qgscache/__init__.py,sha256=UzXKu1MCw-_KOUgaUtMkdFVw986DwQHoAzaS_p3MxWg,39
|
|
27
|
+
pyqgisserver/qgscache/cachemanager.py,sha256=6dB0km6xjPpfKrzqMKJ4Qs7l8sYIfkYhqRyErn3qxPk,19140
|
|
28
|
+
pyqgisserver/qgscache/handlers/__init__.py,sha256=qcmORKdeqMoIUls65e9u4lFsIQCP2FnPmnWO4mNLZNQ,431
|
|
29
|
+
pyqgisserver/qgscache/handlers/file_handler.py,sha256=q-gVFdql8WNmBavDGSb9_ULeGilz4vQn0KEUrBYpddQ,2637
|
|
30
|
+
pyqgisserver/qgscache/handlers/postgres_handler.py,sha256=7o8LRw_HIgqIdR4ciGIpRxQd9OJlAv36D2XXkGxdM8g,5621
|
|
31
|
+
pyqgisserver/qgscache/handlers/proto.py,sha256=xm0uXFPM6qmcMLdeqqc8sUQnt1IzA3qc95VgZvX1u3s,673
|
|
32
|
+
pyqgisserver/qgscache/observer.py,sha256=HmyTC6pvrH9aDC2kQVTT2siw7G2CWNdC9wXD9Z4P-_k,6221
|
|
33
|
+
pyqgisserver/qgscache/observers/ban.py,sha256=RsosgCa10z6-lFl2byOqevnvCDF-r0oelpsLO8zbp7o,1725
|
|
34
|
+
pyqgisserver/qgscache/observers/test.py,sha256=UmvP8ZIVvogXYw-3DTYNE-u8bHZ2weQNxMCvXHOL_4E,676
|
|
35
|
+
pyqgisserver/qgscache/types.py,sha256=HrKmh2E9ltlpfxZYQhEtRAMp1zzH57cRlvhaunAeKLo,383
|
|
36
|
+
pyqgisserver/qgspool.py,sha256=zPciH8GMdRYGBhAC5EMLaEc-Fg3S_OhHj3i_vuZP-Zk,8875
|
|
37
|
+
pyqgisserver/qgsworker.py,sha256=wQV6FprSU9K-XfmEV3HzZ4mxdnkA3tIoJJgpNi8Ba90,22169
|
|
38
|
+
pyqgisserver/runtime.py,sha256=oQdVeLkJg_bq5bectRWnvEMwb6Ctddrr4n3ySK9CZiA,9645
|
|
39
|
+
pyqgisserver/server.py,sha256=fjWcDC31Iueb2AGFJ9cEKNNHVLqHoqnm-CMW7nuofUk,4147
|
|
40
|
+
pyqgisserver/stats.py,sha256=jEJomlnG8rqSxBMNJNtdzBohtouV9WPXT8jMnDFCTxI,880
|
|
41
|
+
pyqgisserver/tests.py,sha256=USk9Ked1hn4BRSWQHneYewQrTxZxd-UP21EN7ZbYiyE,5134
|
|
42
|
+
pyqgisserver/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
|
+
pyqgisserver/utils/decorators.py,sha256=7Q4_PdMD7uSPDKgEju-aP3Scd0WylmLmlSqBRHtBL8s,2550
|
|
44
|
+
pyqgisserver/utils/lru.py,sha256=Rj5xLAAo2iz7cH_cpu46SClEQT0w2BNdQ4Zt3Py6-SU,3636
|
|
45
|
+
pyqgisserver/utils/qgis.py,sha256=mFQS1z4FXOmZhxxItFI4hgNUZRdCXlpSiAA3CTOu92I,5745
|
|
46
|
+
pyqgisserver/utils/stats.py,sha256=Or31WfHKyJMbOxA4Kg-GywgezTctgTe6Wz2QDMpC-vE,807
|
|
47
|
+
pyqgisserver/version.py,sha256=vcNzdwv-hOp6-NJvUT2vg_SRZJAmIQ_CqKTOM-2HdXA,911
|
|
48
|
+
pyqgisserver/zeromq/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
49
|
+
pyqgisserver/zeromq/broker.py,sha256=rDrqCdAokwC21jqx6jqBOdDZ4szZqPLdDsXkKI5krus,7333
|
|
50
|
+
pyqgisserver/zeromq/client.py,sha256=jLg322d4DUV_RCzb0kbS6NCrXbxgBhyqsSytMK9GtBk,9217
|
|
51
|
+
pyqgisserver/zeromq/messages.py,sha256=29W--97D55jMNnJUmcTbbcl0B7eyedxGsLyKAqwXi8g,603
|
|
52
|
+
pyqgisserver/zeromq/pool.py,sha256=i2stFdZDphCV3j0c7QRpF_EXZvxXD7ptpUrwbw_aydQ,4071
|
|
53
|
+
pyqgisserver/zeromq/supervisor.py,sha256=08CaASmHSR4niaR5QLJ82OX9eyxbgG07GaorkjTXOGE,4623
|
|
54
|
+
pyqgisserver/zeromq/utils.py,sha256=pV92sUiFK_SPjTb0jS9jviccc3R6MpaUkeNTYcHrJVM,296
|
|
55
|
+
pyqgisserver/zeromq/worker.py,sha256=4cH565w8lqtrJmpLbsIhcmeLe00oNm3YFb46KvirYXY,8578
|
|
56
|
+
pyqgisservercontrib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
57
|
+
pyqgisservercontrib/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
58
|
+
pyqgisservercontrib/core/componentmanager.py,sha256=sc-jpScYtemUiJ-4pu2bF1IBNTK4LZCeg2ZP-0fKsHw,5097
|
|
59
|
+
pyqgisservercontrib/core/filters.py,sha256=wonN0-2FM_DNk6yh_xCnacsWyTFywEnLpIDYobXDdM8,2676
|
|
60
|
+
pyqgisservercontrib/core/watchfiles.py,sha256=WbdXp3I8Us0-qyHMsynqLSDinWDKW2mGjB8w0dvF1KI,1598
|
|
61
|
+
pyqgisservercontrib/middlewares/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
62
|
+
pyqgisservercontrib/middlewares/request_logger.py,sha256=Mik_j5cTChn5JlLywPsLVcnXnCcbBYEQVBDoKIuzMtA,1571
|
|
63
|
+
pyqgisservercontrib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
64
|
+
py_qgis_server-1.9.8.dist-info/WHEEL,sha256=3OmCxFA0ffBIsX4x0o8CdfSvZAOvO3mzEG8U_z5TvV4,80
|
|
65
|
+
py_qgis_server-1.9.8.dist-info/entry_points.txt,sha256=pDXONMarmKmIoGw1gkOwDBy18VnvWT9xaXWw7LNpoGo,441
|
|
66
|
+
py_qgis_server-1.9.8.dist-info/METADATA,sha256=W9-NvMmt6xKrxpGB012PnGZurwcoZ92QapHWvpl-Qy0,7443
|
|
67
|
+
py_qgis_server-1.9.8.dist-info/RECORD,,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[console_scripts]
|
|
2
|
+
qgisserver = pyqgisserver.server:main
|
|
3
|
+
qgisserver-worker = pyqgisserver.qgsworker:main
|
|
4
|
+
|
|
5
|
+
[py_qgis_server.access_policy]
|
|
6
|
+
request_logger = pyqgisservercontrib.middlewares.request_logger:register_filters
|
|
7
|
+
|
|
8
|
+
[py_qgis_server.cache.observers]
|
|
9
|
+
ban = pyqgisserver.qgscache.observers.ban
|
|
10
|
+
test = pyqgisserver.qgscache.observers.test
|
|
11
|
+
|
|
12
|
+
[py_qgis_server.monitors]
|
|
13
|
+
amqp = pyqgisserver.monitors.amqp:Monitor
|
|
14
|
+
test = pyqgisserver.monitors.test
|
|
15
|
+
|
pyqgisserver/__init__.py
ADDED
|
File without changes
|
pyqgisserver/config.py
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2018 3liz
|
|
3
|
+
# Author David Marteau
|
|
4
|
+
#
|
|
5
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
6
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
7
|
+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
8
|
+
|
|
9
|
+
""" Configuration management
|
|
10
|
+
|
|
11
|
+
Configuration can be done either by using aconfiguration file or with environnement variable.
|
|
12
|
+
|
|
13
|
+
Except stated otherwise, the rule for environnement variable names is ``QGSRV_<SECTION>_<KEY>`` all in uppercase.
|
|
14
|
+
|
|
15
|
+
Options
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import configparser
|
|
21
|
+
import contextlib
|
|
22
|
+
import functools
|
|
23
|
+
import logging
|
|
24
|
+
import os
|
|
25
|
+
|
|
26
|
+
from typing_extensions import (
|
|
27
|
+
TYPE_CHECKING,
|
|
28
|
+
Callable,
|
|
29
|
+
Iterator,
|
|
30
|
+
Literal,
|
|
31
|
+
Tuple,
|
|
32
|
+
TypeAlias,
|
|
33
|
+
Union,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
from pyqgisservercontrib.core import componentmanager
|
|
37
|
+
|
|
38
|
+
ConfigValue: TypeAlias = Union[str, bool, int, float]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
getenv = os.getenv
|
|
42
|
+
|
|
43
|
+
LOGGER = logging.getLogger('SRVLOG')
|
|
44
|
+
|
|
45
|
+
CONFIG = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
|
|
46
|
+
# Preserve case
|
|
47
|
+
CONFIG.optionxform = lambda opt: opt # type: ignore [assignment]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def getenv2(env1, env2, default):
|
|
51
|
+
""" Get value from alternate env variable
|
|
52
|
+
"""
|
|
53
|
+
return getenv(env1, getenv(env2, default))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def print_config(fp):
|
|
57
|
+
""" print configuration to file
|
|
58
|
+
"""
|
|
59
|
+
CONFIG.write(fp)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def load_configuration():
|
|
63
|
+
""" Read configuration file
|
|
64
|
+
|
|
65
|
+
Load server configuration from configuration file.
|
|
66
|
+
"""
|
|
67
|
+
CONFIG.clear()
|
|
68
|
+
|
|
69
|
+
LOGGER.info('loading configuration')
|
|
70
|
+
|
|
71
|
+
CONFIG.add_section('server')
|
|
72
|
+
CONFIG.set('server', 'port', getenv('QGSRV_SERVER_HTTP_PORT', '8080'))
|
|
73
|
+
CONFIG.set('server', 'interfaces', getenv('QGSRV_SERVER_INTERFACES', '0.0.0.0'))
|
|
74
|
+
CONFIG.set('server', 'workers', getenv('QGSRV_SERVER_WORKERS', '2'))
|
|
75
|
+
CONFIG.set('server', 'timeout', getenv('QGSRV_SERVER_TIMEOUT', '20'))
|
|
76
|
+
CONFIG.set('server', 'enable_filters', getenv('QGSRV_SERVER_ENABLE_FILTERS', 'no'))
|
|
77
|
+
CONFIG.set('server', 'http_proxy', getenv('QGSRV_SERVER_HTTP_PROXY', 'no'))
|
|
78
|
+
CONFIG.set('server', 'proxy_url', getenv('QGSRV_SERVER_PROXY_URL', ''))
|
|
79
|
+
CONFIG.set('server', 'restartmon', getenv('QGSRV_SERVER_RESTARTMON', ''))
|
|
80
|
+
CONFIG.set('server', 'ssl', getenv('QGSRV_SERVER_SSL', 'no'))
|
|
81
|
+
CONFIG.set('server', 'ssl_cert', getenv('QGSRV_SERVER_SSL_CERT', ''))
|
|
82
|
+
CONFIG.set('server', 'ssl_key', getenv('QGSRV_SERVER_SSL_KEY', ''))
|
|
83
|
+
CONFIG.set('server', 'cross_origin', getenv('QGSRV_SERVER_CROSS_ORIGIN', 'yes'))
|
|
84
|
+
CONFIG.set('server', 'status_page', getenv('QGSRV_SERVER_STATUS_PAGE', 'no'))
|
|
85
|
+
CONFIG.set('server', 'allow_headers', getenv('QGSRV_SERVER_ALLOW_HEADERS', 'X-Qgis-,X-Lizmap-'))
|
|
86
|
+
CONFIG.set('server', 'memory_high_water_mark',
|
|
87
|
+
getenv('QGSRV_SERVER_MEMORY_HIGH_WATER_MARK', '0.9'))
|
|
88
|
+
CONFIG.set('server', 'getfeaturelimit', getenv('QGSRV_SERVER_GETFEATURELIMIT', '-1'))
|
|
89
|
+
CONFIG.set('server', 'pluginpath',
|
|
90
|
+
getenv2('QGSRV_SERVER_PLUGINPATH', 'QGIS_PLUGINPATH', ''))
|
|
91
|
+
CONFIG.set('server', 'debug_request_id', getenv('QGSRV_SERVER_DEBUG_REQUEST_ID', '*'))
|
|
92
|
+
#
|
|
93
|
+
# Logging
|
|
94
|
+
#
|
|
95
|
+
CONFIG.add_section('logging')
|
|
96
|
+
CONFIG.set('logging', 'level', getenv('QGSRV_LOGGING_LEVEL', 'INFO'))
|
|
97
|
+
CONFIG.set('logging', 'qgis_info', getenv('QGSRV_LOGGING_QGIS_INFO', 'no'))
|
|
98
|
+
|
|
99
|
+
#
|
|
100
|
+
# Api configuration
|
|
101
|
+
#
|
|
102
|
+
|
|
103
|
+
# Qgis api endpoints
|
|
104
|
+
#
|
|
105
|
+
# Note that landing is not available since 3.28 packaging
|
|
106
|
+
# See https://github.com/qgis/QGIS/issues/55462
|
|
107
|
+
#
|
|
108
|
+
CONFIG.add_section('api.endpoints')
|
|
109
|
+
CONFIG.set('api.endpoints', 'landing_page', getenv('QGSRV_API_ENDPOINTS_LANDING_PAGE', '/catalog'))
|
|
110
|
+
CONFIG.set('api.endpoints', 'lizmap_api', getenv('QGSRV_API_ENDPOINTS_LIZMAP', '/lizmap'))
|
|
111
|
+
|
|
112
|
+
# Services enabled
|
|
113
|
+
CONFIG.add_section('api.enabled')
|
|
114
|
+
CONFIG.set('api.enabled', 'landing_page', getenv('QGSRV_API_ENABLED_LANDING_PAGE', 'no'))
|
|
115
|
+
CONFIG.set('api.enabled', 'lizmap_api', getenv('QGSRV_API_ENABLED_LIZMAP', 'no'))
|
|
116
|
+
|
|
117
|
+
# Landing page config mapping
|
|
118
|
+
CONFIG.add_section('api:landing_page')
|
|
119
|
+
CONFIG.set('api:landing_page', 'QGIS_SERVER_LANDING_PAGE_PREFIX',
|
|
120
|
+
'${api.endpoints:landing_page}')
|
|
121
|
+
CONFIG.set('api:landing_page', 'QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES',
|
|
122
|
+
'${projects.cache:rootdir}')
|
|
123
|
+
|
|
124
|
+
#
|
|
125
|
+
# Projects cache
|
|
126
|
+
#
|
|
127
|
+
CONFIG.add_section('projects.cache')
|
|
128
|
+
CONFIG.set('projects.cache', 'size', getenv('QGSRV_CACHE_SIZE', '10'))
|
|
129
|
+
CONFIG.set('projects.cache', 'rootdir', getenv('QGSRV_CACHE_ROOTDIR', ''))
|
|
130
|
+
CONFIG.set('projects.cache', 'strict_check', getenv('QGSRV_CACHE_STRICT_CHECK', 'yes'))
|
|
131
|
+
CONFIG.set('projects.cache', 'insecure', getenv('QGSRV_CACHE_INSECURE', 'no'))
|
|
132
|
+
CONFIG.set('projects.cache', 'preload_config', getenv('QGSRV_CACHE_PRELOAD_CONFIG', ''))
|
|
133
|
+
# Use same variable name as Qgis server options
|
|
134
|
+
CONFIG.set('projects.cache', 'trust_layer_metadata',
|
|
135
|
+
getenv2('QGSRV_TRUST_LAYER_METADATA', 'QGIS_SERVER_TRUST_LAYER_METADATA', 'no'))
|
|
136
|
+
CONFIG.set('projects.cache', 'disable_getprint',
|
|
137
|
+
getenv2('QGSRV_DISABLE_GETPRINT', 'QGIS_SERVER_DISABLE_GETPRINT', 'no'))
|
|
138
|
+
CONFIG.set('projects.cache', 'disable_owsurls', getenv('QGSRV_CACHE_DISABLE_OWSURLS', 'no'))
|
|
139
|
+
CONFIG.set('projects.cache', 'force_etag', getenv('QGSRV_CACHE_FORCE_ETAG', 'no'))
|
|
140
|
+
CONFIG.set('projects.cache', 'default_handler', getenv('QGSRV_CACHE_DEFAULT_HANDLER', 'file'))
|
|
141
|
+
CONFIG.set('projects.cache', 'allow_storage_schemes', getenv('QGSRV_CACHE_ALLOW_STORAGE_SCHEMES', '*'))
|
|
142
|
+
CONFIG.set('projects.cache', 'check_interval', getenv('QGSRV_CACHE_CHECK_INTERVAL', '0'))
|
|
143
|
+
CONFIG.set('projects.cache', 'observers', getenv('QGSRV_CACHE_OBSERVERS', ''))
|
|
144
|
+
CONFIG.set('projects.cache', 'advanced_report', getenv('QGSRV_CACHE_ADVANCED_REPORT', 'no'))
|
|
145
|
+
|
|
146
|
+
# Map read/create options
|
|
147
|
+
CONFIG.set('projects.cache', 'force_readonly_layers', getenv('QGIS_SERVER_FORCE_READONLY_LAYERS', 'yes'))
|
|
148
|
+
|
|
149
|
+
#
|
|
150
|
+
CONFIG.add_section('projects.schemes')
|
|
151
|
+
|
|
152
|
+
#
|
|
153
|
+
CONFIG.add_section('zmq')
|
|
154
|
+
# Identity prefix used in 0MQ worker socket
|
|
155
|
+
CONFIG.set('zmq', 'identity', getenv('QGSRV_ZMQ_IDENTITY', 'OWS-SERVER'))
|
|
156
|
+
# Control the maximum lenghth of the waiting queue
|
|
157
|
+
CONFIG.set('zmq', 'maxqueue', getenv('QGSRV_ZMQ_MAXQUEUE', '1000'))
|
|
158
|
+
# Control the lifetime of requests on the waiting queue
|
|
159
|
+
CONFIG.set('zmq', 'timeout', getenv('QGSRV_ZMQ_TIMEOUT', '15000'))
|
|
160
|
+
# Host Address to bind/connect 0MQ sockets - used only with proxy/worker configuration
|
|
161
|
+
CONFIG.set('zmq', 'hostaddr', getenv('QGSRV_ZMQ_HOSTADDR', '*'))
|
|
162
|
+
# Address to bind 0MQ socket - used only with proxy/worker configuration
|
|
163
|
+
CONFIG.set('zmq', 'bindaddr', getenv('QGSRV_ZMQ_INADDR', 'tcp://${zmq:hostaddr}:18080'))
|
|
164
|
+
# Address to bind broadcast address to - used only with proxy/worker configuration
|
|
165
|
+
CONFIG.set('zmq', 'broadcastaddr', getenv('QGSRV_ZMQ_BROADCASTADDR', 'tcp://${zmq:hostaddr}:18090'))
|
|
166
|
+
# Address to bind cache observer - used only with proxy/worker configuration
|
|
167
|
+
CONFIG.set('zmq', 'cache_observer_addr', getenv('QGSRV_ZMQ_CACHEOBSERVERADDR', 'tcp://${zmq:hostaddr}:18091'))
|
|
168
|
+
|
|
169
|
+
#
|
|
170
|
+
# Monitoring (AMQP)
|
|
171
|
+
#
|
|
172
|
+
CONFIG.add_section('monitor:amqp')
|
|
173
|
+
CONFIG.set('monitor:amqp', 'routing_key', getenv('AMQP_ROUTING', ''))
|
|
174
|
+
CONFIG.set('monitor:amqp', 'host', getenv('AMQP_HOST', 'amqp'))
|
|
175
|
+
CONFIG.set('monitor:amqp', 'user', getenv('AMQP_USER', ''))
|
|
176
|
+
CONFIG.set('monitor:amqp', 'vhost', getenv('AMQP_VHOST', '/'))
|
|
177
|
+
CONFIG.set('monitor:amqp', 'port', getenv('AMQP_PORT', '5672'))
|
|
178
|
+
CONFIG.set('monitor:amqp', 'exchange', getenv('AMQP_EXCHANGE', 'qgis_log'))
|
|
179
|
+
# Beware that a too small reconnect delay
|
|
180
|
+
# may prevent other asynchronous tasks to run
|
|
181
|
+
CONFIG.set('monitor:amqp', 'reconnect_delay', getenv('AMQP_RECONNECT_DELAY', '5'))
|
|
182
|
+
|
|
183
|
+
#
|
|
184
|
+
# Management
|
|
185
|
+
#
|
|
186
|
+
CONFIG.add_section('management')
|
|
187
|
+
CONFIG.set('management', 'enabled', getenv('QGSRV_MANAGEMENT_ENABLED', 'no'))
|
|
188
|
+
CONFIG.set('management', 'interfaces', getenv('QGSRV_MANAGEMENT_INTERFACES', '127.0.0.1'))
|
|
189
|
+
CONFIG.set('management', 'ssl', getenv('QGSRV_MANAGEMENT_SSL', 'no'))
|
|
190
|
+
CONFIG.set('management', 'ss_key', getenv('QGSRV_MANAGEMENT_SSL_KEY', ''))
|
|
191
|
+
CONFIG.set('management', 'ssl_cert', getenv('QGSRV_MANAGEMENT_SSL_CERT', ''))
|
|
192
|
+
CONFIG.set('management', 'port', getenv('QGSRV_MANAGEMENT_PORT', '19876'))
|
|
193
|
+
|
|
194
|
+
#
|
|
195
|
+
# Metadata
|
|
196
|
+
#
|
|
197
|
+
CONFIG.add_section('metadata')
|
|
198
|
+
CONFIG.set('metadata', 'contact_name', '3liz')
|
|
199
|
+
CONFIG.set('metadata', 'contact_address', '')
|
|
200
|
+
CONFIG.set('metadata', 'contact_email', 'info@3liz.com')
|
|
201
|
+
CONFIG.set('metadata', 'contact_url', 'https://www.3liz.com/')
|
|
202
|
+
CONFIG.set('metadata', 'licence_url', 'http://mozilla.org/MPL/2.0/')
|
|
203
|
+
CONFIG.set('metadata', 'licence_name', 'Mozilla Public Licences, v2.0')
|
|
204
|
+
CONFIG.set('metadata', 'external_doc_description', 'Py-qgis-server documentation')
|
|
205
|
+
CONFIG.set('metadata', 'external_doc_url', 'https://docs.3liz.org/py-qgis-server/')
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def read_config_file(cfgfile):
|
|
209
|
+
""" Read configuration from file
|
|
210
|
+
"""
|
|
211
|
+
CONFIG.read_file(cfgfile)
|
|
212
|
+
LOGGER.info('Configuration file <%s> loaded', cfgfile)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def config_to_dict():
|
|
216
|
+
""" Convert actual configuration to dictionary
|
|
217
|
+
"""
|
|
218
|
+
return {s: dict(p.items()) for s, p in CONFIG.items()}
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def validate_config_path(confname, confid, optional=False):
|
|
222
|
+
""" Validate directory path
|
|
223
|
+
"""
|
|
224
|
+
confvalue = CONFIG[confname].get(confid, '')
|
|
225
|
+
|
|
226
|
+
if not confvalue and optional:
|
|
227
|
+
return
|
|
228
|
+
|
|
229
|
+
confvalue = os.path.normpath(confvalue)
|
|
230
|
+
if not os.path.isdir(confvalue):
|
|
231
|
+
LOGGER.error(f'server->{confid} configuration value {confvalue} is not directory')
|
|
232
|
+
raise ValueError(confvalue)
|
|
233
|
+
|
|
234
|
+
if not os.path.isabs(confvalue):
|
|
235
|
+
LOGGER.error(f'server->{confid} configuration value {confvalue} is not absolute path')
|
|
236
|
+
raise ValueError(confvalue)
|
|
237
|
+
|
|
238
|
+
CONFIG.set(confname, confid, confvalue)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def configure_qgis_api(name: str):
|
|
242
|
+
""" Configure qgis service environnement variables
|
|
243
|
+
"""
|
|
244
|
+
section = f"api:{name}"
|
|
245
|
+
if not CONFIG.has_section(section):
|
|
246
|
+
return
|
|
247
|
+
|
|
248
|
+
config = CONFIG[section]
|
|
249
|
+
for k, v in config.items():
|
|
250
|
+
LOGGER.debug("configuring qgis api '%s': %s = %s", name, k, v)
|
|
251
|
+
os.environ[k] = v
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def qgis_api_endpoints(enabled_only: bool = True) -> Iterator[Tuple[str, str]]:
|
|
255
|
+
""" Return the list of enabled services
|
|
256
|
+
"""
|
|
257
|
+
endpoints = CONFIG["api.endpoints"]
|
|
258
|
+
enabled = CONFIG["api.enabled"]
|
|
259
|
+
items: Iterator = ((name, endpoint) for name, endpoint in endpoints.items())
|
|
260
|
+
if enabled_only:
|
|
261
|
+
items = filter(lambda item: enabled.getboolean(item[0]), items)
|
|
262
|
+
return items
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
#
|
|
266
|
+
# Published services
|
|
267
|
+
#
|
|
268
|
+
|
|
269
|
+
NO_DEFAULT = object()
|
|
270
|
+
|
|
271
|
+
NO_DEFAULT_TYPE = Literal[NO_DEFAULT] # type: ignore [valid-type]
|
|
272
|
+
|
|
273
|
+
# Chars that are to be replaced in env variable name
|
|
274
|
+
ENV_REPLACE_CHARS = ':.-@#$%&*'
|
|
275
|
+
|
|
276
|
+
if TYPE_CHECKING:
|
|
277
|
+
from mypy_extensions import DefaultNamedArg
|
|
278
|
+
ConfigValueGetter = Callable[
|
|
279
|
+
[str, str, DefaultNamedArg(Union[str, NO_DEFAULT_TYPE], 'fallback')],
|
|
280
|
+
ConfigValue,
|
|
281
|
+
]
|
|
282
|
+
else:
|
|
283
|
+
ConfigValueGetter = Callable[[str, str, Union[str, NO_DEFAULT_TYPE]], ConfigValue]
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
@componentmanager.register_factory('@3liz.org/config-service;1')
|
|
287
|
+
class ConfigService:
|
|
288
|
+
""" Act as a proxy
|
|
289
|
+
"""
|
|
290
|
+
|
|
291
|
+
def __init__(self):
|
|
292
|
+
self.allow_env = True
|
|
293
|
+
|
|
294
|
+
def __get_impl(
|
|
295
|
+
self,
|
|
296
|
+
_get_fun: ConfigValueGetter,
|
|
297
|
+
section: str,
|
|
298
|
+
option: str,
|
|
299
|
+
fallback: Union[ConfigValue, NO_DEFAULT_TYPE] = NO_DEFAULT,
|
|
300
|
+
) -> ConfigValue:
|
|
301
|
+
"""
|
|
302
|
+
"""
|
|
303
|
+
value = _get_fun(section, option, fallback=NO_DEFAULT)
|
|
304
|
+
if value is NO_DEFAULT:
|
|
305
|
+
# Look in environment
|
|
306
|
+
# Note that the section must exists
|
|
307
|
+
if self.allow_env:
|
|
308
|
+
LOGGER.debug("Looking for option '%s.%s' in environment", section, option)
|
|
309
|
+
varname = f'QGSRV_{section.upper()}_{option.upper()}'
|
|
310
|
+
varname = functools.reduce(lambda s, c: s.replace(c, '_'), ENV_REPLACE_CHARS, varname)
|
|
311
|
+
varvalue = os.getenv(varname)
|
|
312
|
+
if varvalue is not None:
|
|
313
|
+
LOGGER.debug("Setting config value from %s", varname)
|
|
314
|
+
CONFIG.set(section, option, varvalue)
|
|
315
|
+
# Let config parser translate the value for us
|
|
316
|
+
value = _get_fun(section, option, fallback=fallback)
|
|
317
|
+
else:
|
|
318
|
+
value = fallback
|
|
319
|
+
if value is NO_DEFAULT:
|
|
320
|
+
raise KeyError(f'[{section}] {option}')
|
|
321
|
+
return value
|
|
322
|
+
|
|
323
|
+
get = functools.partialmethod(__get_impl, CONFIG.get)
|
|
324
|
+
getint = functools.partialmethod(__get_impl, CONFIG.getint)
|
|
325
|
+
getboolean = functools.partialmethod(__get_impl, CONFIG.getboolean)
|
|
326
|
+
getfloat = functools.partialmethod(__get_impl, CONFIG.getfloat)
|
|
327
|
+
|
|
328
|
+
def __getitem__(self, section):
|
|
329
|
+
return CONFIG[section]
|
|
330
|
+
|
|
331
|
+
def __contains__(self, section):
|
|
332
|
+
return section in CONFIG
|
|
333
|
+
|
|
334
|
+
def set(self, section: str, option: str, value: str):
|
|
335
|
+
CONFIG.set(section, option, value)
|
|
336
|
+
|
|
337
|
+
def add_section(self, sectionname: str):
|
|
338
|
+
# We do not care if the section already exists
|
|
339
|
+
with contextlib.suppress(configparser.DuplicateSectionError):
|
|
340
|
+
CONFIG.add_section(sectionname)
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
confservice = ConfigService()
|