use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.
the class ManagementResource method updateTemplates.
@PUT
@Path("templates")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response updateTemplates(TemplatesDTO templates, @Context SecurityContext sc) throws AlertException {
TemplatesDTO dto = new TemplatesDTO();
try {
alertManagerConfiguration.updateTemplates(templates.getTemplates());
List<String> t = alertManagerConfiguration.getTemplates();
dto.setTemplates(t);
} catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, Level.FINE, e.getMessage());
} catch (AlertManagerConfigUpdateException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_UPDATE_AM_CONFIG, Level.FINE, e.getMessage());
} catch (AlertManagerClientCreateException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
} catch (IllegalArgumentException e) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, e.getMessage());
}
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.
the class ManagementResource method updateConfig.
@POST
@Path("config")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response updateConfig(PostableAlertManagerConfig config, @Context SecurityContext sc) throws AlertException {
try {
AlertManagerConfig alertManagerConfig = toAlertManagerConfig(config);
alertManagerConfiguration.writeAndReload(alertManagerConfig);
alertManagerConfig = alertManagerConfiguration.read();
return Response.ok().entity(alertManagerConfig).build();
} catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, Level.FINE, e.getMessage());
} catch (AlertManagerConfigUpdateException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_UPDATE_AM_CONFIG, Level.FINE, e.getMessage());
} catch (AlertManagerClientCreateException e) {
throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
} catch (IllegalArgumentException e) {
throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, e.getMessage());
}
}
use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.
the class AdminRouteResource method get.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all routes.", response = RouteDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN" })
public Response get(@BeanParam Pagination pagination, @BeanParam RouteBeanParam routeBeanParam, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.ROUTES);
resourceRequest.setOffset(pagination.getOffset());
resourceRequest.setLimit(pagination.getLimit());
RouteDTO dto = routeBuilder.buildItems(uriInfo, resourceRequest, routeBeanParam, null);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.
the class AirflowService method composeDAG.
@POST
@Path("/dag")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Generate an Airflow Python DAG file from a DAG definition")
public Response composeDAG(AirflowDagDTO dagDefinition, @Context SecurityContext sc) throws AirflowException {
Users user = jwtHelper.getUserPrincipal(sc);
AirflowDAG dag = AirflowDagDTO.toAirflowDagTemplate(dagDefinition, user, project);
Map<String, Object> dataModel = new HashMap<>(4);
dataModel.put(AirflowJobLaunchOperator.class.getSimpleName(), AirflowJobLaunchOperator.class);
dataModel.put(AirflowJobSuccessSensor.class.getSimpleName(), AirflowJobSuccessSensor.class);
dataModel.put("dag", dag);
java.nio.file.Path outputFile = Paths.get(airflowJWTManager.getProjectDagDirectory(project.getId()).toString(), dagDefinition.getName() + ".py");
try (FileWriter out = new FileWriter(outputFile.toFile(), false)) {
templateEngine.template(AirflowDAG.TEMPLATE_NAME, dataModel, out);
} catch (IOException | TemplateException ex) {
throw new AirflowException(RESTCodes.AirflowErrorCode.DAG_NOT_TEMPLATED, Level.SEVERE, "Could not template DAG file for Project " + project.getName(), ex.getMessage(), ex);
}
return Response.ok().build();
}
use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.
the class FeaturestoreStorageConnectorService method createNewStorageConnector.
/**
* Endpoint for creating a storage connector with a particular type in a feature store
*
* @return a JSON representation of the connector
* @throws FeaturestoreException
*/
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Create a new storage connector for the feature store", response = FeaturestoreStorageConnectorDTO.class)
public Response createNewStorageConnector(@Context SecurityContext sc, FeaturestoreStorageConnectorDTO featurestoreStorageConnectorDTO) throws FeaturestoreException, UserException, ProjectException {
if (featurestoreStorageConnectorDTO == null) {
throw new IllegalArgumentException("Input JSON for creating a new Feature Store Storage Connector Cannot be " + "null");
}
Users user = jWTHelper.getUserPrincipal(sc);
FeaturestoreStorageConnectorDTO createdFeaturestoreStorageConnectorDTO = storageConnectorController.createStorageConnector(user, project, featurestore, featurestoreStorageConnectorDTO);
GenericEntity<FeaturestoreStorageConnectorDTO> featurestoreStorageConnectorDTOGenericEntity = new GenericEntity<FeaturestoreStorageConnectorDTO>(createdFeaturestoreStorageConnectorDTO) {
};
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.CREATED).entity(featurestoreStorageConnectorDTOGenericEntity).build();
}
Aggregations