Skip to content

Commit

Permalink
chore: mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
renatav committed Dec 3, 2024
1 parent f726788 commit a1b7cf6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions taf/auth_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AuthenticationRepository(GitRepository, TAFRepository):

_conf_dir = None
_dependencies: Dict = {}
_last_validated_data = None
_last_validated_data: Optional[Dict] = None

def __init__(
self,
Expand Down Expand Up @@ -143,7 +143,8 @@ def last_validated_commit(self) -> Optional[str]:
Return the last validated commit of the authentication repository
"""
try:
return self.last_validated_data[self.LAST_VALIDATED_KEY]
if self.last_validated_data is not None:
return self.last_validated_data[self.LAST_VALIDATED_KEY]
except KeyError:
return None

Expand Down Expand Up @@ -293,13 +294,22 @@ def set_last_validated_data(
self._log_debug(f"setting last validated data to: {last_data_str}")
Path(self.conf_dir, self.LAST_VALIDATED_FILENAME).write_text(last_data_str)

def set_last_validated_of_repo(self, repo_name: str, commit: str):
def set_last_validated_of_repo(
self,
repo_name: str,
commit: str,
set_last_validated_commit: Optional[bool] = True,
):
last_validated_data = self.last_validated_data or {}
last_validated_data[repo_name] = commit
last_validated_data[self.LAST_VALIDATED_KEY] = commit
last_data_str = json.dumps(last_validated_data, indent=4)
self._log_debug(f"setting last validated data to: {last_data_str}")
Path(self.conf_dir, self.LAST_VALIDATED_DATA_FILENAME).write_text(last_data_str)
if set_last_validated_commit and self.name == repo_name:
last_validated_data[self.LAST_VALIDATED_KEY] = last_validated_data[
self.name
]
Path(self.conf_dir, self.LAST_VALIDATED_FILENAME).write_text(last_data_str)

def auth_repo_commits_after_repos_last_validated(
self, target_repos: List, last_validated_data
Expand Down Expand Up @@ -519,11 +529,11 @@ def targets_at_revisions(
targets_at_revision = targets_at_revision["signed"]["targets"]

for target_path in targets_at_revision:
# if there are older auth repo commtis corresponding to repositories
# if there are older auth repo commits corresponding to repositories
# that were not validated in the one or more previous updates
# skip the ones that were validated more recently
# when the last validated commit of a repo is reached
# the repo is addes to the repos_to_skip list
# the repo is added to the repos_to_skip list
if target_path in repos_to_skip:
continue
if (
Expand Down
2 changes: 1 addition & 1 deletion taf/tests/test_updater/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def remove_last_validated_commit(auth_repo: AuthenticationRepository):


def remove_last_validated_data(auth_repo: AuthenticationRepository):
Path(auth_repo.conf_dir, auth_repo.LAST_VALIDATED_DATA_FILENAME).unlink()
Path(auth_repo.conf_dir, auth_repo.LAST_VALIDATED_FILENAME).unlink()
assert not auth_repo.last_validated_data


Expand Down

0 comments on commit a1b7cf6

Please sign in to comment.