Skip to content
Snippets Groups Projects

Add whitelist to config, validation response logic

Merged Martin Lowe requested to merge github/fork/autumnfound/malowe/master/56 into master
3 files
+ 42
3
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -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.allowlist")
List<String> allowListUsers;
// 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 (isAllowedUser(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 isAllowedUser(String mail) {
return allowListUsers.indexOf(mail) != -1;
}
/**
* Retrieves projects valid for the current request, or an empty list if no data or matching
* project repos could be found.
Loading