use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.
the class KafkaResource method getTopicAcls.
@ApiOperation(value = "Get all ACLs for a specified topic.")
@GET
@Path("/topics/{topic}/acls")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTopicAcls(@Context UriInfo uriInfo, @PathParam("topic") String topicName, @BeanParam Pagination pagination, @BeanParam AclsBeanParam aclsBeanParam, @Context SecurityContext sc) {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.KAFKA);
resourceRequest.setOffset(pagination.getOffset());
resourceRequest.setLimit(pagination.getLimit());
resourceRequest.setSort(aclsBeanParam.getSortBySet());
resourceRequest.setFilter(aclsBeanParam.getFilter());
AclDTO dto = aclBuilder.build(uriInfo, project, topicName, resourceRequest);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.
the class AclBuilder method build.
private AclDTO build(TopicAcls acl, UriBuilder uriBuilder) {
AclDTO dto = new AclDTO();
dto.setHost(acl.getHost());
dto.setId(acl.getId());
dto.setOperationType(acl.getOperationType());
dto.setPermissionType(acl.getPermissionType());
dto.setProjectName(KafkaConst.getProjectNameFromPrincipal(acl.getPrincipal()));
dto.setRole(acl.getRole());
dto.setUserEmail(acl.getUser().getEmail());
dto.setHref(uriBuilder.clone().path(Integer.toString(acl.getId())).build());
return dto;
}
use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.
the class AclBuilder method build.
public AclDTO build(UriInfo uriInfo, TopicAcls acl) {
AclDTO dto = new AclDTO(acl.getId(), KafkaConst.getProjectNameFromPrincipal(acl.getPrincipal()), acl.getUser().getEmail(), acl.getPermissionType(), acl.getOperationType(), acl.getHost(), acl.getRole());
dto.setHref(uriInfo.getAbsolutePathBuilder().path(Integer.toString(acl.getId())).build());
return dto;
}
use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.
the class KafkaController method addFullPermissionAclsToTopic.
private void addFullPermissionAclsToTopic(String aclProjectName, String topicName, Integer projectId) throws ProjectException, KafkaException, UserException {
Project p = projectFacade.findByName(aclProjectName);
if (p == null) {
throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.FINE, "Could not find project: " + aclProjectName);
}
List<AclDTO> acls = p.getProjectTeamCollection().stream().map(member -> member.getUser().getEmail()).map(email -> new AclDTO(p.getName(), email, "allow", Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD)).collect(Collectors.toList());
for (AclDTO acl : acls) {
addAclsToTopic(topicName, projectId, acl);
}
}
use of io.hops.hopsworks.common.dao.kafka.AclDTO in project hopsworks by logicalclocks.
the class KafkaController method addProjectMemberToTopics.
/**
* Add a new project member to all project's Kafka topics.
*
* @param project
* @param member
*/
public void addProjectMemberToTopics(Project project, String member) throws KafkaException, ProjectException, UserException {
// Get all topics (shared with project as well)
List<TopicDTO> topics = findTopicsByProject(project);
List<SharedTopics> sharedTopics = sharedTopicsFacade.findSharedTopicsByProject(project.getId());
// For every topic that has been shared with the current project, add the new member to its ACLs
for (SharedTopics sharedTopic : sharedTopics) {
addAclsToTopic(sharedTopic.getSharedTopicsPK().getTopicName(), sharedTopic.getProjectId(), new AclDTO(project.getName(), member, "allow", Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD));
}
// Iterate over topics and add user to ACLs
for (TopicDTO topic : topics) {
addAclsToTopic(topic.getName(), project.getId(), new AclDTO(project.getName(), member, "allow", Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD, Settings.KAFKA_ACL_WILDCARD));
}
}
Aggregations