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

feat: proposal to let the API Key READ and WRITE the content of the r… #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
@@ -0,0 +1,49 @@
package io.confluent.developer;

import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.common.acl.AccessControlEntry;
import org.apache.kafka.common.acl.AclBinding;
import org.apache.kafka.common.acl.AclOperation;
import org.apache.kafka.common.acl.AclPermissionType;
import org.apache.kafka.common.resource.PatternType;
import org.apache.kafka.common.resource.ResourcePattern;
import org.apache.kafka.common.resource.ResourceType;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;

public class TopicAclConfigurer {
static public void configureACLs(Admin adminClient, List<NewTopic> topics, String serviceAccountPrincipal) {
topics.forEach(
topic -> {
List<AclBinding> aclBindings = Arrays.asList(
new AclBinding(
new ResourcePattern(ResourceType.TOPIC, topic.name(), PatternType.LITERAL),
new AccessControlEntry(
serviceAccountPrincipal,
"*",
AclOperation.READ,
AclPermissionType.ALLOW
)
),
new AclBinding(
new ResourcePattern(ResourceType.TOPIC, topic.name(), PatternType.LITERAL),
new AccessControlEntry(
serviceAccountPrincipal,
"*",
AclOperation.WRITE,
AclPermissionType.ALLOW
)
)
);
try {
adminClient.createAcls(aclBindings).all().get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.confluent.developer.aggregate;

import io.confluent.developer.StreamsUtils;
import io.confluent.developer.TopicAclConfigurer;
import io.confluent.developer.avro.ElectronicOrder;
import io.confluent.kafka.serializers.KafkaAvroSerializer;
import org.apache.kafka.clients.admin.Admin;
Expand Down Expand Up @@ -33,6 +34,8 @@ public static void runProducer() throws IOException {
final String outputTopic = properties.getProperty("aggregate.output.topic");
var topics = List.of(StreamsUtils.createTopic(inputTopic), StreamsUtils.createTopic(outputTopic));
adminClient.createTopics(topics);
var serviceAccountName ="User:"+properties.getProperty("service.account.name");
TopicAclConfigurer.configureACLs(adminClient, topics, serviceAccountName);

Callback callback = StreamsUtils.callback();

Expand Down