Search in sources :

Example 26 with CONFIG

use of org.bf2.admin.kafka.systemtest.Environment.CONFIG in project kafka-admin-api by bf2fc6cc711aee1a0c2a.

the class AdminClientFactory method createProducer.

public Producer<String, String> createProducer() {
    Map<String, Object> props = config.getProducerConfig();
    if (config.isOauthEnabled()) {
        if (token.isResolvable()) {
            final String accessToken = token.get().getRawToken();
            props.put(SaslConfigs.SASL_JAAS_CONFIG, String.format(SASL_OAUTH_CONFIG_TEMPLATE, accessToken));
        } else {
            log.warn("OAuth is enabled, but there is no JWT principal");
        }
    } else if (config.isBasicEnabled()) {
        extractCredentials(Optional.ofNullable(headers.get().getHeaderString(HttpHeaders.AUTHORIZATION))).ifPresentOrElse(credentials -> props.put(SaslConfigs.SASL_JAAS_CONFIG, credentials), () -> {
            throw new NotAuthorizedException("Invalid or missing credentials", Response.status(Status.UNAUTHORIZED).build());
        });
    } else {
        log.debug("OAuth is disabled - no attempt to set access token in Admin Client config");
    }
    props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
    props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
    props.put(ProducerConfig.ACKS_CONFIG, "all");
    return new KafkaProducer<>(props);
}
Also used : Consumer(org.apache.kafka.clients.consumer.Consumer) Producer(org.apache.kafka.clients.producer.Producer) KafkaAdminConfigRetriever(org.bf2.admin.kafka.admin.KafkaAdminConfigRetriever) Logger(org.jboss.logging.Logger) Vertx(io.vertx.core.Vertx) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) AdminClient(org.apache.kafka.clients.admin.AdminClient) Inject(javax.inject.Inject) Objects(java.util.Objects) Base64(java.util.Base64) KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) HttpHeaders(javax.ws.rs.core.HttpHeaders) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) Response(javax.ws.rs.core.Response) RequestScoped(javax.enterprise.context.RequestScoped) JsonWebToken(org.eclipse.microprofile.jwt.JsonWebToken) Map(java.util.Map) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Optional(java.util.Optional) SaslConfigs(org.apache.kafka.common.config.SaslConfigs) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Status(javax.ws.rs.core.Response.Status) Instance(javax.enterprise.inject.Instance) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) KafkaProducer(org.apache.kafka.clients.producer.KafkaProducer) NotAuthorizedException(javax.ws.rs.NotAuthorizedException)

Example 27 with CONFIG

use of org.bf2.admin.kafka.systemtest.Environment.CONFIG in project kafka-admin-api by bf2fc6cc711aee1a0c2a.

the class DeploymentManager method deployKafka.

private KafkaContainer<?> deployKafka() {
    LOGGER.info("Deploying Kafka container");
    Map<String, String> env = new HashMap<>();
    try (InputStream stream = getClass().getResourceAsStream("/kafka-oauth/env.properties")) {
        Properties envProps = new Properties();
        envProps.load(stream);
        envProps.keySet().stream().map(Object::toString).forEach(key -> env.put(key, envProps.getProperty(key)));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    String imageTag = System.getProperty("strimzi-kafka.tag");
    var container = new KeycloakSecuredKafkaContainer(imageTag).withLabels(Collections.singletonMap("test-ident", Environment.TEST_CONTAINER_LABEL)).withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("systemtests.oauth-kafka"), true)).withCreateContainerCmdModifier(cmd -> cmd.withName(name("oauth-kafka"))).withEnv(env).withNetwork(testNetwork).withClasspathResourceMapping("/certs/cluster.keystore.p12", "/opt/kafka/certs/cluster.keystore.p12", BindMode.READ_ONLY).withClasspathResourceMapping("/certs/cluster.truststore.p12", "/opt/kafka/certs/cluster.truststore.p12", BindMode.READ_ONLY).withClasspathResourceMapping("/kafka-oauth/config/", "/opt/kafka/config/strimzi/", BindMode.READ_ONLY).withCopyFileToContainer(MountableFile.forClasspathResource("/kafka-oauth/scripts/functions.sh"), "/opt/kafka/functions.sh").withCopyFileToContainer(MountableFile.forClasspathResource("/kafka-oauth/scripts/simple_kafka_config.sh", 0755), "/opt/kafka/simple_kafka_config.sh").withCopyFileToContainer(MountableFile.forClasspathResource("/kafka-oauth/scripts/start.sh", 0755), "/opt/kafka/start.sh").withCommand("/opt/kafka/start.sh");
    container.start();
    return container;
}
Also used : BindMode(org.testcontainers.containers.BindMode) CONFIG(org.bf2.admin.kafka.systemtest.Environment.CONFIG) Logger(org.jboss.logging.Logger) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Network(org.testcontainers.containers.Network) StrimziKafkaContainer(io.strimzi.StrimziKafkaContainer) ArrayList(java.util.ArrayList) Slf4jLogConsumer(org.testcontainers.containers.output.Slf4jLogConsumer) Duration(java.time.Duration) Map(java.util.Map) GenericContainer(org.testcontainers.containers.GenericContainer) Startable(org.testcontainers.lifecycle.Startable) Wait(org.testcontainers.containers.wait.strategy.Wait) Properties(java.util.Properties) KafkaAdminConfigRetriever(org.bf2.admin.kafka.admin.KafkaAdminConfigRetriever) Environment(org.bf2.admin.kafka.systemtest.Environment) IOException(java.io.IOException) UUID(java.util.UUID) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) Base64(java.util.Base64) List(java.util.List) MountableFile(org.testcontainers.utility.MountableFile) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) InputStream(java.io.InputStream) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Slf4jLogConsumer(org.testcontainers.containers.output.Slf4jLogConsumer) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Properties(java.util.Properties)

