Skip to content
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

Update config to accept environment variable #1101

Merged
merged 16 commits into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@

import io.quarkus.runtime.annotations.StaticInitSafe;
import io.smallrye.config.source.yaml.YamlConfigSource;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.ConfigSourceProvider;

/**
* Loading the YAML configuration file from the resource folder or env variable and making the
* config available to the application.
*/
@StaticInitSafe
public class EmbeddingConfigSourceProvider implements ConfigSourceProvider {
String configPath = System.getenv("EMBEDDING_CONFIG_PATH");

@Override
public Iterable<ConfigSource> getConfigSources(ClassLoader forClassLoader) {
try {
// Load the YAML files from environment variable
if (configPath != null && !configPath.isEmpty()) {
File file = new File(configPath);
if (!file.exists()) {
throw new RuntimeException(
"Config file does not exist at the path: " + file.getCanonicalPath());
}
URL fileUrl = file.toURI().toURL();
YamlConfigSource configSource = new YamlConfigSource(fileUrl);
return Collections.singletonList(configSource);
}
// Load the YAML files from src/main/resources/
URL resourceURL = forClassLoader.getResource("embedding-providers-config.yaml");
YamlConfigSource configSource = new YamlConfigSource(resourceURL);
return Collections.singletonList(configSource);
Expand Down