use of com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo in project indy by Commonjava.
the class KojiBuildAuthority method isAuthorized.
@IndyMetrics(measure = @Measure(timers = @MetricNamed(name = IndyMetricsKojiNames.METHOD_BUILDAUTHORITY_ISAUTHORIZED + IndyMetricsNames.TIMER), meters = @MetricNamed(name = IndyMetricsKojiNames.METHOD_BUILDAUTHORITY_ISAUTHORIZED + IndyMetricsNames.METER)))
public boolean isAuthorized(String path, EventMetadata eventMetadata, ProjectRef ref, KojiBuildInfo build, KojiSessionInfo session, Map<Integer, KojiBuildArchiveCollection> seenBuildArchives) throws KojiClientException {
ArtifactStore authoritativeStore = getAuthoritativeStore();
if (authoritativeStore != null) {
KojiBuildArchiveCollection archiveCollection = seenBuildArchives.get(build.getId());
if (archiveCollection == null) {
archiveCollection = kojiClient.listArchivesForBuild(build, session);
seenBuildArchives.put(build.getId(), archiveCollection);
}
if (archiveCollection == null) {
throw new KojiClientException("Failed to retrieve archives for build: %s", build);
}
// @formatter:off
Predicate<KojiArchiveInfo> archiveInfoFilter = (archive) -> EXCLUDED_FILE_ENDINGS.stream().allMatch(ending -> !archive.getFilename().endsWith(ending));
List<KojiArchiveInfo> sortedArchives = archiveCollection.getArchives().stream().filter(archiveInfoFilter).sorted((a1, a2) -> {
TypePriority t1 = TypePriority.get(a1.getExtension());
TypePriority t2 = TypePriority.get(a2.getExtension());
return Integer.valueOf(t1.ordinal()).compareTo(t2.ordinal());
}).collect(Collectors.toList());
for (KojiArchiveInfo archive : sortedArchives) {
try {
if (isMavenArtifact(archive)) {
// skip non-Maven artifacts
continue;
}
if (containsPlaceholders(archive)) {
return false;
}
String artifactPath = ArtifactPathUtils.formatArtifactPath(archive.asArtifact(), typeMapper);
String md5 = checksumArtifact(authoritativeStore, artifactPath, eventMetadata);
if (isNotBlank(md5)) {
//FIXME: not sure if all koji archives are using md5 as checksum type for maven build
String kojiMd5 = archive.getChecksum();
Logger logger = LoggerFactory.getLogger(getClass());
logger.info("Checking checksum for {} (path: {}) in auth store {}, auth store checksum:{}, koji build check sum:{}", ref, path, authoritativeStore, md5, kojiMd5);
if (!md5.equals(kojiMd5)) {
// if checksum is not the same, it means the artifact in koji is DIFFERENT from the one in the authoritative store. Reject this.
return false;
}
}
} catch (Exception e) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.error("SHOULD NEVER HAPPEN: Failed to transform artifact to path: " + e.getMessage(), e);
}
}
}
return true;
}
Aggregations