Example 28 with CONFIG

use of org.bf2.admin.kafka.systemtest.Environment.CONFIG in project kafka-admin-api by bf2fc6cc711aee1a0c2a.

the class ConsumerGroupsOAuthTestIT method setup.

@BeforeEach
void setup() {
    String token = tokenUtils.getToken(UserType.OWNER.getUsername());
    topicUtils = new TopicUtils(config, token);
    topicUtils.deleteAllTopics();
    groupUtils = new ConsumerUtils(config, token);
    batchId = UUID.randomUUID().toString();
}
Also used : ConsumerUtils(org.bf2.admin.kafka.systemtest.utils.ConsumerUtils) TopicUtils(org.bf2.admin.kafka.systemtest.utils.TopicUtils) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 29 with CONFIG

use of org.bf2.admin.kafka.systemtest.Environment.CONFIG in project kafka-admin-api by bf2fc6cc711aee1a0c2a.

the class RecordEndpointOAuthTestIT method setup.

@BeforeEach
void setup() {
    String token = tokenUtils.getToken(UserType.OWNER.getUsername());
    topicUtils = new TopicUtils(config, token);
    topicUtils.deleteAllTopics();
    recordUtils = new RecordUtils(config, token);
    metricsUtils = new MetricsUtils(metricsUrl);
}
Also used : MetricsUtils(org.bf2.admin.kafka.systemtest.utils.MetricsUtils) RecordUtils(org.bf2.admin.kafka.systemtest.utils.RecordUtils) TopicUtils(org.bf2.admin.kafka.systemtest.utils.TopicUtils) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 30 with CONFIG

use of org.bf2.admin.kafka.systemtest.Environment.CONFIG in project kafka-admin-api by bf2fc6cc711aee1a0c2a.

the class RestOAuthTestIT method setup.

@BeforeEach
void setup() {
    String token = tokenUtils.getToken(UserType.OWNER.getUsername());
    topicUtils = new TopicUtils(config, token);
    topicUtils.deleteAllTopics();
    this.metricsUtils = new MetricsUtils(metricsUrl);
}
Also used : MetricsUtils(org.bf2.admin.kafka.systemtest.utils.MetricsUtils) TopicUtils(org.bf2.admin.kafka.systemtest.utils.TopicUtils) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Test (org.junit.jupiter.api.Test)15 Map (java.util.Map)12 Inject (javax.inject.Inject)12 QuarkusTest (io.quarkus.test.junit.QuarkusTest)9 List (java.util.List)9 Collectors (java.util.stream.Collectors)8 FleetShardClient (org.bf2.cos.fleetshard.sync.client.FleetShardClient)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 Secret (io.fabric8.kubernetes.api.model.Secret)7 HashMap (java.util.HashMap)7 Objects (java.util.Objects)6 ApplicationScoped (javax.enterprise.context.ApplicationScoped)6 ManagedConnector (org.bf2.cos.fleetshard.api.ManagedConnector)6 FleetShardSyncConfig (org.bf2.cos.fleetshard.sync.FleetShardSyncConfig)6 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)5 ArrayList (java.util.ArrayList)5 Optional (java.util.Optional)5 Set (java.util.Set)5 TopicUtils (org.bf2.admin.kafka.systemtest.utils.TopicUtils)5 Namespace (io.fabric8.kubernetes.api.model.Namespace)4