1
|
package eu.dnetlib.uoaorcidservice.controllers;
|
2
|
|
3
|
import com.mongodb.BasicDBObject;
|
4
|
import com.mongodb.CommandResult;
|
5
|
import com.mongodb.DBObject;
|
6
|
import eu.dnetlib.uoaorcidservice.configuration.mongo.MongoConnection;
|
7
|
import eu.dnetlib.uoaorcidservice.configuration.properties.MongoConfig;
|
8
|
import eu.dnetlib.uoaorcidservice.configuration.properties.OrcidConfig;
|
9
|
import eu.dnetlib.uoaorcidservice.handlers.utils.AESUtils;
|
10
|
import org.apache.log4j.Logger;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
13
|
import org.springframework.security.access.prepost.PreAuthorize;
|
14
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
15
|
import org.springframework.web.bind.annotation.RequestMapping;
|
16
|
import org.springframework.web.bind.annotation.RequestMethod;
|
17
|
import org.springframework.web.bind.annotation.RestController;
|
18
|
|
19
|
import java.util.HashMap;
|
20
|
import java.util.Map;
|
21
|
|
22
|
@RestController
|
23
|
@CrossOrigin(origins = "*")
|
24
|
public class OrcidServiceCheckDeployController {
|
25
|
private final Logger log = Logger.getLogger(this.getClass());
|
26
|
|
27
|
@Autowired
|
28
|
private MongoConnection mongoConnection;
|
29
|
|
30
|
@Autowired
|
31
|
private MongoConfig mongoConfig;
|
32
|
|
33
|
@Autowired
|
34
|
private OrcidConfig orcidConfig;
|
35
|
|
36
|
@Autowired
|
37
|
private AESUtils aesUtils;
|
38
|
|
39
|
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
|
40
|
public String hello() {
|
41
|
log.debug("Hello from uoa-orcid-service!");
|
42
|
return "Hello from uoa-orcid-service!";
|
43
|
}
|
44
|
|
45
|
@PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
46
|
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
|
47
|
public Map<String, String> checkEverything() {
|
48
|
Map<String, String> response = new HashMap<>();
|
49
|
|
50
|
MongoTemplate mt = mongoConnection.getMongoTemplate();
|
51
|
DBObject ping = new BasicDBObject("ping", "1");
|
52
|
try {
|
53
|
CommandResult answer = mt.getDb().command(ping);
|
54
|
response.put("Mongo try: error", answer.getErrorMessage());
|
55
|
} catch (Exception e) {
|
56
|
response.put("Mongo catch: error", e.getMessage());
|
57
|
}
|
58
|
|
59
|
response.put("orcidservice.mongodb.database", mongoConfig.getDatabase());
|
60
|
response.put("orcidservice.mongodb.host", mongoConfig.getHost());
|
61
|
response.put("orcidservice.mongodb.port", mongoConfig.getPort()+"");
|
62
|
response.put("orcidservice.mongodb.username", mongoConfig.getUsername() == null ? null : "[unexposed value]");
|
63
|
response.put("orcidservice.mongodb.password", mongoConfig.getPassword() == null ? null : "[unexposed value]");
|
64
|
|
65
|
response.put("orcidservice.orcid.apiURL", orcidConfig.getApiURL());
|
66
|
response.put("orcidservice.orcid.tokenURL", orcidConfig.getTokenURL());
|
67
|
response.put("orcidservice.orcid.clientId", orcidConfig.getClientId() == null ? null : "[unexposed value]");
|
68
|
response.put("orcidservice.orcid.clientSecret", orcidConfig.getClientSecret() == null ? null : "[unexposed value]");
|
69
|
|
70
|
response.put("orcidservice.encryption.password", aesUtils.getPassword() == null ? null : "[unexposed value]");
|
71
|
|
72
|
return response;
|
73
|
}
|
74
|
}
|