Search in sources :

Example 16 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class KafkaResource method deleteSubjectsVersion.

@ApiOperation(value = "Delete a specific version of a subject (and its compatibility).")
@DELETE
@Path("/subjects/{subject}/versions/{version}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
@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 deleteSubjectsVersion(@PathParam("subject") String subject, @PathParam("version") String version, @Context SecurityContext sc) throws KafkaException {
    try {
        Integer deleted = subjectsController.deleteSubjectsVersion(project, subject, version);
        GenericEntity<Integer> entity = new GenericEntity<Integer>(deleted) {
        };
        return Response.ok().entity(entity).build();
    } catch (SchemaException e) {
        SchemaRegistryError error = new SchemaRegistryError(e.getErrorCode().getCode(), e.getErrorCode().getMessage());
        return Response.status(e.getErrorCode().getRespStatus()).entity(error).build();
    }
}
Also used : SchemaException(io.hops.hopsworks.exceptions.SchemaException) GenericEntity(javax.ws.rs.core.GenericEntity) SchemaRegistryError(io.hops.hopsworks.common.dao.kafka.schemas.SchemaRegistryError) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 17 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class KafkaResource method getTopics.

@ApiOperation(value = "Retrieve Kafka topics metadata .")
@GET
@Path("/topics")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTopics(@Context UriInfo uriInfo, @BeanParam Pagination pagination, @BeanParam TopicsBeanParam topicsBeanParam, @Context SecurityContext sc) {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.KAFKA);
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    resourceRequest.setSort(topicsBeanParam.getSortBySet());
    resourceRequest.setFilter(topicsBeanParam.getFilter());
    TopicDTO dto = topicsBuilder.build(uriInfo, resourceRequest, project);
    return Response.ok().entity(dto).build();
}
Also used : TopicDTO(io.hops.hopsworks.common.dao.kafka.TopicDTO) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 18 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class KafkaResource method updateTopicAcls.

@ApiOperation(value = "Update ACL specified by id.")
@PUT
@Path("/topics/{topic}/acls/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response updateTopicAcls(@Context UriInfo uriInfo, @PathParam("topic") String topicName, @PathParam("id") Integer aclId, AclDTO aclDto, @Context SecurityContext sc) throws KafkaException, ProjectException, UserException {
    Integer updatedAclId = kafkaController.updateTopicAcl(project, topicName, aclId, aclDto);
    aclDto.setId(updatedAclId);
    URI uri = aclBuilder.getAclUri(uriInfo, project, topicName).path(Integer.toString(updatedAclId)).build();
    aclDto.setHref(uri);
    return Response.ok(uri).entity(aclDto).build();
}
Also used : URI(java.net.URI) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 19 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class JupyterService method getGitStatusOfJupyterRepo.

@GET
@Path("/git/status")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getGitStatusOfJupyterRepo(@Context SecurityContext sc) throws ProjectException, ServiceException {
    Users user = jWTHelper.getUserPrincipal(sc);
    String projectUser = hdfsUsersController.getHdfsUserName(project, user);
    JupyterProject jupyterProject = jupyterFacade.findByUser(projectUser);
    if (jupyterProject == null) {
        throw new ProjectException(RESTCodes.ProjectErrorCode.JUPYTER_SERVER_NOT_FOUND, Level.FINE, "Could not found Jupyter server", "Could not found Jupyter server for Hopsworks user: " + projectUser);
    }
    if (!jupyterManager.ping(jupyterProject)) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.JUPYTER_SERVERS_NOT_RUNNING, Level.FINE, "Jupyter server is not running", "Jupyter server for Hopsworks user: " + projectUser + " is not running");
    }
    JupyterSettings jupyterSettings = jupyterSettingsFacade.findByProjectUser(project, user.getEmail());
    RepositoryStatus status = NullJupyterNbVCSController.EMPTY_REPOSITORY_STATUS;
    if (jupyterSettings.isGitBackend()) {
        status = jupyterNbVCSController.status(jupyterProject, jupyterSettings);
    }
    return Response.ok(status).build();
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) JupyterSettings(io.hops.hopsworks.persistence.entity.jupyter.JupyterSettings) RepositoryStatus(io.hops.hopsworks.common.jupyter.RepositoryStatus) JupyterProject(io.hops.hopsworks.persistence.entity.jupyter.JupyterProject) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 20 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class JupyterService method settings.

/**
 * Get livy session Yarn AppId
 *
 * @param sc
 * @return
 */
@GET
@Path("/settings")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response settings(@Context SecurityContext sc) {
    Users user = jWTHelper.getUserPrincipal(sc);
    JupyterSettings js = jupyterSettingsFacade.findByProjectUser(project, user.getEmail());
    if (settings.isPythonKernelEnabled()) {
        js.setPrivateDir(settings.getStagingDir() + Settings.PRIVATE_DIRS + js.getSecret());
    }
    js.setGitAvailable(jupyterNbVCSController.isGitAvailable());
    js.setMode(JupyterMode.JUPYTER_LAB);
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(js).build();
}
Also used : JupyterSettings(io.hops.hopsworks.persistence.entity.jupyter.JupyterSettings) HdfsUsers(io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)292 Produces (javax.ws.rs.Produces)265 ApiOperation (io.swagger.annotations.ApiOperation)244 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)238 Path (javax.ws.rs.Path)203 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)171 Users (io.hops.hopsworks.persistence.entity.user.Users)169 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)151 GET (javax.ws.rs.GET)150 Consumes (javax.ws.rs.Consumes)73 POST (javax.ws.rs.POST)62 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)44 PUT (javax.ws.rs.PUT)42 DELETE (javax.ws.rs.DELETE)37 GenericEntity (javax.ws.rs.core.GenericEntity)30 Project (io.hops.hopsworks.persistence.entity.project.Project)24 AlertException (io.hops.hopsworks.exceptions.AlertException)20 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)16 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)16 TagsDTO (io.hops.hopsworks.common.tags.TagsDTO)16