Check service configurations in verify phase

This commit is contained in:
Chris Eager 2021-11-08 20:51:13 -08:00 committed by Chris Eager
parent ab9e6ac48a
commit 26f876a2cb
2 changed files with 78 additions and 0 deletions

View File

@ -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>

View File

@ -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);
}
}