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:
@@ -5,6 +5,8 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val artefactVersion: String by project
|
val artefactVersion: String by project
|
||||||
|
val buildChannel: String by project
|
||||||
|
val vendor: String by project
|
||||||
|
|
||||||
group = "com.onixbyte.helix"
|
group = "com.onixbyte.helix"
|
||||||
version = artefactVersion
|
version = artefactVersion
|
||||||
@@ -61,6 +63,16 @@ dependencies {
|
|||||||
testRuntimeOnly(libs.junit.launcher)
|
testRuntimeOnly(libs.junit.launcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.processResources {
|
||||||
|
filesMatching("application.yaml") {
|
||||||
|
expand(
|
||||||
|
"appVersion" to artefactVersion,
|
||||||
|
"channel" to buildChannel,
|
||||||
|
"vendor" to vendor
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tasks.test {
|
tasks.test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.onixbyte.deltaforceguide.config;
|
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.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(WebhookProperties.class)
|
@EnableConfigurationProperties({GitHubWebhookProperties.class})
|
||||||
public class WebhookConfig {
|
public class WebhookConfig {
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -48,7 +48,7 @@ public class GitHubWebhookInterceptor implements HandlerInterceptor {
|
|||||||
"Request body is not readable");
|
"Request body is not readable");
|
||||||
}
|
}
|
||||||
|
|
||||||
var secret = webhookManager.github().secret();
|
var secret = webhookManager.secret();
|
||||||
if (secret == null || secret.isBlank()) {
|
if (secret == null || secret.isBlank()) {
|
||||||
log.debug("No GitHub webhook secret configured, skipping signature verification");
|
log.debug("No GitHub webhook secret configured, skipping signature verification");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ public class AppManager {
|
|||||||
* @return the version string of this application
|
* @return the version string of this application
|
||||||
*/
|
*/
|
||||||
public String getVersion() {
|
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;
|
package com.onixbyte.deltaforceguide.manager;
|
||||||
|
|
||||||
import com.onixbyte.deltaforceguide.properties.GitHubWebhookProperties;
|
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 org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class WebhookManager {
|
public class WebhookManager {
|
||||||
|
|
||||||
private final WebhookProperties webhookProperties;
|
private final GitHubWebhookProperties gitHubWebhookProperties;
|
||||||
|
|
||||||
@Autowired
|
public WebhookManager(GitHubWebhookProperties gitHubWebhookProperties) {
|
||||||
public WebhookManager(WebhookProperties webhookProperties) {
|
this.gitHubWebhookProperties = gitHubWebhookProperties;
|
||||||
this.webhookProperties = webhookProperties;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GitHubWebhookProperties github() {
|
public String secret() {
|
||||||
return webhookProperties.github();
|
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")
|
@ConfigurationProperties(prefix = "app.common")
|
||||||
public record AppProperties(
|
public record AppProperties(
|
||||||
String version
|
String version,
|
||||||
|
String channel,
|
||||||
|
String vendor
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package com.onixbyte.deltaforceguide.properties;
|
package com.onixbyte.deltaforceguide.properties;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ConfigurationProperties(prefix = "app.webhook.github")
|
||||||
public record GitHubWebhookProperties(
|
public record GitHubWebhookProperties(
|
||||||
String secret,
|
String secret,
|
||||||
List<String> allowedUsers
|
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(
|
private boolean isAllowedSender(
|
||||||
GitHubWebhookSender sender
|
GitHubWebhookSender sender
|
||||||
) {
|
) {
|
||||||
var allowedUsers = webhookManager.github().allowedUsers();
|
var allowedUsers = webhookManager.allowedUsers();
|
||||||
if (allowedUsers == null || allowedUsers.isEmpty()) {
|
if (allowedUsers == null || allowedUsers.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,13 +39,13 @@ mybatis:
|
|||||||
type-handlers-package: com.onixbyte.deltaforceguide.mapper.handler
|
type-handlers-package: com.onixbyte.deltaforceguide.mapper.handler
|
||||||
mapper-locations: classpath:/mapper/*.xml
|
mapper-locations: classpath:/mapper/*.xml
|
||||||
|
|
||||||
app:
|
|
||||||
webhook:
|
|
||||||
github:
|
|
||||||
secret: ${GITHUB_WEBHOOK_SECRET:}
|
|
||||||
allowed-users: []
|
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
org.hibernate:
|
org.hibernate:
|
||||||
orm.connections.pooling: off
|
orm.connections.pooling: off
|
||||||
|
|
||||||
|
app:
|
||||||
|
common:
|
||||||
|
version: ${appVersion}
|
||||||
|
channel: ${channel}
|
||||||
|
vendor: ${vendor}
|
||||||
|
|||||||
Reference in New Issue
Block a user