Skip to content
Snippets Groups Projects
Commit aae951a0 authored by Zachary Sabourin's avatar Zachary Sabourin
Browse files

Merge branch 'zacharysabourin/main/134' into 'main'

feat: Standardize configs

See merge request !149
parents 082c39d6 2571ca73
No related branches found
No related tags found
1 merge request!149feat: Standardize configs
Pipeline #30139 passed
Showing
with 191 additions and 75 deletions
eclipse.internal-host=localhost
## Required for authenticated requests to profile API (api.eclipse.org: git.eclipse.org/r/ (dev-git-eca-rest-api)))
## Ask webdev@eclipse-foundation.org if you think you should have access to this client.
oauth2.client-id=
oauth2.client-secret=
eclipse.security.oauth2.token-generation.client-id=
eclipse.security.oauth2.token-generation.client-secret=
## mariadb username and password
quarkus.datasource.username=
......@@ -10,4 +10,6 @@ quarkus.datasource.password=
## database connection
quarkus.datasource.jdbc.url=jdbc:mariadb://mariadb/dev_eclipse_eca
%dev.quarkus.datasource.jdbc.url=jdbc:mariadb://${eclipse.internal-host}:10101/dev_eclipse_eca
\ No newline at end of file
%dev.quarkus.datasource.jdbc.url=jdbc:mariadb://${eclipse.internal-host}:10101/dev_eclipse_eca
eclipse.gitlab.access-token=
\ No newline at end of file
......@@ -5,7 +5,7 @@
<artifactId>git-eca</artifactId>
<version>1.1.0</version>
<properties>
<eclipse-api-version>0.7.6</eclipse-api-version>
<eclipse-api-version>0.7.7</eclipse-api-version>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
......@@ -14,7 +14,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>2.16.3.Final</quarkus.platform.version>
<quarkus.platform.version>2.16.7.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
<auto-value.version>1.8.2</auto-value.version>
<org.mapstruct.version>1.4.1.Final</org.mapstruct.version>
......
/*********************************************************************
* Copyright (c) 2023 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.git.eca.config;
import java.util.List;
import io.smallrye.config.ConfigMapping;
/**
* Captures all configs related to eca reports. Includes resource access key and list of allowed users.
*/
@ConfigMapping(prefix = "eclipse.git-eca.reports")
public interface EcaReportsConfig {
String accessKey();
List<String> allowedUsers();
}
/*********************************************************************
* Copyright (c) 2023 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.git.eca.config;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
/**
* Captures all configs related to hcaptcha. Includes enabled flag, site key, and secret.
*/
@ConfigMapping(prefix = "eclipse.hcaptcha")
public interface HcaptchaConfig {
@WithDefault("true")
boolean enabled();
String siteKey();
String secret();
}
/*********************************************************************
* Copyright (c) 2023 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.git.eca.config;
import java.util.List;
import io.smallrye.config.ConfigMapping;
/**
* Captures all configs related to mail validation. Includesan allow list and a list of no-reply email patterns.
*/
@ConfigMapping(prefix = "eclipse.git-eca.mail-validation")
public interface MailValidationConfig {
public List<String> allowList();
public List<String> noreplyEmailPatterns();
}
/*********************************************************************
* Copyright (c) 2023 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Zachary Sabourin <zachary.sabourin@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.git.eca.config;
import io.smallrye.config.ConfigMapping;
/**
* Captures all configs related to webhooks. Includes github configs such as server target and request context.
*/
@ConfigMapping(prefix = "eclipse.webhooks")
public interface WebhooksConfig {
GithubWebhooksDefinition github();
interface GithubWebhooksDefinition {
String context();
String serverTarget();
}
}
......@@ -16,12 +16,13 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.eclipsefoundation.git.eca.api.HCaptchaCallbackAPI;
import org.eclipsefoundation.git.eca.config.HcaptchaConfig;
import org.eclipsefoundation.git.eca.namespace.HCaptchaErrorCodes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -36,12 +37,8 @@ import org.slf4j.LoggerFactory;
public class CaptchaHelper {
private static final Logger LOGGER = LoggerFactory.getLogger(CaptchaHelper.class);
@ConfigProperty(name = "eclipse.hcaptcha.enabled", defaultValue = "true")
boolean isEnabled;
@ConfigProperty(name = "eclipse.hcaptcha.sitekey")
String siteKey;
@ConfigProperty(name = "eclipse.hcaptcha.secret")
String captchaSecret;
@Inject
HcaptchaConfig config;
@RestClient
HCaptchaCallbackAPI hcaptchaApi;
......@@ -54,7 +51,7 @@ public class CaptchaHelper {
*/
public List<HCaptchaErrorCodes> validateCaptchaResponse(String response) {
// allow for disabling the captcha in case there are service issues, or in testing
if (!isEnabled) {
if (!config.enabled()) {
LOGGER.trace("Captcha validation is currently disabled, skipping captcha check");
return Collections.emptyList();
} else if (StringUtils.isBlank(response)) {
......@@ -63,7 +60,8 @@ public class CaptchaHelper {
}
// validate the hcaptcha response with the site API, passing the secret and response
return Optional
.ofNullable(hcaptchaApi.validateCaptchaRequest(response, captchaSecret, siteKey).getErrorCodes())
.ofNullable(
hcaptchaApi.validateCaptchaRequest(response, config.secret(), config.siteKey()).getErrorCodes())
.orElse(Collections.emptyList());
}
}
......@@ -35,6 +35,7 @@ import org.eclipsefoundation.git.eca.api.models.GithubCommit.ParentCommit;
import org.eclipsefoundation.git.eca.api.models.GithubCommitStatusRequest;
import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest;
import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.PullRequest;
import org.eclipsefoundation.git.eca.config.WebhooksConfig;
import org.eclipsefoundation.git.eca.dto.GithubWebhookTracking;
import org.eclipsefoundation.git.eca.helper.JwtHelper;
import org.eclipsefoundation.git.eca.model.Commit;
......@@ -64,13 +65,12 @@ public abstract class GithubAdjacentResource {
private static final String VALIDATION_LOGGING_MESSAGE = "Setting validation state for {}/#{} to {}";
@ConfigProperty(name = "eclipse.webhooks.github.context")
String context;
@ConfigProperty(name = "eclipse.webhooks.github.server-target")
String serverTarget;
@ConfigProperty(name = "eclipse.github.default-api-version", defaultValue = "2022-11-28")
String apiVersion;
@Inject
WebhooksConfig webhooksConfig;
@Inject
JwtHelper jwtHelper;
@Inject
......@@ -268,9 +268,9 @@ public abstract class GithubAdjacentResource {
.builder()
.setDescription(state.getMessage())
.setState(state.toString())
.setTargetUrl(serverTarget + "/git/eca/status/gh/" + request.getRepository().getFullName() + '/'
.setTargetUrl(webhooksConfig.github().serverTarget() + "/git/eca/status/gh/" + request.getRepository().getFullName() + '/'
+ request.getPullRequest().getNumber())
.setContext(context)
.setContext(webhooksConfig.github().context())
.build());
}
......
......@@ -21,8 +21,8 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipsefoundation.core.model.RequestWrapper;
import org.eclipsefoundation.git.eca.config.EcaReportsConfig;
import org.eclipsefoundation.git.eca.namespace.GitEcaParameterNames;
import org.eclipsefoundation.git.eca.service.ReportsService;
import org.slf4j.Logger;
......@@ -32,8 +32,8 @@ import org.slf4j.LoggerFactory;
public class ReportsResource {
private static final Logger LOGGER = LoggerFactory.getLogger(ReportsResource.class);
@ConfigProperty(name = "eclipse.reports.access-key")
String key;
@Inject
EcaReportsConfig config;
@Inject
RequestWrapper wrap;
......@@ -44,7 +44,7 @@ public class ReportsResource {
@Path("/gitlab/private-projects")
public Response getPrivateProjectEvents(@QueryParam("key") String passedKey, @QueryParam("status") String status,
@QueryParam("since") LocalDate since, @QueryParam("until") LocalDate until) {
if (!key.equals(passedKey)) {
if (!config.accessKey().equals(passedKey)) {
LOGGER.debug("Bad key passed for access, access blocked");
return Response.status(401).build();
}
......
......@@ -25,7 +25,6 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipsefoundation.core.model.RequestWrapper;
import org.eclipsefoundation.core.service.CachingService;
import org.eclipsefoundation.git.eca.api.models.EclipseUser;
......@@ -52,13 +51,6 @@ 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;
@Inject
@ConfigProperty(name = "eclipse.noreply.email-patterns")
List<String> emailPatterns;
@Inject
RequestWrapper wrapper;
......
......@@ -25,7 +25,6 @@ import javax.inject.Inject;
import javax.ws.rs.WebApplicationException;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.eclipsefoundation.core.service.CachingService;
import org.eclipsefoundation.efservices.api.models.Project;
......@@ -33,6 +32,7 @@ import org.eclipsefoundation.efservices.services.DrupalTokenService;
import org.eclipsefoundation.git.eca.api.AccountsAPI;
import org.eclipsefoundation.git.eca.api.BotsAPI;
import org.eclipsefoundation.git.eca.api.models.EclipseUser;
import org.eclipsefoundation.git.eca.config.MailValidationConfig;
import org.eclipsefoundation.git.eca.service.UserService;
import org.jboss.resteasy.specimpl.MultivaluedMapImpl;
import org.slf4j.Logger;
......@@ -51,8 +51,7 @@ public class CachedUserService implements UserService {
private static final Logger LOGGER = LoggerFactory.getLogger(CachedUserService.class);
@Inject
@ConfigProperty(name = "eclipse.noreply.email-patterns")
List<String> emailPatterns;
MailValidationConfig config;
// eclipse API rest client interfaces
@Inject
......@@ -73,7 +72,7 @@ public class CachedUserService implements UserService {
@PostConstruct
void init() {
// compile the patterns once per object to save processing time
this.patterns = emailPatterns.stream().map(Pattern::compile).collect(Collectors.toList());
this.patterns = config.noreplyEmailPatterns().stream().map(Pattern::compile).collect(Collectors.toList());
}
@Override
......
......@@ -24,12 +24,12 @@ import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipsefoundation.core.helper.DateTimeHelper;
import org.eclipsefoundation.core.model.RequestWrapper;
import org.eclipsefoundation.core.service.CachingService;
import org.eclipsefoundation.efservices.api.models.Project;
import org.eclipsefoundation.git.eca.api.models.EclipseUser;
import org.eclipsefoundation.git.eca.config.MailValidationConfig;
import org.eclipsefoundation.git.eca.dto.CommitValidationMessage;
import org.eclipsefoundation.git.eca.dto.CommitValidationStatus;
import org.eclipsefoundation.git.eca.dto.CommitValidationStatusGrouping;
......@@ -61,8 +61,8 @@ import org.slf4j.LoggerFactory;
public class DefaultValidationService implements ValidationService {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultValidationService.class);
@ConfigProperty(name = "eclipse.mail.allowlist")
List<String> allowListUsers;
@Inject
MailValidationConfig config;
@Inject
ProjectHelper projects;
......@@ -413,7 +413,7 @@ public class DefaultValidationService implements ValidationService {
* @return true if user email is in allow list, false otherwise
*/
private boolean isAllowedUser(String mail) {
return StringUtils.isNotBlank(mail) && allowListUsers.indexOf(mail) != -1;
return StringUtils.isNotBlank(mail) && config.allowList().indexOf(mail) != -1;
}
/**
......
quarkus.rest-client."org.eclipsefoundation.git.eca.api.AccountsAPI".scope=javax.enterprise.context.ApplicationScoped
quarkus.rest-client."org.eclipsefoundation.git.eca.api.AccountsAPI".url=https://api.eclipse.org
projects-api/mp-rest/url=https://projects.eclipse.org
org.eclipsefoundation.git.eca.api.BotsAPI/mp-rest/url=https://api.eclipse.org
quarkus.rest-client."org.eclipsefoundation.git.eca.api.GitlabAPI".url=https://gitlab.eclipse.org/api/v4/
eclipse.noreply.email-patterns=@users.noreply.github.com\$,@noreply.github.com\$
## Base HTTP settings
## Base Quarkus HTTP settings
quarkus.http.enable-compression=true
quarkus.http.port=8080
## Expect to be mounted to '/git' to match current URL spec
quarkus.http.root-path=/git
## RestClient configs
org.eclipsefoundation.git.eca.api.AccountsAPI/mp-rest/url=https://api.eclipse.org
projects-api/mp-rest/url=https://projects.eclipse.org
org.eclipsefoundation.git.eca.api.BotsAPI/mp-rest/url=https://api.eclipse.org
org.eclipsefoundation.git.eca.api.GitlabAPI/mp-rest/url=https://gitlab.eclipse.org/api/v4/
## DATASOURCE CONFIG
eclipse.db.default.limit=10
eclipse.db.default.limit.max=100
eclipse.persistence.pagination-limit=10
eclipse.persistence.pagination-limit.max=100
quarkus.datasource.db-kind=mariadb
quarkus.datasource.jdbc.min-size = 5
quarkus.datasource.jdbc.max-size = 15
......@@ -23,13 +20,12 @@ quarkus.datasource.jdbc.max-size = 15
quarkus.hibernate-orm.packages=org.eclipsefoundation.git.eca.dto
quarkus.hibernate-orm.datasource=<default>
## OAUTH CONFIG
## Security configs
quarkus.oauth2.enabled=false
quarkus.oidc.enabled=false
oauth2.scope=eclipsefdn_view_all_profiles
oauth2.client-id=placeholder
oauth2.client-secret=placeholder
eclipse.reports.allowed-users=mbarbaro,webdev
eclipse.security.oauth2.token-generation.scope=eclipsefdn_view_all_profiles
eclipse.security.oauth2.token-generation.client-id=placeholder
eclipse.security.oauth2.token-generation.client-secret=placeholder
## CACHE SETTINGS
eclipse.cache.loading."projects".timeout=10
......@@ -47,9 +43,17 @@ quarkus.cache.caffeine."accesstoken".expire-after-write=119S
## JWT Placeholders/defaults
smallrye.jwt.new-token.lifespan=120
smallrye.jwt.new-token.issuer=262450
## Webhook configs
eclipse.webhooks.github.context=eclipsefdn/eca
eclipse.webhooks.github.server-target=https://api.eclipse.org
eclipse.mail.allowlist=noreply@github.com,49699333+dependabot[bot]@users.noreply.github.com,bot@stepsecurity.io
## Git-eca mail configs
eclipse.git-eca.mail-validation.allow-list=noreply@github.com,49699333+dependabot[bot]@users.noreply.github.com,bot@stepsecurity.io
eclipse.git-eca.mail-validation.noreply-email-patterns=@users.noreply.github.com\$,@noreply.github.com\$
## Reports configs
eclipse.git-eca.reports.allowed-users=mbarbaro,webdev
## Misc
eclipse.system-hook.pool-size=5
......@@ -56,7 +56,8 @@ class ReportsResourceTest {
SchemaNamespaceHelper.PRIVATE_PROJECT_EVENTS_SCHEMA_PATH);
public static final EndpointTestCase GET_REPORT_RANGE_SUCCESS_CASE = TestCaseHelper
.buildSuccessCase(REPORTS_PROJECTS_RANGE_URL, new String[] { VALID_TEST_ACCESS_KEY, "2022-11-15", "2022-11-15" },
.buildSuccessCase(REPORTS_PROJECTS_RANGE_URL,
new String[] { VALID_TEST_ACCESS_KEY, "2022-11-15", "2022-11-15" },
SchemaNamespaceHelper.PRIVATE_PROJECT_EVENTS_SCHEMA_PATH);
public static final EndpointTestCase GET_REPORT_BAD_ACCESS_KEY = EndpointTestCase
......@@ -97,10 +98,13 @@ class ReportsResourceTest {
}
@Test
void getPrivProjReport_failure_invalidRequestFormat() {
void getPrivProjReport_failure_invalidResponseFormat() {
RestAssuredTemplates
.testGet(TestCaseHelper
.buildInvalidFormatCase(REPORTS_PROJECTS_URL, new String[] { VALID_TEST_ACCESS_KEY }, ContentType.TEXT));
.prepareTestCase(REPORTS_PROJECTS_URL, new String[] { VALID_TEST_ACCESS_KEY }, null)
.setResponseContentType(ContentType.TEXT)
.setStatusCode(500)
.build());
}
@Test
......
## Quarkus configs
quarkus.http.root-path=/git
quarkus.http.port=8080
quarkus.jacoco.includes=**/git/eca/**/*
## Prevents test profile from pulling docker images for testing
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
eclipse.noreply.email-patterns=@users.noreply.github.com\$,@noreply.github.com\$
eclipse.mail.allowlist=noreply@github.com
eclipse.reports.access-key=samplekey
eclipse.gitlab.access-token=token_val
## DATASOURCE CONFIG
quarkus.datasource.db-kind=h2
eclipse.db.default.limit=25
eclipse.db.default.limit.max=100
eclipse.persistence.pagination-limit=25
eclipse.persistence.pagination-limit.max=100
quarkus.hibernate-orm.database.generation=none
# Flyway configuration for the default datasource
quarkus.flyway.locations=classpath:database/default
quarkus.flyway.migrate-at-start=true
## Expect to be mounted to '/git' to match current URL spec
quarkus.http.root-path=/git
quarkus.http.port=8080
## OIDC Connection/Authentication Info
quarkus.oidc.enabled=false
quarkus.keycloak.devservices.enabled=false
quarkus.oidc-client.enabled=false
smallrye.jwt.sign.key.location=test.pem
# hCaptcha test key and secret
eclipse.hcaptcha.sitekey=20000000-ffff-ffff-ffff-000000000002
eclipse.hcaptcha.secret=0x0000000000000000000000000000000000000000
\ No newline at end of file
eclipse.hcaptcha.site-key=20000000-ffff-ffff-ffff-000000000002
eclipse.hcaptcha.secret=0x0000000000000000000000000000000000000000
## Git-eca mail configs
eclipse.git-eca.mail.noreply-email-patterns=@users.noreply.github.com\$,@noreply.github.com\$
eclipse.git-eca.mail.allow-list=noreply@github.com
## Reports configs
eclipse.git-eca.reports.access-key=samplekey
## Misc
eclipse.gitlab.access-token=token_val
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment