use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class ApiKeyResource method getByName.
@GET
@Path("{name}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Find api key by name.", response = ApiKeyDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getByName(@PathParam("name") String name, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ApiKeyException {
Users user = jwtHelper.getUserPrincipal(sc);
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.APIKEY);
ApiKeyDTO dto = apikeyBuilder.build(uriInfo, resourceRequest, user, name);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class ApiKeyResource method update.
@PUT
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an api key.", response = ApiKeyDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response update(@QueryParam("name") String name, @QueryParam("action") ApiKeyUpdateAction action, @QueryParam("scope") Set<ApiScope> scopes, @Context UriInfo uriInfo, @Context HttpServletRequest req, @Context SecurityContext sc) throws ApiKeyException {
Users user = jwtHelper.getUserPrincipal(sc);
Set<ApiScope> validatedScopes = validateScopes(user, scopes);
ApiKey apikey;
switch(action == null ? ApiKeyUpdateAction.ADD : action) {
case ADD:
apikey = apikeyController.addScope(user, name, validatedScopes);
break;
case DELETE:
apikey = apikeyController.removeScope(user, name, validatedScopes);
break;
case UPDATE:
apikey = apikeyController.update(user, name, validatedScopes);
break;
default:
throw new WebApplicationException("Action need to set a valid action, but found: " + action, Response.Status.NOT_FOUND);
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.APIKEY);
ApiKeyDTO dto = apikeyBuilder.build(uriInfo, resourceRequest, apikey);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class ApiKeyResource method getByKey.
@GET
@Path("key")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Find api key by name.", response = ApiKeyDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getByKey(@QueryParam("key") String key, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ApiKeyException {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.APIKEY);
ApiKey apikey = apikeyController.getApiKey(key);
ApiKeyDTO dto = apikeyBuilder.build(uriInfo, resourceRequest, apikey);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class TagSchemasResource method post.
@ApiOperation(value = "Create new schema", response = SchemaDTO.class)
@POST
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN" })
@ApiKeyRequired(acceptedScopes = { ApiScope.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN" })
public Response post(@Context SecurityContext sc, @Context UriInfo uriInfo, @QueryParam("name") String schemaName, String schema) throws SchematizedTagException {
TagSchemasController.create(schemaName, schema);
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAG_SCHEMAS);
SchemaDTO dto = tagSchemasBuilder.build(uriInfo, resourceRequest, schemaName);
return Response.created(dto.getHref()).entity(dto).build();
}
use of io.hops.hopsworks.common.api.ResourceRequest in project hopsworks by logicalclocks.
the class UsersResource method getUserProfile.
@GET
@Path("profile")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets logged in User\'s info.", response = UserProfileDTO.class)
public Response getUserProfile(@Context UriInfo uriInfo, @Context SecurityContext sc) throws UserException {
Users user = jWTHelper.getUserPrincipal(sc);
if (user == null) {
throw new UserException(RESTCodes.UserErrorCode.USER_WAS_NOT_FOUND, Level.FINE);
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.USERS);
UserProfileDTO userDTO = usersBuilder.buildFull(uriInfo, resourceRequest, user);
return Response.ok().entity(userDTO).build();
}
Aggregations