diff --git a/taf/auth_repo.py b/taf/auth_repo.py index 566a27ca..d5cf46dd 100644 --- a/taf/auth_repo.py +++ b/taf/auth_repo.py @@ -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, @@ -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 @@ -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 @@ -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 ( diff --git a/taf/tests/test_updater/conftest.py b/taf/tests/test_updater/conftest.py index 8bcc4da0..c3e77aeb 100644 --- a/taf/tests/test_updater/conftest.py +++ b/taf/tests/test_updater/conftest.py @@ -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