-
Notifications
You must be signed in to change notification settings - Fork 49
Read env vars for server name and env name #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -360,4 +360,9 @@ public Properties getPropertiesForGroup(String group) { | |||||||||||||||||||
| public abstract void setChannelTags(Set<ChannelTag> tags); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| public abstract Set<ChannelTag> getChannelTags(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Update server settings based on environment variables. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| public abstract void updateServerSettingsFromEnvironment(); | ||||||||||||||||||||
|
Comment on lines
+366
to
+367
|
||||||||||||||||||||
| */ | |
| public abstract void updateServerSettingsFromEnvironment(); | |
| * <p> | |
| * Default implementation is a no-op to preserve backward compatibility for | |
| * existing ConfigurationController implementations. | |
| */ | |
| public void updateServerSettingsFromEnvironment() { | |
| // No-op by default. | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |||||||
| import java.util.Locale; | ||||||||
| import java.util.Map; | ||||||||
| import java.util.Map.Entry; | ||||||||
| import java.util.Optional; | ||||||||
| import java.util.Properties; | ||||||||
| import java.util.Set; | ||||||||
| import java.util.SortedMap; | ||||||||
|
|
@@ -75,7 +76,6 @@ | |||||||
| import org.apache.ibatis.session.SqlSessionManager; | ||||||||
| import org.apache.logging.log4j.LogManager; | ||||||||
| import org.apache.logging.log4j.Logger; | ||||||||
| import org.bouncycastle.asn1.ASN1Sequence; | ||||||||
| import org.bouncycastle.asn1.x500.X500Name; | ||||||||
| import org.bouncycastle.asn1.x509.AuthorityKeyIdentifier; | ||||||||
| import org.bouncycastle.asn1.x509.BasicConstraints; | ||||||||
|
|
@@ -1704,4 +1704,38 @@ public ConnectionTestResponse sendTestEmail(Properties properties) throws Except | |||||||
| return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, e.getMessage()); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| @Override | ||||||||
| public void updateServerSettingsFromEnvironment() { | ||||||||
| Optional<String> newServerName = getEnvironmentVariable("MC_SERVER_NAME"); | ||||||||
| Optional<String> newEnvName = getEnvironmentVariable("MC_ENV_NAME"); | ||||||||
|
|
||||||||
| if (newServerName.isPresent() || newEnvName.isPresent()) { | ||||||||
| try { | ||||||||
| ServerSettings serverSettings = getServerSettings(); | ||||||||
|
|
||||||||
| if (newServerName.isPresent()) { | ||||||||
| serverSettings.setServerName(newServerName.get()); | ||||||||
| } | ||||||||
| if (newEnvName.isPresent()) { | ||||||||
| serverSettings.setEnvironmentName(newEnvName.get()); | ||||||||
| } | ||||||||
|
|
||||||||
| setServerSettings(serverSettings); | ||||||||
|
Comment on lines
+1709
to
+1724
|
||||||||
| } catch (ControllerException e) { | ||||||||
|
Comment on lines
+1713
to
+1725
|
||||||||
| logger.error("Failed to update server settings via environment variables", e); | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Pull an environment variable. Values are trimmed, and only non-empty values are returned. | ||||||||
| * | ||||||||
| * @param envName the environment variable name | ||||||||
| * @return the property's value | ||||||||
|
||||||||
| * @return the property's value | |
| * @return an {@link Optional} containing the trimmed environment variable value if present and non-blank; | |
| * otherwise {@link Optional#empty()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This startup call can throw AbstractMethodError at runtime if an extension supplies a custom ConfigurationController compiled against an older version (missing updateServerSettingsFromEnvironment). Either ensure the base class provides a default implementation, or guard this call (e.g., catch AbstractMethodError) so third-party controllers don’t prevent server startup.