io.streamthoughts.kafka.specs.resources.acl.AclRulesBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kafka-specs Show documentation
Show all versions of kafka-specs Show documentation
Tool to ease and automate Apache Kafka cluster configuration management
The newest version!
/*
* Copyright 2020 StreamThoughts.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.streamthoughts.kafka.specs.resources.acl;
import io.streamthoughts.kafka.specs.model.V1AccessRoleObject;
import io.streamthoughts.kafka.specs.model.V1AccessPrincipalObject;
import java.util.Collection;
import java.util.LinkedList;
/**
* Default interface to convert from and to {@link AclRulesBuilder} instance.
*/
public interface AclRulesBuilder {
Collection toAccessControlPolicy(final Collection groups,
final V1AccessPrincipalObject user);
Collection toAclUserPolicy(final Collection rules);
default boolean canBuildAclUserPolicy() {
return true;
}
static AclRulesBuilder combines(final AclRulesBuilder...builders) {
return new AclRulesBuilder() {
/**
* {@inheritDoc}
*/
@Override
public Collection toAccessControlPolicy(final Collection groups,
final V1AccessPrincipalObject user) {
Collection rules = new LinkedList<>();
for (AclRulesBuilder b : builders) {
rules.addAll(b.toAccessControlPolicy(groups, user));
}
return rules;
}
/**
* {@inheritDoc}
*/
@Override
public Collection toAclUserPolicy(final Collection rules) {
Collection policies = new LinkedList<>();
for (AclRulesBuilder b : builders) {
if (b.canBuildAclUserPolicy()) {
policies.addAll(b.toAclUserPolicy(rules));
}
}
return policies;
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy