Add env test

This commit is contained in:
2025-12-02 16:45:56 +01:00
parent 8b7bf1ecde
commit 60f04f1aa8
5 changed files with 81 additions and 3 deletions

View File

@@ -0,0 +1,31 @@
package com.imgfloat.app.config;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@Component
public class TwitchCredentialsValidator {
private final String clientId;
private final String clientSecret;
public TwitchCredentialsValidator(
@Value("${spring.security.oauth2.client.registration.twitch.client-id}") String clientId,
@Value("${spring.security.oauth2.client.registration.twitch.client-secret}") String clientSecret) {
this.clientId = clientId;
this.clientSecret = clientSecret;
}
@PostConstruct
void validate() {
ensurePresent(clientId, "TWITCH_CLIENT_ID");
ensurePresent(clientSecret, "TWITCH_CLIENT_SECRET");
}
private void ensurePresent(String value, String name) {
if (!StringUtils.hasText(value) || "changeme".equalsIgnoreCase(value.trim())) {
throw new IllegalStateException(name + " must be set in the environment or .env file");
}
}
}