-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New ksql.properties.overrides.denylist to deny clients configs …
…overrides (#5877)
- Loading branch information
Showing
12 changed files
with
455 additions
and
28 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
ksqldb-common/src/main/java/io/confluent/ksql/properties/DenyListPropertyValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2020 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.properties; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.Sets; | ||
import io.confluent.ksql.util.KsqlException; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
/** | ||
* Class that validates if a property, or list of properties, is part of a list of denied | ||
* properties. | ||
*/ | ||
public class DenyListPropertyValidator { | ||
private final Set<String> immutableProps; | ||
|
||
public DenyListPropertyValidator(final Collection<String> immutableProps) { | ||
this.immutableProps = ImmutableSet.copyOf( | ||
Objects.requireNonNull(immutableProps, "immutableProps")); | ||
} | ||
|
||
/** | ||
* Validates if a list of properties are part of the list of denied properties. | ||
* @throws if at least one property is part of the denied list. | ||
*/ | ||
public void validateAll(final Map<String, Object> properties) { | ||
final Set<String> propsDenied = Sets.intersection(immutableProps, properties.keySet()); | ||
if (!propsDenied.isEmpty()) { | ||
throw new KsqlException(String.format("One or more properties overrides set locally are " | ||
+ "prohibited by the KSQL server (use UNSET to reset their default value): %s", | ||
propsDenied)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
ksqldb-common/src/test/java/io/confluent/ksql/properties/DenyListPropertyValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2020 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (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.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.properties; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.confluent.ksql.util.KsqlException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import java.util.Arrays; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
public class DenyListPropertyValidatorTest { | ||
private DenyListPropertyValidator validator; | ||
|
||
@Before | ||
public void setUp() { | ||
validator = new DenyListPropertyValidator(Arrays.asList( | ||
"immutable-property-1", | ||
"immutable-property-2" | ||
)); | ||
} | ||
|
||
@Test | ||
public void shouldThrowOnDenyListedProperty() { | ||
// When: | ||
final KsqlException e = assertThrows( | ||
KsqlException.class, | ||
() -> validator.validateAll(ImmutableMap.of( | ||
"immutable-property-1", "v1", | ||
"anything", "v2", | ||
"immutable-property-2", "v3" | ||
)) | ||
); | ||
|
||
// Then: | ||
assertThat(e.getMessage(), containsString( | ||
"One or more properties overrides set locally are prohibited by the KSQL server " | ||
+ "(use UNSET to reset their default value): " | ||
+ "[immutable-property-1, immutable-property-2]" | ||
)); | ||
|
||
} | ||
|
||
@Test | ||
public void shouldNotThrowOnAllowedProp() { | ||
validator.validateAll(ImmutableMap.of( | ||
"mutable-1", "v1", | ||
"anything", "v2" | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.