Search in sources :

Example 61 with Config

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);
}
Also used : Config(io.helidon.config.Config) WebServer(io.helidon.webserver.WebServer) Optional(java.util.Optional) WebSecurity(io.helidon.security.integration.webserver.WebSecurity) SecurityContext(io.helidon.security.SecurityContext) LogConfig(io.helidon.common.LogConfig) Routing(io.helidon.webserver.Routing) MediaType(io.helidon.common.http.MediaType) Optional(java.util.Optional) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) SecurityContext(io.helidon.security.SecurityContext) Routing(io.helidon.webserver.Routing)

Example 62 with Config

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");
}
Also used : WebServer(io.helidon.webserver.WebServer) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) Security(io.helidon.security.Security)

Example 63 with Config

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));
}
Also used : Config(io.helidon.config.Config) Test(org.junit.jupiter.api.Test)

Example 64 with Config

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));
}
Also used : Config(io.helidon.config.Config) PrometheusConfig(io.micrometer.prometheus.PrometheusConfig) Test(org.junit.jupiter.api.Test)

Example 65 with Config

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();
}
Also used : Config(io.helidon.config.Config) Test(org.junit.jupiter.api.Test)

Aggregations

Config (io.helidon.config.Config)329 Test (org.junit.jupiter.api.Test)169 LogConfig (io.helidon.common.LogConfig)56 WebServer (io.helidon.webserver.WebServer)54 Routing (io.helidon.webserver.Routing)51 BeforeAll (org.junit.jupiter.api.BeforeAll)24 Security (io.helidon.security.Security)20 HealthSupport (io.helidon.health.HealthSupport)18 Single (io.helidon.common.reactive.Single)17 MetricsSupport (io.helidon.metrics.MetricsSupport)16 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)16 ConfigSources (io.helidon.config.ConfigSources)15 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)15 SecurityContext (io.helidon.security.SecurityContext)15 Optional (java.util.Optional)15 TimeUnit (java.util.concurrent.TimeUnit)15 WebSecurity (io.helidon.security.integration.webserver.WebSecurity)13 HealthChecks (io.helidon.health.checks.HealthChecks)12 WebClient (io.helidon.webclient.WebClient)12 GrpcRouting (io.helidon.grpc.server.GrpcRouting)11