feat: inject build-time variables via Gradle processResources
Replace hardcoded AppProperties values with Gradle ${} placeholders,
allowing version/channel/vendor to be configured via gradle.properties
or -P flags at build time.
Also refactor webhook configuration to flatten the properties hierarchy
by removing the intermediate WebhookProperties wrapper.
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package com.onixbyte.deltaforceguide.config;
|
||||
|
||||
import com.onixbyte.deltaforceguide.properties.WebhookProperties;
|
||||
import com.onixbyte.deltaforceguide.properties.GitHubWebhookProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(WebhookProperties.class)
|
||||
@EnableConfigurationProperties({GitHubWebhookProperties.class})
|
||||
public class WebhookConfig {
|
||||
}
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class GitHubWebhookInterceptor implements HandlerInterceptor {
|
||||
"Request body is not readable");
|
||||
}
|
||||
|
||||
var secret = webhookManager.github().secret();
|
||||
var secret = webhookManager.secret();
|
||||
if (secret == null || secret.isBlank()) {
|
||||
log.debug("No GitHub webhook secret configured, skipping signature verification");
|
||||
return true;
|
||||
|
||||
@@ -18,6 +18,10 @@ public class AppManager {
|
||||
* @return the version string of this application
|
||||
*/
|
||||
public String getVersion() {
|
||||
return appProperties.version();
|
||||
return "v%s-%s by @%s".formatted(
|
||||
appProperties.version(),
|
||||
appProperties.channel(),
|
||||
appProperties.vendor()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
package com.onixbyte.deltaforceguide.manager;
|
||||
|
||||
import com.onixbyte.deltaforceguide.properties.GitHubWebhookProperties;
|
||||
import com.onixbyte.deltaforceguide.properties.WebhookProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class WebhookManager {
|
||||
|
||||
private final WebhookProperties webhookProperties;
|
||||
private final GitHubWebhookProperties gitHubWebhookProperties;
|
||||
|
||||
@Autowired
|
||||
public WebhookManager(WebhookProperties webhookProperties) {
|
||||
this.webhookProperties = webhookProperties;
|
||||
public WebhookManager(GitHubWebhookProperties gitHubWebhookProperties) {
|
||||
this.gitHubWebhookProperties = gitHubWebhookProperties;
|
||||
}
|
||||
|
||||
public GitHubWebhookProperties github() {
|
||||
return webhookProperties.github();
|
||||
public String secret() {
|
||||
return gitHubWebhookProperties.secret();
|
||||
}
|
||||
|
||||
public List<String> allowedUsers() {
|
||||
return gitHubWebhookProperties.allowedUsers();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "app.common")
|
||||
public record AppProperties(
|
||||
String version
|
||||
String version,
|
||||
String channel,
|
||||
String vendor
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.onixbyte.deltaforceguide.properties;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ConfigurationProperties(prefix = "app.webhook.github")
|
||||
public record GitHubWebhookProperties(
|
||||
String secret,
|
||||
List<String> allowedUsers
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.onixbyte.deltaforceguide.properties;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "app.webhook")
|
||||
public record WebhookProperties(
|
||||
GitHubWebhookProperties github
|
||||
) {
|
||||
}
|
||||
@@ -172,7 +172,7 @@ public class WebhookService {
|
||||
private boolean isAllowedSender(
|
||||
GitHubWebhookSender sender
|
||||
) {
|
||||
var allowedUsers = webhookManager.github().allowedUsers();
|
||||
var allowedUsers = webhookManager.allowedUsers();
|
||||
if (allowedUsers == null || allowedUsers.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -39,13 +39,13 @@ mybatis:
|
||||
type-handlers-package: com.onixbyte.deltaforceguide.mapper.handler
|
||||
mapper-locations: classpath:/mapper/*.xml
|
||||
|
||||
app:
|
||||
webhook:
|
||||
github:
|
||||
secret: ${GITHUB_WEBHOOK_SECRET:}
|
||||
allowed-users: []
|
||||
|
||||
logging:
|
||||
level:
|
||||
org.hibernate:
|
||||
orm.connections.pooling: off
|
||||
|
||||
app:
|
||||
common:
|
||||
version: ${appVersion}
|
||||
channel: ${channel}
|
||||
vendor: ${vendor}
|
||||
|
||||
Reference in New Issue
Block a user