Skip to content

Commit 520b344

Browse files
committed
Rename UpdaterConfig attributes
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]>
1 parent a50e76d commit 520b344

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

tuf/ngclient/config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
@dataclass
1111
class UpdaterConfig:
12-
MAX_ROOT_ROTATIONS: int = 32
13-
MAX_DELEGATIONS: int = 32
14-
DEFAULT_ROOT_MAX_LENGTH: int = 512000 # bytes
15-
DEFAULT_TIMESTAMP_MAX_LENGTH: int = 16384 # bytes
16-
DEFAULT_SNAPSHOT_MAX_LENGTH: int = 2000000 # bytes
17-
DEFAULT_TARGETS_MAX_LENGTH: int = 5000000 # bytes
12+
max_root_rotations: int = 32
13+
max_delegations: int = 32
14+
root_max_length: int = 512000 # bytes
15+
timestamp_max_length: int = 16384 # bytes
16+
snapshot_max_length: int = 2000000 # bytes
17+
targets_max_length: int = 5000000 # bytes

tuf/ngclient/updater.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ def _load_root(self) -> None:
247247

248248
# Update the root role
249249
lower_bound = self._trusted_set.root.signed.version + 1
250-
upper_bound = lower_bound + self.config.MAX_ROOT_ROTATIONS
250+
upper_bound = lower_bound + self.config.max_root_rotations
251251

252252
for next_version in range(lower_bound, upper_bound):
253253
try:
254254
data = self._download_metadata(
255-
"root", self.config.DEFAULT_ROOT_MAX_LENGTH, next_version
255+
"root", self.config.root_max_length, next_version
256256
)
257257
self._trusted_set.update_root(data)
258258
self._persist_metadata("root", data)
@@ -277,7 +277,7 @@ def _load_timestamp(self) -> None:
277277

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

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

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

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

0 commit comments

Comments
 (0)