use of com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo in project indy by Commonjava.
the class KojiBuildAuthority method isAuthorized.
@Measure
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) {
List<KojiArchiveInfo> archiveList = kojiContentProvider.listArchivesForBuild(build.getId(), session);
archiveCollection = new KojiBuildArchiveCollection(build, archiveList);
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;
}
use of com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo in project indy by Commonjava.
the class KojiContentManagerDecorator method proxyKojiBuild.
private <T> T proxyKojiBuild(final StoreKey inStore, final ArtifactRef artifactRef, final String path, EventMetadata eventMetadata, T defValue, KojiBuildAction<T> consumer) throws IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
try {
// return kojiClient.withKojiSession( ( session ) -> {
KojiSessionInfo session = null;
List<KojiBuildInfo> builds = kojiContentProvider.listBuildsContaining(artifactRef, session);
builds.sort((build1, build2) -> build2.getCreationTime().compareTo(build1.getCreationTime()));
logger.debug("Got {} builds from koji. Looking for best match.", builds.size());
// use multicall
Map<Integer, List<KojiTagInfo>> tagsMap = getTagsByBuildIds(builds, session);
for (KojiBuildInfo build : builds) {
if (build.getBuildState() != KojiBuildState.COMPLETE) {
logger.debug("Build: {} is not completed. The state is {}. Skipping.", build.getNvr(), build.getBuildState());
continue;
}
boolean buildAllowed = false;
if (kojiUtils.isBinaryBuild(build)) {
// This is not a real build, it's a binary import.
if (config.isProxyBinaryBuilds()) {
logger.info("Trying binary build: {} with id: {}", build.getNvr(), build.getId());
buildAllowed = true;
} else {
logger.debug("Skipping binary build: {} with id: {}", build.getNvr(), build.getId());
}
} else {
logger.info("Trying build: {} with id: {}", build.getNvr(), build.getId());
if (!config.isTagPatternsEnabled()) {
buildAllowed = true;
} else {
List<KojiTagInfo> tags = tagsMap.get(build.getId());
logger.debug("Build {} is in {} tags.", build.getId(), tags.size());
if (logger.isTraceEnabled()) {
logTagsForBuild(build.getId(), tags);
}
for (KojiTagInfo tag : tags) {
// If the tags match patterns configured in whitelist, construct a new remote repo.
if (config.isTagAllowed(tag.getName())) {
logger.info("Koji tag is on whitelist: {}", tag.getName());
buildAllowed = true;
break;
} else {
logger.debug("Tag: {} is not in the whitelist.", tag.getName());
}
}
}
}
if (buildAllowed) {
// or the artifact matches the one in the authoritative store, go ahead.
if (buildAuthority.isAuthorized(path, eventMetadata, artifactRef, build, session)) {
return consumer.execute(inStore, artifactRef, build, session);
}
} else {
logger.debug("No whitelisted tags found for: {}", build.getNvr());
}
}
logger.trace("No builds were found that matched the restrictions.");
return defValue;
// } );
} catch (KojiClientException e) {
throw new IndyWorkflowException("Cannot retrieve builds for: %s. Error: %s", e, artifactRef, e.getMessage());
}
}
use of com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo in project indy by Commonjava.
the class IndyKojiContentProvider method getBuildInfo.
public List<KojiBuildInfo> getBuildInfo(List<Object> args, KojiSessionInfo session) throws KojiClientException {
logger.debug("getBuildInfo, args: {}", args);
if (!kojiConfig.isQueryCacheEnabled()) {
logger.trace("Cache not enabled, run direct kojiClient.multiCall");
return kojiClient.multiCall(GET_BUILD, args, KojiBuildInfo.class, session);
}
CacheHandle<Object, KojiBuildInfo> cache = cacheProducer.getCache(KOJI_BUILD_INFO);
Map<Object, KojiBuildInfo> m = new HashMap<>();
List<Object> missed = new ArrayList<>();
for (Object obj : args) {
KojiBuildInfo kojiBuildInfo = cache.get(obj);
if (kojiBuildInfo != null) {
m.put(obj, kojiBuildInfo);
} else {
missed.add(obj);
}
}
if (!missed.isEmpty()) {
List<KojiBuildInfo> retrieved = kojiClient.multiCall(GET_BUILD, missed, KojiBuildInfo.class, session);
for (int i = 0; i < missed.size(); i++) {
Object obj = missed.get(i);
KojiBuildInfo kojiBuildInfo = retrieved.get(i);
m.put(obj, kojiBuildInfo);
cache.put(obj, kojiBuildInfo);
}
}
List<KojiBuildInfo> ret = new ArrayList<>();
// keep the order of results equal to args
args.forEach((a) -> ret.add(m.get(a)));
return ret;
}
Aggregations