mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-23 12:18:04 +01:00
remove appconfig in favor of S3ObjectMonitor
This commit is contained in:
committed by
GitHub
parent
63021e0ca3
commit
0018e0bec6
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.configuration;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager;
|
||||
|
||||
import io.dropwizard.util.Resources;
|
||||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
|
||||
|
||||
@JsonTypeName("local")
|
||||
public class LocalDynamicConfigurationManagerFactory implements DynamicConfigurationManagerFactory {
|
||||
|
||||
@JsonProperty
|
||||
@NotEmpty
|
||||
private String application;
|
||||
|
||||
@JsonProperty
|
||||
@NotEmpty
|
||||
private String environment;
|
||||
|
||||
@JsonProperty
|
||||
@NotEmpty
|
||||
private String configuration;
|
||||
|
||||
@JsonProperty
|
||||
@NotBlank
|
||||
private String configPath;
|
||||
|
||||
@Override
|
||||
public <T> DynamicConfigurationManager<T> build(final Class<T> klazz,
|
||||
final ScheduledExecutorService scheduledExecutorService, final AwsCredentialsProvider awsCredentialsProvider) {
|
||||
|
||||
return new LocalDynamicConfigurationManager<>(configPath, application, environment, configuration,
|
||||
awsCredentialsProvider, klazz, scheduledExecutorService);
|
||||
}
|
||||
|
||||
private static class LocalDynamicConfigurationManager<T> extends DynamicConfigurationManager<T> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DynamicConfigurationManager.class);
|
||||
|
||||
private final Path configPath;
|
||||
private final Class<T> configurationClass;
|
||||
private T cachedConfig;
|
||||
private final Instant lastConfigLoadedTime;
|
||||
|
||||
public LocalDynamicConfigurationManager(final String configPath, final String application, final String environment,
|
||||
final String configurationName, final AwsCredentialsProvider awsCredentialsProvider,
|
||||
final Class<T> configurationClass, final ScheduledExecutorService scheduledExecutorService) {
|
||||
|
||||
super(application, environment, configurationName, awsCredentialsProvider, configurationClass,
|
||||
scheduledExecutorService);
|
||||
|
||||
this.configPath = Path.of(Resources.getResource("config").getPath()).resolve(configPath);
|
||||
this.configurationClass = configurationClass;
|
||||
this.cachedConfig = null;
|
||||
this.lastConfigLoadedTime = null;
|
||||
maybeUpdateConfig();
|
||||
if (cachedConfig == null) {
|
||||
throw new IllegalArgumentException("failed to load initial config");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getConfiguration() {
|
||||
maybeUpdateConfig();
|
||||
return cachedConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
private synchronized void maybeUpdateConfig() {
|
||||
try {
|
||||
if (lastConfigLoadedTime != null &&
|
||||
!lastConfigLoadedTime.isBefore(Files.readAttributes(configPath, BasicFileAttributes.class).lastModifiedTime().toInstant())) {
|
||||
return;
|
||||
}
|
||||
String configContents = Files.readString(configPath);
|
||||
parseConfiguration(configContents, configurationClass).ifPresent(config -> cachedConfig = config);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to update configuration", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import java.util.function.Consumer;
|
||||
public class StaticS3ObjectMonitorFactory implements S3ObjectMonitorFactory {
|
||||
|
||||
@JsonProperty
|
||||
private byte[] object = new byte[0];
|
||||
private String object = "";
|
||||
|
||||
@Override
|
||||
public S3ObjectMonitor build(final AwsCredentialsProvider awsCredentialsProvider,
|
||||
@@ -28,9 +28,9 @@ public class StaticS3ObjectMonitorFactory implements S3ObjectMonitorFactory {
|
||||
|
||||
private static class StaticS3ObjectMonitor extends S3ObjectMonitor {
|
||||
|
||||
private final byte[] object;
|
||||
private final String object;
|
||||
|
||||
public StaticS3ObjectMonitor(final byte[] object, final AwsCredentialsProvider awsCredentialsProvider) {
|
||||
public StaticS3ObjectMonitor(final String object, final AwsCredentialsProvider awsCredentialsProvider) {
|
||||
super(awsCredentialsProvider, "local-test-region", "test-bucket", null, 0L, null, null);
|
||||
|
||||
this.object = object;
|
||||
@@ -38,7 +38,7 @@ public class StaticS3ObjectMonitorFactory implements S3ObjectMonitorFactory {
|
||||
|
||||
@Override
|
||||
public synchronized void start(final Consumer<InputStream> changeListener) {
|
||||
changeListener.accept(new ByteArrayInputStream(object));
|
||||
changeListener.accept(new ByteArrayInputStream(object.getBytes()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user