include CHECKSUM_TYPES in kojikamid.py, and use it when validating checksums of downloaded files

The Koji data model has been updated to support multiple checksum types. These are listed in the
CHECKSUM_TYPES enum in koji/__init__.py, but are not available in kojikamid.py. This change
copies the Enum class and the CHECKSUM_TYPES enum into kojikamid at build time, and uses it when
validating the checksums of downloaded files.
This commit is contained in:
Mike Bonnet 2019-11-26 11:06:49 -08:00 committed by Tomas Kopecek
parent 4cd37132dd
commit be31305f52
2 changed files with 21 additions and 10 deletions

View file

@ -127,6 +127,7 @@ for h in (
'RECOMMENDNAME', 'RECOMMENDVERSION', 'RECOMMENDFLAGS'):
SUPPORTED_OPT_DEP_HDRS[h] = hasattr(rpm, 'RPMTAG_%s' % h)
## BEGIN kojikamid dup
class Enum(dict):
"""A simple class to track our enumerated constants
@ -174,6 +175,8 @@ class Enum(dict):
update = _notImplemented
setdefault = _notImplemented
## END kojikamid dup
API_VERSION = 1
TASK_STATES = Enum((
@ -262,12 +265,16 @@ TAG_UPDATE_TYPES = Enum((
'MANUAL',
))
## BEGIN kojikamid dup
CHECKSUM_TYPES = Enum((
'md5',
'sha1',
'sha256',
))
## END kojikamid dup
#PARAMETERS
BASEDIR = '/mnt/koji'
# default task priority

View file

@ -316,15 +316,16 @@ class WindowsBuild(object):
destpath = os.path.join(basedir, fileinfo['localpath'])
ensuredir(os.path.dirname(destpath))
if 'checksum_type' in fileinfo:
if fileinfo['checksum_type'] == 'sha1':
checksum_type = CHECKSUM_TYPES[fileinfo['checksum_type']]
if checksum_type == 'sha1':
checksum = hashlib.sha1()
elif fileinfo['checksum_type'] == 'sha256':
elif checksum_type == 'sha256':
checksum = hashlib.sha256()
elif fileinfo['checksum_type'] == 'md5':
elif checksum_type == 'md5':
checksum = hashlib.md5()
else:
raise BuildError('Unknown checksum type %s for %s' % (
fileinfo['checksum_type'],
checksum_type,
os.path.basename(fileinfo['localpath'])))
with open(destpath, 'w') as destfile:
offset = 0
@ -338,12 +339,15 @@ class WindowsBuild(object):
offset += len(data)
if 'checksum_type' in fileinfo:
checksum.update(data)
# rpms don't have a md5sum in the fileinfo, but check it for everything else
# rpms don't have a checksum in the fileinfo, but check it for everything else
if 'checksum_type' in fileinfo:
digest = checksum.hexdigest()
if 'checksum' in fileinfo and fileinfo['checksum'] != digest:
if fileinfo['checksum'] != digest:
raise BuildError('checksum validation failed for %s, %s (computed) != %s (provided)' % \
(destpath, digest, fileinfo['checksum']))
self.logger.info('Retrieved %s (%s bytes, md5: %s)', destpath, offset, digest)
self.logger.info('Retrieved %s (%s bytes, %s: %s)', destpath, offset, checksum_type, digest)
else:
self.logger.info('Retrieved %s (%s bytes)', destpath, offset)
def fetchBuildReqs(self):
"""Retrieve buildrequires listed in the spec file"""