use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResource method regenerateIdentityCertificates.
/**
* Retrieves a single Consumer
*
* @param uuid uuid of the consumer sought.
* @return a Consumer object
* @httpcode 400
* @httpcode 404
* @httpcode 200
*/
@ApiOperation(notes = "Retrieves a single Consumer", value = "regenerateIdentityCertificates")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") })
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.WILDCARD)
@Path("{consumer_uuid}")
public ConsumerDTO regenerateIdentityCertificates(@PathParam("consumer_uuid") @Verify(Consumer.class) String uuid) {
Consumer consumer = consumerCurator.verifyAndLookupConsumer(uuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
logShareConsumerRequestWarning("regenerate identity certificate", consumer);
} else {
consumer = regenerateIdentityCertificate(consumer);
}
return translator.translate(consumer, ConsumerDTO.class);
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResource method list.
@ApiOperation(notes = "Retrieves a list of the Consumers", value = "list", response = Consumer.class, responseContainer = "list")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "") })
@GET
@Produces(MediaType.APPLICATION_JSON)
@Wrapped(element = "consumers")
@SuppressWarnings("checkstyle:indentation")
public CandlepinQuery<ConsumerDTO> list(@QueryParam("username") String userName, @QueryParam("type") Set<String> typeLabels, @QueryParam("owner") String ownerKey, @QueryParam("uuid") List<String> uuids, @QueryParam("hypervisor_id") List<String> hypervisorIds, @QueryParam("fact") @CandlepinParam(type = KeyValueParameter.class) List<KeyValueParameter> attrFilters, @Context PageRequest pageRequest) {
if (userName == null && (typeLabels == null || typeLabels.isEmpty()) && ownerKey == null && (uuids == null || uuids.isEmpty()) && (hypervisorIds == null || hypervisorIds.isEmpty()) && (attrFilters == null || attrFilters.isEmpty())) {
throw new BadRequestException(i18n.tr("Must specify at least one search criteria."));
}
Owner owner = null;
if (ownerKey != null) {
owner = ownerCurator.lookupByKey(ownerKey);
if (owner == null) {
throw new NotFoundException(i18n.tr("owner with key: {0} was not found.", ownerKey));
}
}
List<ConsumerType> types = consumerTypeValidator.findAndValidateTypeLabels(typeLabels);
CandlepinQuery<Consumer> query = this.consumerCurator.searchOwnerConsumers(owner, userName, types, uuids, hypervisorIds, attrFilters, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
return this.translator.translateQuery(query, ConsumerDTO.class);
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResource method create.
@ApiOperation(notes = "Creates a Consumer. NOTE: Opening this method up " + "to everyone, as we have nothing we can reliably " + "verify in the method signature. Instead we have to " + "figure out what owner this consumer is destined for " + "(due to backward compatability with existing clients " + "which do not specify an owner during registration), " + "and then check the access to the specified owner in " + "the method itself.", value = "create")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 403, message = ""), @ApiResponse(code = 404, message = "") })
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@SecurityHole(noAuth = true)
@Transactional
public ConsumerDTO create(@ApiParam(name = "consumer", required = true) ConsumerDTO dto, @Context Principal principal, @QueryParam("username") String userName, @QueryParam("owner") String ownerKey, @QueryParam("activation_keys") String activationKeys, @QueryParam("identity_cert_creation") @DefaultValue("true") boolean identityCertCreation) throws BadRequestException {
// fix for duplicate hypervisor/consumer problem
Consumer consumer = null;
if (ownerKey != null && dto.getFact("system_uuid") != null && !"true".equalsIgnoreCase(dto.getFact("virt.is_guest"))) {
Owner owner = ownerCurator.lookupByKey(ownerKey);
if (owner != null) {
consumer = consumerCurator.getHypervisor(dto.getFact("system_uuid"), owner);
if (consumer != null) {
consumer.setIdCert(generateIdCert(consumer, false));
this.updateConsumer(consumer.getUuid(), dto, principal);
return translator.translate(consumer, ConsumerDTO.class);
}
}
}
if (consumer == null) {
consumer = new Consumer();
}
if (dto.getUuid() != null) {
consumer.setUuid(dto.getUuid());
}
consumer.setOwner(ownerCurator.lookupByKey(ownerKey));
populateEntity(consumer, dto);
if (dto.getType() == null) {
throw new BadRequestException(i18n.tr("Unit type must be specified."));
}
ConsumerType ctype = this.consumerTypeCurator.lookupByLabel(dto.getType().getLabel());
if (ctype == null) {
throw new BadRequestException(i18n.tr("Invalid unit type: {0}", dto.getType().getLabel()));
}
return translator.translate(createConsumerFromDTO(dto, ctype, principal, userName, ownerKey, activationKeys, identityCertCreation), ConsumerDTO.class);
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResource method exportDataAsync.
/**
* Initiates an async generation of a compressed file representation of a {@link Consumer} (manifest).
* The response will contain the id of the job from which its result data will contain the href to
* download the generated file.
*
* @param response the response to send back from the server.
* @param consumerUuid the uuid of the target consumer.
* @param cdnLabel the CDN label to store in the meta file.
* @param webAppPrefix the URL pointing to the manifest's originating web application.
* @param apiUrl the API URL pointing to the manifest's originating candlepin API.
* @return the details of the async export job that is to be started.
*/
@ApiOperation(notes = "Initiates an async generation of a Compressed File representation of a Consumer " + "(manifest). The response will contain the id of the job from which its result data " + " will contain the href to download the generated file.", value = "Async Consumer Export (manifest)", response = JobDetail.class)
@ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 404, message = "") })
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{consumer_uuid}/export/async")
public JobDetail exportDataAsync(@Context HttpServletResponse response, @PathParam("consumer_uuid") @Verify(Consumer.class) @ApiParam(value = "The UUID of the target consumer", required = true) String consumerUuid, @QueryParam("cdn_label") @ApiParam(value = "The lable of the target CDN", required = false) String cdnLabel, @QueryParam("webapp_prefix") @ApiParam(value = "the URL pointing to the manifest's originating web application", required = false) String webAppPrefix, @QueryParam("api_url") @ApiParam(value = "the URL pointing to the manifest's originating candlepin API", required = false) String apiUrl, @QueryParam("ext") @CandlepinParam(type = KeyValueParameter.class) @ApiParam(value = "Key/Value pairs to be passed to the extension adapter when generating a manifest", required = false, example = "ext=version:1.2.3&ext=extension_key:EXT1") List<KeyValueParameter> extensionArgs) {
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
throw new BadRequestException(i18n.tr("Can not export manifest of a share consumer"));
}
Owner owner = ownerCurator.findOwnerById(consumer.getOwnerId());
return manifestManager.generateManifestAsync(consumerUuid, owner.getKey(), cdnLabel, webAppPrefix, apiUrl, getExtensionParamMap(extensionArgs));
}
use of org.candlepin.model.ConsumerType in project candlepin by candlepin.
the class ConsumerResource method getEntitlementCertificateSerials.
@ApiOperation(notes = "Retrieves a list of Certiticate Serials Return the " + "client certificate metadata a for the given consumer. This is a small" + " subset of data clients can use to determine which certificates they" + " need to update/fetch.", value = "getEntitlementCertificateSerials")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@GET
@Path("{consumer_uuid}/certificates/serials")
@Produces(MediaType.APPLICATION_JSON)
@Wrapped(element = "serials")
@UpdateConsumerCheckIn
public List<CertificateSerialDto> getEntitlementCertificateSerials(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid) {
log.debug("Getting client certificate serials for consumer: {}", consumerUuid);
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
logShareConsumerRequestWarning("cert serial fetch", consumer);
return new ArrayList<>();
}
revokeOnGuestMigration(consumer);
poolManager.regenerateDirtyEntitlements(consumer);
List<CertificateSerialDto> allCerts = new LinkedList<>();
for (Long id : entCertService.listEntitlementSerialIds(consumer)) {
allCerts.add(new CertificateSerialDto(id));
}
// add content access cert if needed
try {
ContentAccessCertificate cac = contentAccessCertService.getCertificate(consumer);
if (cac != null) {
allCerts.add(new CertificateSerialDto(cac.getSerial().getId()));
}
} catch (IOException ioe) {
throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate"), ioe);
} catch (GeneralSecurityException gse) {
throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate", gse));
}
return allCerts;
}
Aggregations