mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Add env test
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ server:
|
||||
key-store-type: ${SSL_KEYSTORE_TYPE:PKCS12}
|
||||
|
||||
spring:
|
||||
config:
|
||||
import: optional:file:.env[.properties]
|
||||
application:
|
||||
name: imgfloat
|
||||
thymeleaf:
|
||||
@@ -16,8 +18,8 @@ spring:
|
||||
client:
|
||||
registration:
|
||||
twitch:
|
||||
client-id: ${TWITCH_CLIENT_ID:changeme}
|
||||
client-secret: ${TWITCH_CLIENT_SECRET:changeme}
|
||||
client-id: ${TWITCH_CLIENT_ID}
|
||||
client-secret: ${TWITCH_CLIENT_SECRET}
|
||||
redirect-uri: "{baseUrl}/login/oauth2/code/twitch"
|
||||
authorization-grant-type: authorization_code
|
||||
scope: ["user:read:email"]
|
||||
|
||||
Reference in New Issue
Block a user