Commit 828d1903 authored by Martin Lowe's avatar Martin Lowe 🇨🇦 Committed by Martin Lowe
Browse files

Add whitelist to config, validation response logic

parent 050a50d3
......@@ -23,6 +23,7 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.eclipsefoundation.git.eca.api.AccountsAPI;
import org.eclipsefoundation.git.eca.api.BotsAPI;
......@@ -56,6 +57,10 @@ import org.slf4j.LoggerFactory;
public class ValidationResource {
private static final Logger LOGGER = LoggerFactory.getLogger(ValidationResource.class);
@Inject
@ConfigProperty(name = "eclipse.mail.whitelist")
List<String> whitelistedUsers;
// eclipse API rest client interfaces
@Inject @RestClient AccountsAPI accounts;
@Inject @RestClient BotsAPI bots;
......@@ -180,7 +185,16 @@ public class ValidationResource {
// retrieve the eclipse account for the committer
EclipseUser eclipseCommitter = getIdentifiedUser(committer);
if (eclipseCommitter == null) {
if (!userIsABot(committer.getMail(), provider)) {
// check if whitelisted or bot
if (isWhitelistedUser(committer.getMail())) {
addMessage(
response,
String.format(
"Automated user '%1$s' detected for committer of commit %2$s",
committer.getMail(), c.getHash()),
c.getHash());
eclipseCommitter = EclipseUser.createBotStub(committer);
} else if (!userIsABot(committer.getMail(), provider)) {
addMessage(
response,
String.format(
......@@ -319,6 +333,10 @@ public class ValidationResource {
});
}
private boolean isWhitelistedUser(String mail) {
return whitelistedUsers.indexOf(mail) != -1;
}
/**
* Retrieves projects valid for the current request, or an empty list if no data or matching
* project repos could be found.
......
......@@ -11,4 +11,6 @@ quarkus.http.port=8080
## required to start when secret.properties isn't found/mounted
oauth2.client-id=placeholder
oauth2.client-secret=placeholder
\ No newline at end of file
oauth2.client-secret=placeholder
eclipse.mail.whitelist=noreply@github.com
\ No newline at end of file
org.eclipsefoundation.git.eca.api.AccountsAPI/mp-rest/url=https://api.eclipse.org
org.eclipsefoundation.git.eca.api.ProjectsAPI/mp-rest/url=https://projects.eclipse.org
org.eclipsefoundation.git.eca.api.BotsAPI/mp-rest/url=https://api.eclipse.org
## Expect to be mounted to '/git' to match current URL spec
quarkus.http.root-path=/git
## OAUTH CONFIG
oauth2.scope=eclipsefdn_view_all_profiles
quarkus.http.port=8080
## required to start when secret.properties isn't found/mounted
oauth2.client-id=placeholder
oauth2.client-secret=placeholder
quarkus.log.level=DEBUG
eclipse.mail.whitelist=noreply@github.com
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment