code format

This commit is contained in:
Alfredo Oliviero 2024-02-26 10:05:14 +01:00
parent c9d0281691
commit 914197e3f2
6 changed files with 33 additions and 32 deletions

View File

@ -5,4 +5,4 @@ description: HelloWorld Service
excludes:
- path: /excluded
- path: /guest
- path: /api-docs/*
- path: /api-docs/*

View File

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>Hello World</display-name>
<description>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>Hello World</display-name>
<description>
A gcube HelloWorld service - smartgears 4
</description>
<servlet>
@ -15,4 +14,4 @@
<servlet-name>org.gcube.service.helloworld.HelloWorld</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
</web-app>

View File

@ -9,9 +9,10 @@ import org.gcube.common.health.api.response.HealthCheckResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
/**
*
* this class is used to add checks about components used by the service (DB, external FS, other services etc. )
* this class is used to add checks about components used by the service (DB,
* external FS, other services etc. )
* and automatically exposed using the REST method webapp/gcube/resources/health
*
*
@ -20,11 +21,10 @@ import org.slf4j.LoggerFactory;
*/
@ReadinessChecker
public class CreateTempFileCheck implements HealthCheck{
public class CreateTempFileCheck implements HealthCheck {
private static Logger log = LoggerFactory.getLogger(CreateTempFileCheck.class);
@Override
public String getName() {
return "create temp file";
@ -33,13 +33,13 @@ public class CreateTempFileCheck implements HealthCheck{
@Override
public HealthCheckResponse check() {
try {
File.createTempFile("exampleTest","txt");
File.createTempFile("exampleTest", "txt");
return HealthCheckResponse.builder(getName()).up().info("health check example").build();
} catch (IOException e) {
log.error("error checking defaultStorage",e);
return HealthCheckResponse.builder(getName()).down().error(e.getMessage()).build();
}
log.error("error checking defaultStorage", e);
return HealthCheckResponse.builder(getName()).down().error(e.getMessage()).build();
}
}
}

View File

@ -24,7 +24,7 @@ public class HelloWorldManager implements ApplicationManager {
Logger logger = LoggerFactory.getLogger(HelloWorldManager.class);
@Override
public void onInit() {
public void onInit() {
if (ContextProvider.get().container().configuration().mode() == Mode.offline) {
logger.debug("init called in offline mode");
} else {

View File

@ -32,7 +32,8 @@ public class AuthenticatedService {
String userId = secret.getOwner().getId();
String context = secret.getContext();
return String.format(
"User %s in context %s is authorized to execute this method because he has the role %s", userId, context, ALLOWED_ROLE_ORG);
"User %s in context %s is authorized to execute this method because he has the role %s", userId,
context, ALLOWED_ROLE_ORG);
}
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE_MEMBER })
@ -45,10 +46,10 @@ public class AuthenticatedService {
String userId = secret.getOwner().getId();
String context = secret.getContext();
return String.format(
"User %s in context %s is authorized to execute this method because he has the role %s", userId, context, ALLOWED_ROLE_MEMBER);
"User %s in context %s is authorized to execute this method because he has the role %s", userId,
context, ALLOWED_ROLE_MEMBER);
}
@AuthorizationControl(allowedRoles = { ALLOWED_ROLE })
@GET
@Path("")
@ -59,7 +60,8 @@ public class AuthenticatedService {
String userId = secret.getOwner().getId();
String context = secret.getContext();
return String.format(
"User %s in context %s is authorized to execute this method because he has the role %s", userId, context, ALLOWED_ROLE);
"User %s in context %s is authorized to execute this method because he has the role %s", userId,
context, ALLOWED_ROLE);
}
}

View File

@ -8,20 +8,20 @@ import org.slf4j.LoggerFactory;
@Path("guest")
public class ExcludeAuthorizationService {
private final Logger logger = LoggerFactory.getLogger(ExcludeAuthorizationService.class);
private final Logger logger = LoggerFactory.getLogger(ExcludeAuthorizationService.class);
/**
* this method doesn't need authorization and the SecretManagerProvider is null
* see to implement this behavior add to excludes section in your application.yaml
* see to implement this behavior add to excludes section in your
* application.yaml
*
* - path: /{path-to-your-method-path}
*
* example for this method
*
* - path: /excluded
*
* - path: /{path-to-your-method-path}
*
* example for this method
*
* - path: /excluded
*
*/
@GET
public String exludedMethod() {