@Path("{dbid}/upstream_cert")
public String getUpstreamCert(
@PathParam("dbid") String entitlementId) {
Entitlement ent = entitlementCurator.find(entitlementId);
if (ent == null) {
throw new NotFoundException(i18n.tr(
"Entitlement with ID ''{0}'' could not be found.", entitlementId));
}
String subscriptionId = null;
Pool entPool = ent.getPool();
if (StringUtils.isBlank(entPool.getSourceStackId())) {
subscriptionId = entPool.getSubscriptionId();
}
/*
* A derived pool originating from a stacked parent pool will have no subscription
* ID as the pool is technically from many subscriptions. (i.e. all the
* entitlements in the stack) In this case we must look up an active entitlement
* in the hosts stack, and use this as our upstream certificate.
*/
else {
log.debug("Entitlement is from a stack derived pool, searching for oldest " +
"active entitlements in source stack.");
Entitlement e = entitlementCurator.findUpstreamEntitlementForStack(
entPool.getSourceConsumer(),
entPool.getSourceStackId());
if (e != null) {
subscriptionId = e.getPool().getSubscriptionId();
}
}
if (subscriptionId == null) {
throw new NotFoundException(
i18n.tr("Unable to find upstream certificate for entitlement: {0}",
entitlementId));
}
return subResource.getSubCertAsPem(subscriptionId);