Skip to content

Commit

Permalink
Improve secret fields detection.
Browse files Browse the repository at this point in the history
Now the `_flags` fields must have a corresponding field without
`_flags` suffix.
Fixes several fields which were not secret but mark as is.
  • Loading branch information
igo95862 committed Dec 20, 2022
1 parent 07507e8 commit 82b6f23
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
4 changes: 1 addition & 3 deletions sdbus_async/networkmanager/settings/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
# if possible, please make changes by also updating the script.
from __future__ import annotations
from dataclasses import dataclass, field
from typing import ClassVar, List, Optional
from typing import List, Optional
from .base import NetworkManagerSettingsMixin


@dataclass
class ConnectionSettings(NetworkManagerSettingsMixin):
"""General Connection Profile Settings"""
secret_fields_names: ClassVar[List[str]] = ['mptcp']
secret_name = 'connection'

auth_retries: Optional[int] = field(
metadata={
Expand Down
2 changes: 1 addition & 1 deletion sdbus_async/networkmanager/settings/dcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@dataclass
class DcbSettings(NetworkManagerSettingsMixin):
"""Data Center Bridging Settings"""
secret_fields_names: ClassVar[List[str]] = ['app_fcoe', 'app_fip', 'app_iscsi', 'priority_flow_control', 'priority_group']
secret_fields_names: ClassVar[List[str]] = ['priority_flow_control']
secret_name = 'dcb'

app_fcoe_flags: Optional[int] = field(
Expand Down
2 changes: 1 addition & 1 deletion sdbus_async/networkmanager/settings/eapol.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@dataclass
class EapolSettings(NetworkManagerSettingsMixin):
"""IEEE 802.1x Authentication Settings"""
secret_fields_names: ClassVar[List[str]] = ['ca_cert_password', 'client_cert_password', 'password', 'password_raw', 'phase1_auth', 'phase2_ca_cert_password', 'phase2_client_cert_password', 'phase2_private_key_password', 'pin', 'private_key_password']
secret_fields_names: ClassVar[List[str]] = ['ca_cert_password', 'client_cert_password', 'password', 'password_raw', 'phase2_ca_cert_password', 'phase2_client_cert_password', 'phase2_private_key_password', 'pin', 'private_key_password']
secret_name = '802-1x'

altsubject_matches: Optional[List[str]] = field(
Expand Down
2 changes: 1 addition & 1 deletion sdbus_async/networkmanager/settings/wireless_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@dataclass
class WirelessSecuritySettings(NetworkManagerSettingsMixin):
"""Wi-Fi Security Settings"""
secret_fields_names: ClassVar[List[str]] = ['leap_password', 'psk', 'wep_key']
secret_fields_names: ClassVar[List[str]] = ['leap_password', 'psk']
secret_name = '802-11-wireless-security'

auth_alg: Optional[str] = field(
Expand Down
18 changes: 12 additions & 6 deletions tools/generate-settings-dataclasses-jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from typing import List, Optional, Set
from xml.etree.ElementTree import Element, parse

from jinja2 import Environment, FileSystemLoader
from jinja2 import Environment, FileSystemLoader, StrictUndefined

dbus_to_python_extra_typing_imports = {
"as": ("List", ),
Expand Down Expand Up @@ -150,7 +150,7 @@ def __init__(self, name: str, description: str, name_upper: str,
self.properties: List[NmSettingPropertyIntrospection] = []

@cached_property
def typing_imports(self) -> List[str]:
def typing_imports(self) -> Set[str]:
typing_imports: Set[str] = self.properties_want_imports.copy()

if self.secret_fields:
Expand Down Expand Up @@ -198,14 +198,19 @@ def is_optional_setting(self) -> bool:
return True

@cached_property
def secret_fields(self) -> List[str]:
secret_fields: List[str] = []
def secret_fields(self) -> Set[str]:
all_fields: Set[str] = set()
possible_secret_fields: Set[str] = set()

for x in self.properties:

if x.python_name.endswith('_flags') and x.python_type == 'int':
secret_fields.append(x.python_name.removesuffix('_flags'))
possible_secret_fields.add(
x.python_name.removesuffix('_flags'))
else:
all_fields.add(x.python_name)

return secret_fields
return all_fields.intersection(possible_secret_fields)


def extract_docbook_paragraphs(docbook_node: Element) -> List[str]:
Expand Down Expand Up @@ -307,6 +312,7 @@ def main(
) -> None:
jinja_env = Environment(
loader=FileSystemLoader(Path('./tools/jinja_templates/')),
undefined=StrictUndefined,
)
settings_template = jinja_env.get_template('setting.py.jinja2')

Expand Down

0 comments on commit 82b6f23

Please sign in to comment.