Skip to content

Commit

Permalink
Rename UpdaterConfig attributes
Browse files Browse the repository at this point in the history
Since configuration constants are now part of a
config class, make them lower case. This also avoids
pylint's invalid-name error for class attributes.

Remove the 'default' prefix as they are now configurable
options.

Signed-off-by: Teodora Sechkova <[email protected]>
  • Loading branch information
sechkova committed Jul 6, 2021
1 parent a50e76d commit 520b344
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions tuf/ngclient/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

@dataclass
class UpdaterConfig:
MAX_ROOT_ROTATIONS: int = 32
MAX_DELEGATIONS: int = 32
DEFAULT_ROOT_MAX_LENGTH: int = 512000 # bytes
DEFAULT_TIMESTAMP_MAX_LENGTH: int = 16384 # bytes
DEFAULT_SNAPSHOT_MAX_LENGTH: int = 2000000 # bytes
DEFAULT_TARGETS_MAX_LENGTH: int = 5000000 # bytes
max_root_rotations: int = 32
max_delegations: int = 32
root_max_length: int = 512000 # bytes
timestamp_max_length: int = 16384 # bytes
snapshot_max_length: int = 2000000 # bytes
targets_max_length: int = 5000000 # bytes
14 changes: 7 additions & 7 deletions tuf/ngclient/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ def _load_root(self) -> None:

# Update the root role
lower_bound = self._trusted_set.root.signed.version + 1
upper_bound = lower_bound + self.config.MAX_ROOT_ROTATIONS
upper_bound = lower_bound + self.config.max_root_rotations

for next_version in range(lower_bound, upper_bound):
try:
data = self._download_metadata(
"root", self.config.DEFAULT_ROOT_MAX_LENGTH, next_version
"root", self.config.root_max_length, next_version
)
self._trusted_set.update_root(data)
self._persist_metadata("root", data)
Expand All @@ -277,7 +277,7 @@ def _load_timestamp(self) -> None:

# Load from remote (whether local load succeeded or not)
data = self._download_metadata(
"timestamp", self.config.DEFAULT_TIMESTAMP_MAX_LENGTH
"timestamp", self.config.timestamp_max_length
)
self._trusted_set.update_timestamp(data)
self._persist_metadata("timestamp", data)
Expand All @@ -293,7 +293,7 @@ def _load_snapshot(self) -> None:
logger.debug("Failed to load local snapshot %s", e)

metainfo = self._trusted_set.timestamp.signed.meta["snapshot.json"]
length = metainfo.length or self.config.DEFAULT_SNAPSHOT_MAX_LENGTH
length = metainfo.length or self.config.snapshot_max_length
version = None
if self._trusted_set.root.signed.consistent_snapshot:
version = metainfo.version
Expand All @@ -313,7 +313,7 @@ def _load_targets(self, role: str, parent_role: str) -> None:
logger.debug("Failed to load local %s: %s", role, e)

metainfo = self._trusted_set.snapshot.signed.meta[f"{role}.json"]
length = metainfo.length or self.config.DEFAULT_TARGETS_MAX_LENGTH
length = metainfo.length or self.config.targets_max_length
version = None
if self._trusted_set.root.signed.consistent_snapshot:
version = metainfo.version
Expand All @@ -332,7 +332,7 @@ def _preorder_depth_first_walk(self, target_filepath) -> Dict:
target = None
role_names = [("targets", "root")]
visited_role_names = set()
number_of_delegations = self.config.MAX_DELEGATIONS
number_of_delegations = self.config.max_delegations

# Preorder depth-first traversal of the graph of target delegations.
while (
Expand Down Expand Up @@ -413,7 +413,7 @@ def _preorder_depth_first_walk(self, target_filepath) -> Dict:
):
msg = (
f"{len(role_names)} roles left to visit, but allowed to ",
f"visit at most {self.config.MAX_DELEGATIONS} delegations.",
f"visit at most {self.config.max_delegations} delegations.",
)
logger.debug(msg)

Expand Down

0 comments on commit 520b344

Please sign in to comment.