Skip to content

Commit

Permalink
Raise keystore error when key not found in keystore directory. Added …
Browse files Browse the repository at this point in the history
…is_test_repo property
  • Loading branch information
renatav committed Apr 6, 2021
1 parent c68939a commit 3247558
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions taf/auth_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def certs_dir(self):
certs_dir.mkdir(parents=True, exist_ok=True)
return str(certs_dir)

@property
def is_test_repo(self):
return Path(self.path, self.targets_path, self.TEST_REPO_FLAG_FILE).is_file()

@property
def last_validated_commit(self):
"""
Expand Down
20 changes: 12 additions & 8 deletions taf/repository_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
TimestampMetadataUpdateError,
YubikeyError,
InvalidRepositoryError,
KeystoreError
)
from taf.git import GitRepository
from taf.utils import normalize_file_line_endings, on_rm_error
Expand Down Expand Up @@ -97,14 +98,17 @@ def load_role_key(keystore, role, password=None, scheme=DEFAULT_RSA_SIGNATURE_SC
password = None
key = role_keys_cache.get(role)
if key is None:
if password is not None:
key = import_rsa_privatekey_from_file(
str(Path(keystore, role)), password, scheme=scheme
)
else:
key = import_rsa_privatekey_from_file(
str(Path(keystore, role)), scheme=scheme
)
try:
if password is not None:
key = import_rsa_privatekey_from_file(
str(Path(keystore, role)), password, scheme=scheme
)
else:
key = import_rsa_privatekey_from_file(
str(Path(keystore, role)), scheme=scheme
)
except FileNotFoundError:
raise KeystoreError(f"Cannot find {role} key in {keystore}")
if not DISABLE_KEYS_CACHING:
role_keys_cache[role] = key
return key
Expand Down

0 comments on commit 3247558

Please sign in to comment.