Skip to content

Commit b4b272d

Browse files
authored
Merge pull request #729 from rldhont/fix-security-scan
Fix security scan
2 parents f98b072 + 1c74f9c commit b4b272d

71 files changed

Lines changed: 921 additions & 867 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ on:
1313
jobs:
1414
tests:
1515
uses: ./.github/workflows/tests.yml
16-

.github/workflows/tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ jobs:
2525
run: ruff check --preview --output-format=concise lizmap
2626

2727
- name: Run security check
28-
run: bandit -r lizmap --severity-level=high
28+
run: bandit -r lizmap -ll
29+
30+
- name: Run Detect Secrets
31+
run: detect-secrets scan lizmap --all-files
2932

3033
tests:
3134
runs-on: ubuntu-latest
@@ -44,5 +47,3 @@ jobs:
4447

4548
- name: Running tests
4649
run: make docker-test QGIS_VERSION=${{ matrix.qgis_version }}
47-
48-

lizmap/config/config.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
from __future__ import annotations
2+
13
import json
24
import os
35

46
from typing import (
7+
TYPE_CHECKING,
58
Any,
6-
Dict,
7-
Mapping,
8-
Optional,
9-
Sequence,
109
)
1110

1211
from qgis.core import QgsMapLayer, QgsProject
@@ -15,6 +14,9 @@
1514
from .layer_options import layerOptionDefinitions
1615
from .models import MappingQgisGeometryType
1716

17+
if TYPE_CHECKING:
18+
from collections.abc import Mapping, Sequence
19+
1820

1921
class LizmapConfigError(Exception):
2022
pass
@@ -34,9 +36,9 @@ def __init__(self, project: QgsProject):
3436

3537
self._WFSLayers = self.project.readListEntry("WFSLayers", "")[0]
3638

37-
self._layer_attributes: Dict = {}
38-
self._global_options: Dict = {}
39-
self._layer_options: Dict = {}
39+
self._layer_attributes: dict = {}
40+
self._global_options: dict = {}
41+
self._layer_options: dict = {}
4042

4143
@staticmethod
4244
def _load_project(path):
@@ -48,7 +50,7 @@ def _load_project(path):
4850
raise LizmapConfigError("Error reading qgis project")
4951
return project
5052

51-
def get_layer_by_name(self, name: str) -> Optional[QgsMapLayer]:
53+
def get_layer_by_name(self, name: str) -> QgsMapLayer | None:
5254
"""Return a unique layer by its name"""
5355
matches = self.project.mapLayersByName(name)
5456
if len(matches) > 0:
@@ -57,9 +59,9 @@ def get_layer_by_name(self, name: str) -> Optional[QgsMapLayer]:
5759

