Skip to content

Commit

Permalink
fix, chore: typing fixes, minor keys generation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
renatav committed Sep 21, 2023
1 parent b12e91b commit 2877d37
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 130 deletions.
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy]
ignore_missing_imports = True
4 changes: 2 additions & 2 deletions taf/api/keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def generate_keys(keystore: str, roles_key_infos: str) -> None:
Returns:
None
"""
roles_key_infos, keystore = _initialize_roles_and_keystore(
roles_key_infos_dict, keystore = _initialize_roles_and_keystore(
roles_key_infos, keystore
)

roles_keys_data = from_dict(roles_key_infos, RolesKeysData)
roles_keys_data = from_dict(roles_key_infos_dict, RolesKeysData)
for role in RolesIterator(roles_keys_data.roles, include_delegations=False):
if not role.is_yubikey:
for key_num in range(role.number):
Expand Down
14 changes: 8 additions & 6 deletions taf/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ def check_expiration_dates(
Returns:
None
"""
path = Path(path)
taf_repo = Repository(path)

if start_date is None:
start_date = datetime.now()

expired_dict, will_expire_dict = taf_repo.check_roles_expiration_dates(
interval, start_date, excluded_roles
)

if expired_dict or will_expire_dict:
now = datetime.now()
print(
f"Given a {interval} day interval from today ({start_date.strftime('%Y-%m-%d')}):"
f"Given a {interval} day interval from ({start_date.strftime('%Y-%m-%d')}):"
)
for role, expiry_date in expired_dict.items():
delta = now - expiry_date
Expand Down Expand Up @@ -106,7 +108,7 @@ def update_metadata_expiration_date(
start_date = datetime.now()

taf_repo = Repository(path)
loaded_yubikeys = {}
loaded_yubikeys: Dict = {}
roles_to_update = []

if "root" in roles:
Expand Down Expand Up @@ -209,7 +211,7 @@ def update_snapshot_and_timestamp(
Returns:
None
"""
loaded_yubikeys = {}
loaded_yubikeys: Dict = {}

for role in ("snapshot", "timestamp"):
keystore_keys, yubikeys = load_signing_keys(
Expand Down Expand Up @@ -248,7 +250,7 @@ def update_target_metadata(
write: Optional[bool] = False,
scheme: Optional[str] = DEFAULT_RSA_SIGNATURE_SCHEME,
prompt_for_keys: Optional[bool] = False,
) -> None:
) -> bool:
"""Given dictionaries containing targets that should be added and targets that should
be removed, update and sign target metadata files and, if write is True, also
sign snapshot and timestamp.
Expand Down Expand Up @@ -283,7 +285,7 @@ def update_target_metadata(
return False

# update targets
loaded_yubikeys = {}
loaded_yubikeys: Dict = {}
for role, target_paths in roles_targets.items():
keystore_keys, yubikeys = load_signing_keys(
taf_repo,
Expand Down
26 changes: 15 additions & 11 deletions taf/api/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def add_dependency(
print(f"{path} is not a git repository!")
return
if library_dir is None:
library_dir = auth_repo.path.parent.parent
library_dir = str(auth_repo.path.parent.parent)

if dependency_path is not None:
dependency = GitRepository(path=dependency_path)
Expand Down Expand Up @@ -134,8 +134,8 @@ def add_dependency(
json.dumps(dependencies_json, indent=4)
)

removed_targets_data = {}
added_targets_data = {repositoriesdb.DEPENDENCIES_JSON_NAME: {}}
removed_targets_data: Dict = {}
added_targets_data: Dict = {repositoriesdb.DEPENDENCIES_JSON_NAME: {}}
update_target_metadata(
auth_repo,
added_targets_data,
Expand Down Expand Up @@ -193,23 +193,28 @@ def create_repository(
None
"""
auth_repo = AuthenticationRepository(path=path)
path = Path(path)

if not _check_if_can_create_repository(auth_repo):
return

roles_key_infos, keystore = _initialize_roles_and_keystore(
roles_key_infos_dict, keystore = _initialize_roles_and_keystore(
roles_key_infos, keystore
)

roles_keys_data = from_dict(roles_key_infos, RolesKeysData)
keystore_path = Path(keystore)
if not keystore_path.is_dir():
keystore_path.mkdir(parents=False)

roles_keys_data = from_dict(roles_key_infos_dict, RolesKeysData)
repository = create_new_repository(str(auth_repo.path))
signing_keys, verification_keys = load_sorted_keys_of_new_roles(
auth_repo=auth_repo,
roles=roles_keys_data.roles,
yubikeys_data=roles_keys_data.yubikeys,
keystore=keystore,
)
if signing_keys is None:
return
# set threshold and register keys of main roles
# we cannot do the same for the delegated roles until delegations are created
for role in RolesIterator(roles_keys_data.roles, include_delegations=False):
Expand Down Expand Up @@ -241,6 +246,7 @@ def create_repository(
commit=False,
taf_repo=taf_repository,
write=True,
no_commit_warning=True,
)
if not updated:
repository.writeall()
Expand Down Expand Up @@ -310,9 +316,7 @@ def _determine_out_of_band_data(
except TAFError:
raise TAFError("Specified out-of-band authentication commit does not exist")
if branch_name not in branches:
raise TAFError(
f"Commit {out_of_band_commit} not on branch {dependency.branch_name}"
)
raise TAFError(f"Commit {out_of_band_commit} not on branch {branch_name}")

if not is_branch_specified or not is_commit_specified:
if not click.confirm(
Expand Down Expand Up @@ -387,8 +391,8 @@ def remove_dependency(
json.dumps(dependencies_json, indent=4)
)

removed_targets_data = {}
added_targets_data = {repositoriesdb.DEPENDENCIES_JSON_NAME: {}}
removed_targets_data: Dict = {}
added_targets_data: Dict = {repositoriesdb.DEPENDENCIES_JSON_NAME: {}}
update_target_metadata(
auth_repo,
added_targets_data,
Expand Down
Loading

0 comments on commit 2877d37

Please sign in to comment.