def _check_rolename(rolename, repository_name='default'): """ Raise tuf.FormatError if 'rolename' does not match 'tuf.formats.ROLENAME_SCHEMA', tuf.UnknownRoleError if 'rolename' is not found in the role database, or tuf.InvalidNameError if 'repository_name' does not exist in the role database. """ # Does 'rolename' have the correct object format? # This check will ensure 'rolename' has the appropriate number of objects # and object types, and that all dict keys are properly named. tuf.formats.ROLENAME_SCHEMA.check_match(rolename) # Does 'repository_name' have the correct format? tuf.formats.NAME_SCHEMA.check_match(repository_name) # Raises tuf.InvalidNameError. _validate_rolename(rolename) global _roledb_dict global _dirty_roles if repository_name not in _roledb_dict or repository_name not in _dirty_roles: raise tuf.InvalidNameError('Repository name does not' ' exist: ' + repository_name) if rolename not in _roledb_dict[repository_name]: raise tuf.UnknownRoleError('Role name does not exist: ' + rolename)
def update_roleinfo(rolename, roleinfo): """ <Purpose> <Arguments> rolename: An object representing the role's name, conformant to 'ROLENAME_SCHEMA' (e.g., 'root', 'snapshot', 'timestamp'). roleinfo: An object representing the role associated with 'rolename', conformant to ROLEDB_SCHEMA. 'roleinfo' has the form: {'name': 'role_name', 'keyids': ['34345df32093bd12...'], 'threshold': 1, 'paths': ['path/to/target1', 'path/to/target2', ...], 'path_hash_prefixes': ['a324fcd...', ...]} The 'name', 'paths', and 'path_hash_prefixes' dict keys are optional. The 'target' role has an additional 'paths' key. Its value is a list of strings representing the path of the target file(s). <Exceptions> tuf.FormatError, if 'rolename' or 'roleinfo' does not have the correct object format. tuf.UnknownRoleError, if 'rolename' cannot be found in the role database. tuf.InvalidNameError, if 'rolename' is improperly formatted. <Side Effects> The role database is modified. <Returns> None. """ # Does 'rolename' have the correct object format? # This check will ensure 'rolename' has the appropriate number of objects # and object types, and that all dict keys are properly named. tuf.formats.ROLENAME_SCHEMA.check_match(rolename) # Does 'roleinfo' have the correct object format? tuf.formats.ROLEDB_SCHEMA.check_match(roleinfo) # Raises tuf.InvalidNameError. _validate_rolename(rolename) if rolename not in _roledb_dict: raise tuf.UnknownRoleError('Role does not exist: ' + rolename) _roledb_dict[rolename] = copy.deepcopy(roleinfo)
def _check_rolename(rolename): """ Raise tuf.FormatError if 'rolename' does not match 'tuf.formats.ROLENAME_SCHEMA', tuf.UnknownRoleError if 'rolename' is not found in the role database, or tuf.InvalidNameError if 'rolename' is not formatted correctly. """ # Does 'rolename' have the correct object format? # This check will ensure 'rolename' has the appropriate number of objects # and object types, and that all dict keys are properly named. tuf.formats.ROLENAME_SCHEMA.check_match(rolename) # Raises tuf.InvalidNameError. _validate_rolename(rolename) if rolename not in _roledb_dict: raise tuf.UnknownRoleError('Role name does not exist: ' + rolename)
def update_roleinfo(rolename, roleinfo, mark_role_as_dirty=True, repository_name='default'): """ <Purpose> Modify 'rolename's _roledb_dict entry to include the new 'roleinfo'. 'rolename' is also added to the _dirty_roles set. Roles added to '_dirty_roles' are marked as modified and can be used by the repository tools to determine which roles need to be written to disk. <Arguments> rolename: An object representing the role's name, conformant to 'ROLENAME_SCHEMA' (e.g., 'root', 'snapshot', 'timestamp'). roleinfo: An object representing the role associated with 'rolename', conformant to ROLEDB_SCHEMA. 'roleinfo' has the form: {'name': 'role_name', 'keyids': ['34345df32093bd12...'], 'threshold': 1, 'paths': ['path/to/target1', 'path/to/target2', ...], 'path_hash_prefixes': ['a324fcd...', ...]} The 'name', 'paths', and 'path_hash_prefixes' dict keys are optional. The 'target' role has an additional 'paths' key. Its value is a list of strings representing the path of the target file(s). mark_role_as_dirty: A boolean indicating whether the updated 'roleinfo' for 'rolename' should be marked as dirty. The caller might not want to mark 'rolename' as dirty if it is loading metadata from disk and only wants to populate roledb.py. Likewise, add_role() would support a similar boolean to allow the repository tools to successfully load roles via load_repository() without needing to mark these roles as dirty (default behavior). repository_name: The name of the repository to update the roleinfo of 'rolename'. If not supplied, the 'default' repository is searched. <Exceptions> tuf.FormatError, if 'rolename' or 'roleinfo' does not have the correct object format. tuf.UnknownRoleError, if 'rolename' cannot be found in the role database. tuf.InvalidNameError, if 'rolename' is improperly formatted, or 'repository_name' does not exist in the role database. <Side Effects> The role database is modified. <Returns> None. """ I_TO_PRINT = TO_PRINT + uptane.YELLOW + '[update_roleinfo(rolename, roleinfo, mark_role_as_dirty, repository_name)]: ' + uptane.ENDCOLORS #TODO: Print to be deleted print(str('%s %s %s %s %s %s %s %s %s' % (I_TO_PRINT, 'Updating info for Role: ', rolename, 'With roleinfo:', roleinfo, 'Mark role as dirty:', mark_role_as_dirty, 'repository name:', repository_name))) #TODO: Until here # Does the arguments have the correct object format? # This check will ensure arguments have the appropriate number of objects # and object types, and that all dict keys are properly named. tuf.formats.ROLENAME_SCHEMA.check_match(rolename) tuf.formats.BOOLEAN_SCHEMA.check_match(mark_role_as_dirty) tuf.formats.NAME_SCHEMA.check_match(repository_name) # Does 'roleinfo' have the correct object format? tuf.formats.ROLEDB_SCHEMA.check_match(roleinfo) # Raises tuf.InvalidNameError. _validate_rolename(rolename) global _roledb_dict global _dirty_roles if repository_name not in _roledb_dict or repository_name not in _dirty_roles: raise tuf.InvalidNameError('Repository name does not' ' exist: ' + repository_name) if rolename not in _roledb_dict[repository_name]: raise tuf.UnknownRoleError('Role does not exist: ' + rolename) # Update the global _roledb_dict and _dirty_roles structures so that # the latest 'roleinfo' is available to other modules, and the repository # tools know which roles should be saved to disk. _roledb_dict[repository_name][rolename] = copy.deepcopy(roleinfo) if mark_role_as_dirty: _dirty_roles[repository_name].add(rolename) #TODO: Print to be deleted print(str('%s %s ' % (I_TO_PRINT, 'Returning ...')))