Skip to content

Commit f0b114a

Browse files
authored
Merge pull request #143 from Deltares/fix/DEI-261-Fix-sonar-qube-cloud-and-security-issues
Dei-261 fix sonar qube cloud and security issues
2 parents f54297c + e0046f2 commit f0b114a

23 files changed

Lines changed: 703 additions & 756 deletions

Dockerfile

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
FROM python:3.11-slim
2-
3-
LABEL org.opencontainers.image.source="https://github.com/Deltares/D-EcoImpact"
4-
5-
WORKDIR /decoimpact
6-
7-
# Copy files in local working directory to docker working directory
8-
COPY . .
9-
10-
# Update the package source list, update system packages
11-
RUN apt-get update && apt-get upgrade -y
12-
13-
# install poetry (/usr/local/bin/poetry)
14-
RUN pip install poetry
15-
16-
# Install Poetry dependencies without creating poetry environment
17-
## Packages are installed in "/usr/local/lib/python/site-packages/" when the environment is not created,
18-
## which corresponds to the local installation of Python "/usr/local/bin/python" in the base Docker image
19-
RUN poetry config virtualenvs.create false
20-
RUN poetry install
21-
RUN apt-get clean autoclean
1+
FROM python:3.11-slim
2+
3+
LABEL org.opencontainers.image.source="https://github.com/Deltares/D-EcoImpact"
4+
5+
WORKDIR /decoimpact
6+
7+
# Copy files in local working directory to docker working directory
8+
COPY . .
9+
10+
# Update the package source list, update system packages
11+
RUN apt-get update && apt-get upgrade -y \
12+
&& pip install poetry
13+
14+
# Install Poetry dependencies without creating poetry environment
15+
## Packages are installed in "/usr/local/lib/python/site-packages/" when the environment is not created,
16+
## which corresponds to the local installation of Python "/usr/local/bin/python" in the base Docker image
17+
RUN poetry config virtualenvs.create false \
18+
&& poetry install \
19+
&& apt-get clean autoclean
20+

decoimpact/business/entities/rule_processor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ def _process_by_cell(
251251
result_variable = _np.zeros_like(np_array)
252252

253253
# define variables to count value exceedings (for some rules): min and max
254-
warning_counter = [0, 0]
255254
warning_counter_total = [0, 0]
256255

257256
# execute rule and gather warnings for exceeded values (for some rules)
@@ -384,7 +383,7 @@ def _expand_dimensions_of_variable(
384383
# Let the user know which variables will be broadcast to all dimensions
385384
dims_orig = var_orig.dims
386385
dims_result = ref_var.dims
387-
dims_diff = list(str(x) for x in dims_result if x not in dims_orig)
386+
dims_diff = [str(x) for x in dims_result if x not in dims_orig]
388387
str_dims_broadcasted = ",".join(dims_diff)
389388
logger.log_info(
390389
f"""Variable {var_orig.name} will be expanded to the following \

decoimpact/business/entities/rules/formula_rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def validate(self, logger: ILogger) -> bool:
4848
filename="<inline code>",
4949
mode="exec",
5050
)
51-
local_variables = {name: 1.0 for name in self.input_variable_names}
51+
local_variables = dict.fromkeys(self.input_variable_names, 1.0)
5252
exec(byte_code, self._global_variables, local_variables)
5353

5454
except (SyntaxError, NameError) as exception:

decoimpact/business/entities/rules/time_operation_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(
2828
raise ValueError("The time_scale_mapping does not contain any values")
2929

3030
self._time_scale_mapping = time_scale_mapping
31-
self._time_scale = next(i for i in time_scale_mapping.keys())
31+
self._time_scale = next(iter(time_scale_mapping.keys()))
3232
self._operation_type = TimeOperationType.AVERAGE
3333
self._percentile_value = 0.0
3434

decoimpact/data/entities/data_access_layer.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,29 @@ def __create_yaml_loader(self):
213213

214214
loader = _yaml.FullLoader
215215
loader.add_constructor("!include", self.yaml_include_constructor)
216+
216217
# Add support for scientific notation (example 1e5=100000)
218+
# Define the YAML float tag and regex pattern for scientific notation
219+
float_decimal = r"[-+]?(?:\d[\d_]*)\.[0-9_]*(?:[eE][-+]?\d+)?"
220+
float_exponent = r"[-+]?(?:\d[\d_]*)(?:[eE][-+]?\d+)"
221+
float_leading_dot = r"\.[\d_]+(?:[eE][-+]\d+)?"
222+
float_time = r"[-+]?\d[\d_]*(?::[0-5]?\d)+\.[\d_]*"
223+
float_inf = r"[-+]?\.(?:inf|Inf|INF)"
224+
float_nan = r"\.(?:nan|NaN|NAN)"
225+
226+
float_regex_pattern = rf"""^(?:
227+
{float_decimal}
228+
|{float_exponent}
229+
|{float_leading_dot}
230+
|{float_time}
231+
|{float_inf}
232+
|{float_nan})$"""
233+
234+
float_regex = re.compile(float_regex_pattern, re.X)
235+
217236
loader.add_implicit_resolver(
218237
"tag:yaml.org,2002:float",
219-
re.compile(
220-
"""^(?:
221-
[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+]?[0-9]+)?
222-
|[-+]?(?:[0-9][0-9_]*)(?:[eE][-+]?[0-9]+)
223-
|\\.[0-9_]+(?:[eE][-+][0-9]+)?
224-
|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*
225-
|[-+]?\\.(?:inf|Inf|INF)
226-
|\\.(?:nan|NaN|NAN))$""",
227-
re.X,
228-
),
238+
float_regex,
229239
list("-+0123456789."),
230240
)
231241

decoimpact/data/parsers/parser_response_curve_rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def parse_dict(self, dictionary: Dict[str, Any], logger: ILogger) -> IRuleData:
4747
output_values = response_table["output"]
4848

4949
# check that response table has exactly two columns:
50-
if not len(response_table) == 2:
50+
if len(response_table) != 2:
5151
raise ValueError("ERROR: response table should have exactly 2 columns")
5252

5353
# validate input values to be int/float

decoimpact/data/parsers/validation_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def validate_start_before_end(start_list: List[str], end_list: List[str]):
7777
start_str = datetime.strptime(start, r"%d-%m")
7878
end_str = datetime.strptime(end, r"%d-%m").replace()
7979

80-
if not start_str < end_str:
80+
if start_str >= end_str:
8181
message = (
8282
f"All start dates should be before the end dates. "
8383
f"ERROR in position {index} where start: "

0 commit comments

Comments
 (0)