Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sonar/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ def reload(self, data: types.ApiPayload) -> None:
elif self.key == COMPONENT_VISIBILITY:
self.value = data.get("visibility", None)
elif self.key == "sonar.login.message":
self.value: Optional[Any] = None
self.value = None
if "values" in data and isinstance(data["values"], list) and len(data["values"]) > 0:
self.value = data["values"][0]
else:
self.value = next((data[key] for key in ("fieldValues", "values", "value") if key in data), None)
self.value = util.convert_to_type(next((data[key] for key in ("fieldValues", "values", "value") if key in data), None))
if not self.value and "defaultValue" in data:
self.value = util.DEFAULT
self.__reload_inheritance(data)
Expand Down
8 changes: 7 additions & 1 deletion sonar/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ def redacted_token(token: str) -> str:
return re.sub(r"(..).*(..)", r"\1***\2", token)


def convert_to_type(value: Any) -> Any:
def convert_to_type(value: str) -> Any:
"""Converts a potentially string value to the corresponding int or float"""
if not isinstance(value, str):
return value
try:
return int(value)
except ValueError:
Expand All @@ -169,6 +171,10 @@ def convert_to_type(value: Any) -> Any:
return float(value)
except ValueError:
pass
try:
return bool(value)
except ValueError:
pass
return value


Expand Down