use of io.helidon.config.Config in project helidon by oracle.
the class DigestExampleConfigMain method main.
/**
* Starts this example. Loads configuration from src/main/resources/application.conf. See standard output for instructions.
*
* @param args ignored
*/
public static void main(String[] args) {
// load logging configuration
LogConfig.configureRuntime();
// load configuration
Config config = Config.create();
// build routing (security is loaded from config)
Routing routing = Routing.builder().register(WebSecurity.create(config.get("security"))).get("/{*}", (req, res) -> {
Optional<SecurityContext> securityContext = req.context().get(SecurityContext.class);
res.headers().contentType(MediaType.TEXT_PLAIN.withCharset("UTF-8"));
res.send("Hello, you are: \n" + securityContext.map(ctx -> ctx.user().orElse(SecurityContext.ANONYMOUS).toString()).orElse("Security context is null"));
}).build();
server = DigestExampleUtil.startServer(routing);
}
use of io.helidon.config.Config in project helidon by oracle.
the class VaultsExampleMain method main.
/**
* Start the server.
*
* @param args ignored
*/
public static void main(String[] args) {
LogConfig.configureRuntime();
// as I cannot share my configuration of OCI, let's combine the configuration
// from my home directory with the one compiled into the jar
// when running this example, you can either update the application.yaml in resources directory
// or use the same approach
Config config = buildConfig();
System.out.println("This example requires a valid OCI Vault, Secret and keys configured. It also requires " + "a Hashicorp Vault running with preconfigured data. Please see README.md");
Security security = Security.create(config.get("security"));
WebServer server = WebServer.builder().config(config.get("server")).routing(Routing.builder().register("/secrets", new SecretsService(security)).register("/encryption", new EncryptionService(security)).register("/digests", new DigestService(security))).build().start().await(10, TimeUnit.SECONDS);
System.out.println("Server started on port: " + server.port());
String baseAddress = "http://localhost:" + server.port() + "/";
System.out.println("Secrets endpoints:");
System.out.println();
System.out.println("OCI secret:");
System.out.println("\t" + baseAddress + "secrets/password");
System.out.println("Config secret:");
System.out.println("\t" + baseAddress + "secrets/token");
System.out.println("HCP Vault secret:");
System.out.println("\t" + baseAddress + "secrets/username");
System.out.println();
System.out.println("Encryption endpoints:");
System.out.println("OCI encrypted:");
System.out.println("\t" + baseAddress + "encryption/encrypt/crypto-1/text");
System.out.println("\t" + baseAddress + "encryption/decrypt/crypto-1/cipherText");
System.out.println("Config encrypted:");
System.out.println("\t" + baseAddress + "encryption/encrypt/crypto-2/text");
System.out.println("\t" + baseAddress + "encryption/decrypt/crypto-2/cipherText");
System.out.println("HCP Vault encrypted:");
System.out.println("\t" + baseAddress + "encryption/encrypt/crypto-3/text");
System.out.println("\t" + baseAddress + "encryption/decrypt/crypto-3/cipherText");
System.out.println();
System.out.println("Signature/HMAC endpoints:");
System.out.println("OCI Signature:");
System.out.println("\t" + baseAddress + "digests/digest/sig-1/text");
System.out.println("\t" + baseAddress + "digests/verify/sig-1/text/signature");
System.out.println("HCP Vault Signature:");
System.out.println("\t" + baseAddress + "digests/digest/sig-2/text");
System.out.println("\t" + baseAddress + "digests/digest/sig-2/text/signature");
System.out.println("HCP Vault HMAC:");
System.out.println("\t" + baseAddress + "digests/digest/hmac-1/text");
System.out.println("\t" + baseAddress + "digests/digest/hmac-2/text/hmac");
}
use of io.helidon.config.Config in project helidon by oracle.
the class GrpcServerConfigurationTest method shouldBuildFromConfig.
@Test
public void shouldBuildFromConfig() {
Config config = Config.builder().sources(ConfigSources.classpath("config1.conf")).build();
GrpcServerConfiguration serverConfig = config.get("grpcserver").as(GrpcServerConfiguration::create).get();
assertThat(serverConfig.name(), is("foo"));
assertThat(serverConfig.port(), is(19));
assertThat(serverConfig.useNativeTransport(), is(true));
assertThat(serverConfig.workers(), is(51));
}
use of io.helidon.config.Config in project helidon by oracle.
the class MicrometerSupportBuilderTest method testMultipleNamesOnly.
@Test
public void testMultipleNamesOnly() {
Config config = Config.create(ConfigSources.classpath("/micrometerTestData.json")).get("listOfValues");
MeterRegistryFactory.Builder factoryBuilder = MeterRegistryFactory.builder().config(config.get("metrics.micrometer"));
MeterRegistryFactory factory = factoryBuilder.build();
MicrometerSupport.Builder builder = MicrometerSupport.builder().config(config.get("metrics.micrometer")).meterRegistryFactorySupplier(factory);
assertThat(factoryBuilder.logRecords(), is(empty()));
MicrometerSupport support = builder.build();
// Even though the test data defines two Prometheus registries, internally we use a map to store
// them, keyed by the enum. So the map will contain only one.
assertThat("Did not find expected Prometheus registry", factory.registries().stream().anyMatch(PrometheusMeterRegistry.class::isInstance));
}
use of io.helidon.config.Config in project helidon by oracle.
the class CacheTest method createCacheFromConfigTest.
@Test
void createCacheFromConfigTest() {
Config helidonConfig = Config.builder().addSource(ClasspathConfigSource.create("/microstreamCacheConfig.yml")).addSource(ConfigSources.create(Map.of("cache.microstream.storage.storage-directory", tempDir.toString()))).build();
CacheConfiguration<Integer, String> config = MicrostreamCacheConfigurationBuilder.builder(helidonConfig.get("cache.microstream"), Integer.class, String.class).build();
Cache<Integer, String> cache = CacheBuilder.builder(config, Integer.class, String.class).build("Cache_IntStr");
cache.put(1, "Hello");
cache.close();
}
Aggregations