5860
def to_json(
5961
self,
60-
p_global_options: Optional[Mapping[str, Any]] = None,
61-
p_layer_options: Optional[Mapping[str, Any]] = None,
62-
p_attributes_options: Optional[Mapping[str, Any]] = None,
62+
p_global_options: Mapping[str, Any] | None = None,
63+
p_layer_options: Mapping[str, Any] | None = None,
64+
p_attributes_options: Mapping[str, Any] | None = None,
6365
sort_keys: bool = False,
6466
indent: int = 4,
6567
**kwargs,
@@ -86,7 +88,7 @@ def to_json(
8688
# Write json to the cfg file
8789
return json.dumps(config, sort_keys=sort_keys, indent=indent, **kwargs)
8890

89-
def set_global_options(self, options: Optional[Mapping[str, Any]] = None):
91+
def set_global_options(self, options: Mapping[str, Any] | None = None):
9092
"""Set the global lizmap configuration options"""
9193
# set defaults
9294
self._global_options = {
@@ -171,7 +173,7 @@ def add_layer(self, layer: QgsMapLayer, **options) -> Mapping[str, Any]:
171173
self._layer_options[lid] = lo
172174
return lo
173175

174-
def set_layer_options(self, p_layer_options: Optional[Mapping[str, Any]] = None):
176+
def set_layer_options(self, p_layer_options: Mapping[str, Any] | None = None):
175177
"""Set the configuration options for the the project layers
176178
177179
:param p_layer_options: dict of options for each layers
@@ -207,7 +209,7 @@ def publish_layer_attribute_table(
207209

208210
# Check that the layer has WFS enabled
209211
if not self.hasWFSCapabilities(layer):
210-
raise LizmapConfigError("WFS Required for layer %s" % layer.name())
212+
raise LizmapConfigError(f"WFS Required for layer {layer.name()}")
211213

212214
lyr_name = layer.name()
213215
lyr_attrs = self._layer_attributes.get(lyr_name)
@@ -249,10 +251,10 @@ def set_wmsextent(self, xmin: float, ymin: float, xmax: float, ymax: float):
249251
# noinspection PyPep8Naming
250252
def configure_server_options(
251253
self,
252-
WMSTitle: Optional[str] = None,
253-
WMSDescription: Optional[str] = None,
254+
WMSTitle: str | None = None,
255+
WMSDescription: str | None = None,
254256
WFSLayersPrecision: int = 6,
255-
WMSExtent: Optional[Sequence[int]] = None,
257+
WMSExtent: Sequence[int] | None = None,
256258
):
257259
"""Configure server options for layers in the qgis project
258260

lizmap/config/global_options.py

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,79 +6,79 @@
66
from lizmap.toolbelt.i18n import tr
77
from lizmap.toolbelt.version import format_version_integer, version
88

9-
from .models import _Item
9+
from .models import ModelItem
1010

1111

1212
class Metadata(TypedDict):
13-
lizmap_plugin_version: _Item
14-
lizmap_web_client_target_version: _Item
13+
lizmap_plugin_version: ModelItem
14+
lizmap_web_client_target_version: ModelItem
1515

1616

1717
class GlobalOptionsDefinitions(TypedDict):
1818
metadata: Metadata
19-
mapScales: _Item
20-
minScale: _Item
21-
max_scale_points: _Item
22-
max_scale_lines_polygons: _Item
23-
use_native_zoom_levels: _Item
24-
hide_numeric_scale_value: _Item
25-
acl: _Item
26-
initialExtent: _Item
27-
googleKey: _Item
28-
googleHybrid: _Item
29-
googleSatellite: _Item
30-
googleTerrain: _Item
31-
googleStreets: _Item
32-
osmMapnik: _Item
33-
openTopoMap: _Item
34-
bingKey: _Item
35-
bingStreets: _Item
36-
bingSatellite: _Item
37-
bingHybrid: _Item
38-
ignKey: _Item
39-
ignSatellite: _Item
40-
ignTerrain: _Item
41-
ignCadastral: _Item
42-
hideGroupCheckbox: _Item
43-
activateFirstMapTheme: _Item
44-
popupLocation: _Item
45-
draw: _Item
19+
mapScales: ModelItem
20+
minScale: ModelItem
21+
max_scale_points: ModelItem
22+
max_scale_lines_polygons: ModelItem
23+
use_native_zoom_levels: ModelItem
24+
hide_numeric_scale_value: ModelItem
25+
acl: ModelItem
26+
initialExtent: ModelItem
27+
googleKey: ModelItem
28+
googleHybrid: ModelItem
29+
googleSatellite: ModelItem
30+
googleTerrain: ModelItem
31+
googleStreets: ModelItem
32+
osmMapnik: ModelItem
33+
openTopoMap: ModelItem
34+
bingKey: ModelItem
35+
bingStreets: ModelItem
36+
bingSatellite: ModelItem
37+
bingHybrid: ModelItem
38+
ignKey: ModelItem
39+
ignSatellite: ModelItem
40+
ignTerrain: ModelItem
41+
ignCadastral: ModelItem
42+
hideGroupCheckbox: ModelItem
43+
activateFirstMapTheme: ModelItem
44+
popupLocation: ModelItem
45+
draw: ModelItem
4646
# Deprecated since LWC 3.7.0
4747
# There is a new "print" panel
48-
print: _Item
49-
measure: _Item
50-
externalSearch: _Item
48+
print: ModelItem
49+
measure: ModelItem
50+
externalSearch: ModelItem
5151
# Deprecated, it has been removed in LWC 3.8
52-
zoomHistory: _Item
53-
geolocation: _Item
54-
geolocationPrecision: _Item
55-
geolocationDirection: _Item
56-
pointTolerance: _Item
57-
lineTolerance: _Item
58-
polygonTolerance: _Item
59-
hideHeader: _Item
60-
hideMenu: _Item
61-
hideLegend: _Item
62-
hideOverview: _Item
63-
hideNavbar: _Item
64-
hideProject: _Item
65-
automatic_permalink: _Item
66-
wms_single_request_for_all_layers: _Item
67-
exclude_basemaps_from_single_wms: _Item
68-
tmTimeFrameSize: _Item
69-
tmTimeFrameType: _Item
70-
tmAnimationFrameLength: _Item
71-
emptyBaselayer: _Item
72-
startupBaselayer: _Item
73-
limitDataToBbox: _Item
74-
datavizLocation: _Item
75-
datavizTemplate: _Item
76-
theme: _Item
77-
atlasShowAtStartup: _Item
78-
atlasAutoPlay: _Item
79-
fixed_scale_overview_map: _Item
80-
dxfExportEnabled: _Item
81-
allowedGroups: _Item
52+
zoomHistory: ModelItem
53+
geolocation: ModelItem
54+
geolocationPrecision: ModelItem
55+
geolocationDirection: ModelItem
56+
pointTolerance: ModelItem
57+
lineTolerance: ModelItem
58+
polygonTolerance: ModelItem
59+
hideHeader: ModelItem
60+
hideMenu: ModelItem
61+
hideLegend: ModelItem
62+
hideOverview: ModelItem
63+
hideNavbar: ModelItem
64+
hideProject: ModelItem
65+
automatic_permalink: ModelItem
66+
wms_single_request_for_all_layers: ModelItem
67+
exclude_basemaps_from_single_wms: ModelItem
68+
tmTimeFrameSize: ModelItem
69+
tmTimeFrameType: ModelItem
70+
tmAnimationFrameLength: ModelItem
71+
emptyBaselayer: ModelItem
72+
startupBaselayer: ModelItem
73+
limitDataToBbox: ModelItem
74+
datavizLocation: ModelItem
75+
datavizTemplate: ModelItem
76+
theme: ModelItem
77+
atlasShowAtStartup: ModelItem
78+
atlasAutoPlay: ModelItem
79+
fixed_scale_overview_map: ModelItem
80+
dxfExportEnabled: ModelItem
81+
allowedGroups: ModelItem
8282

8383

8484
globalOptionDefinitions = {
@@ -91,7 +91,7 @@ class GlobalOptionsDefinitions(TypedDict):
9191
"lizmap_web_client_target_version": {
9292
"wType": "spinbox",
9393
"type": "integer",
94-
"default": format_version_integer("{}.0".format(LwcVersions.latest().value)),
94+
"default": format_version_integer(f"{LwcVersions.latest().value}.0"),
9595
},
9696
},
9797
"mapScales": {

lizmap/config/layer_options.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,40 @@
55
from lizmap.definitions.definitions import LwcVersions
66
from lizmap.toolbelt.i18n import tr
77

8-
from .models import _Item
8+
from .models import ModelItem
99

1010

1111
class LayerOptionDefinitions(TypedDict):
12-
title: _Item
13-
abstract: _Item
14-
link: _Item
15-
minScale: _Item
16-
maxScale: _Item
17-
toggled: _Item
18-
popup: _Item
19-
popupFrame: _Item
20-
popupSource: _Item
21-
popupTemplate: _Item
22-
popupMaxFeatures: _Item
23-
children_lizmap_features_table: _Item
24-
popupDisplayChildren: _Item
25-
popup_allow_download: _Item
26-
noLegendImage: _Item
27-
legend_image_option: _Item
28-
groupAsLayer: _Item
29-
baseLayer: _Item
30-
displayInLegend: _Item
31-
group_visibility: _Item
32-
singleTile: _Item
33-
imageFormat: _Item
34-
cached: _Item
35-
serverFrame: _Item
36-
cacheExpiration: _Item
37-
metatileSize: _Item
38-
clientCacheExpiration: _Item
39-
externalWmsToggle: _Item
40-
sourceRepository: _Item
41-
sourceProject: _Item
12+
title: ModelItem
13+
abstract: ModelItem
14+
link: ModelItem
15+
minScale: ModelItem
16+
maxScale: ModelItem
17+
toggled: ModelItem
18+
popup: ModelItem
19+
popupFrame: ModelItem
20+
popupSource: ModelItem
21+
popupTemplate: ModelItem
22+
popupMaxFeatures: ModelItem
23+
children_lizmap_features_table: ModelItem
24+
popupDisplayChildren: ModelItem
25+
popup_allow_download: ModelItem
26+
noLegendImage: ModelItem
27+
legend_image_option: ModelItem
28+
groupAsLayer: ModelItem
29+
baseLayer: ModelItem
30+
displayInLegend: ModelItem
31+
group_visibility: ModelItem
32+
singleTile: ModelItem
33+
imageFormat: ModelItem
34+
cached: ModelItem
35+
serverFrame: ModelItem
36+
cacheExpiration: ModelItem
37+
metatileSize: ModelItem
38+
clientCacheExpiration: ModelItem
39+
externalWmsToggle: ModelItem
40+
sourceRepository: ModelItem
41+
sourceProject: ModelItem
4242

4343

4444
layerOptionDefinitions = {

lizmap/config/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
from collections.abc import Sequence
12
from types import MappingProxyType
23
from typing import (
34
Any,
4-
Sequence,
55
TypedDict,
66
)
77

@@ -25,7 +25,7 @@
2525
)
2626

2727

28-
class _Item(TypedDict):
28+
class ModelItem(TypedDict):
2929
wType: str
3030
type: str
3131
default: Any

0 commit comments

Comments
 (0)