Skip to content

Commit

Permalink
Add TOP_LEVEL_ROLES as a global variable
Browse files Browse the repository at this point in the history
Add TOP_LEVEL_ROLES as a global variable in roledb.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
  • Loading branch information
sechkova committed Jun 29, 2020
1 parent a69208c commit 6ae3ea6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tuf/client/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ def __init__(self, repository_name, repository_mirrors):

# Load current and previous metadata.
for metadata_set in ['current', 'previous']:
for metadata_role in ['root', 'targets', 'snapshot', 'timestamp']:
for metadata_role in tuf.roledb.TOP_LEVEL_ROLES:
self._load_metadata_from_file(metadata_set, metadata_role)

# Raise an exception if the repository is missing the required 'root'
Expand Down Expand Up @@ -2435,7 +2435,7 @@ def all_targets(self):
# all roles available on the repository.
delegated_targets = []
for role in tuf.roledb.get_rolenames(self.repository_name):
if role in ['root', 'snapshot', 'targets', 'timestamp']:
if role in tuf.roledb.TOP_LEVEL_ROLES:
continue

else:
Expand Down
13 changes: 5 additions & 8 deletions tuf/repository_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _generate_and_write_metadata(rolename, metadata_filename,
else:
logger.debug('Not incrementing ' + repr(rolename) + '\'s version number.')

if rolename in ['root', 'targets', 'snapshot', 'timestamp'] and not allow_partially_signed:
if rolename in tuf.roledb.TOP_LEVEL_ROLES and not allow_partially_signed:
# Verify that the top-level 'rolename' is fully signed. Only a delegated
# role should not be written to disk without full verification of its
# signature(s), since it can only be considered fully signed depending on
Expand Down Expand Up @@ -394,18 +394,15 @@ def _delete_obsolete_metadata(metadata_directory, snapshot_metadata,
else:
logger.debug(repr(metadata_role) + ' found in the snapshot role.')



# Strip metadata extension from filename. The role database does not
# include the metadata extension.
if metadata_role.endswith(METADATA_EXTENSION):
metadata_role = metadata_role[:-len(METADATA_EXTENSION)]

else:
logger.debug(repr(metadata_role) + ' does not match'
' supported extension ' + repr(METADATA_EXTENSION))

if metadata_role in ['root', 'targets', 'snapshot', 'timestamp']:
if metadata_role in tuf.roledb.TOP_LEVEL_ROLES:
logger.debug('Not removing top-level metadata ' + repr(metadata_role))
return

Expand Down Expand Up @@ -850,7 +847,7 @@ def get_delegated_roles_metadata_filenames(metadata_directory,
continue

# Skip top-level roles, only interested in delegated roles.
if metadata_name in ['root', 'snapshot', 'targets', 'timestamp']:
if metadata_name in tuf.roledb.TOP_LEVEL_ROLES:
continue

# Prevent reloading duplicate versions if consistent_snapshot is True
Expand Down Expand Up @@ -1131,7 +1128,7 @@ def generate_root_metadata(version, expiration_date, consistent_snapshot,
# Extract the role, threshold, and keyid information of the top-level roles,
# which Root stores in its metadata. The necessary role metadata is generated
# from this information.
for rolename in ['root', 'targets', 'snapshot', 'timestamp']:
for rolename in tuf.roledb.TOP_LEVEL_ROLES:

# If a top-level role is missing from 'tuf.roledb.py', raise an exception.
if not tuf.roledb.role_exists(rolename, repository_name):
Expand Down Expand Up @@ -1507,7 +1504,7 @@ def generate_snapshot_metadata(metadata_directory, version, expiration_date,
# snapshot and timestamp roles are not listed in snapshot.json, do not
# list these roles found in the metadata directory.
if tuf.roledb.role_exists(rolename, repository_name) and \
rolename not in ['root', 'snapshot', 'timestamp', 'targets']:
rolename not in tuf.roledb.TOP_LEVEL_ROLES:
fileinfodict[metadata_name] = get_metadata_versioninfo(rolename,
repository_name)

Expand Down
2 changes: 1 addition & 1 deletion tuf/repository_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def writeall(self, consistent_snapshot=False, use_existing_fileinfo=False):
for dirty_rolename in dirty_rolenames:

# Ignore top-level roles, they will be generated later in this method.
if dirty_rolename in ['root', 'targets', 'snapshot', 'timestamp']:
if dirty_rolename in tuf.roledb.TOP_LEVEL_ROLES:
continue

dirty_filename = os.path.join(self._metadata_directory,
Expand Down
3 changes: 3 additions & 0 deletions tuf/roledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
_dirty_roles['default'] = set()


TOP_LEVEL_ROLES = ['root', 'targets', 'snapshot', 'timestamp']


def create_roledb_from_root_metadata(root_metadata, repository_name='default'):
"""
<Purpose>
Expand Down

0 comments on commit 6ae3ea6

Please sign in to comment.