Check service configurations in verify phase
This commit is contained in:
parent
ab9e6ac48a
commit
26f876a2cb
|
@ -593,6 +593,28 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>check-all-service-config</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>java</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<mainClass>org.whispersystems.textsecuregcm.CheckServiceConfigurations</mainClass>
|
||||
<classpathScope>test</classpathScope>
|
||||
<arguments>
|
||||
<argument>${project.basedir}/config</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright 2021 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Checks whether all YAML configuration files in a given directory are valid.
|
||||
* <p>
|
||||
* Note: the current implementation fails fast, rather than reporting multiple invalid files
|
||||
*/
|
||||
public class CheckServiceConfigurations {
|
||||
|
||||
private void checkConfiguration(final File configDirectory) {
|
||||
|
||||
final File[] configFiles = configDirectory.listFiles(f ->
|
||||
!f.isDirectory()
|
||||
&& f.getPath().endsWith(".yml"));
|
||||
|
||||
if (configFiles == null || configFiles.length == 0) {
|
||||
throw new IllegalArgumentException("No .yml configuration files found at " + configDirectory.getPath());
|
||||
}
|
||||
|
||||
for (File configFile : configFiles) {
|
||||
String[] args = new String[]{"check", configFile.getAbsolutePath()};
|
||||
|
||||
try {
|
||||
new WhisperServerService().run(args);
|
||||
} catch (final Exception e) {
|
||||
// Invalid configuration will cause the "check" command to call `System.exit()`, rather than throwing,
|
||||
// so this is unexpected
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
if (args.length != 1) {
|
||||
throw new IllegalArgumentException("Expected single argument with config directory: " + Arrays.toString(args));
|
||||
}
|
||||
|
||||
final File configDirectory = new File(args[0]);
|
||||
|
||||
if (!(configDirectory.exists() && configDirectory.isDirectory())) {
|
||||
throw new IllegalArgumentException("No directory found at " + configDirectory.getPath());
|
||||
}
|
||||
|
||||
new CheckServiceConfigurations().checkConfiguration(configDirectory);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue