-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log deprecation message on legacy ldap pool settings (#2099)
* Log deprecation message on legacy ldap pool settings Signed-off-by: Peter Nied <[email protected]> Signed-off-by: Peter Nied <[email protected]> Co-authored-by: Martin Kemp <[email protected]>
- Loading branch information
Showing
6 changed files
with
114 additions
and
12 deletions.
There are no files selected for viewing
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
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
26 changes: 26 additions & 0 deletions
26
src/main/java/org/opensearch/security/setting/DeprecatedSettings.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,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.security.setting; | ||
|
||
import org.opensearch.common.logging.DeprecationLogger; | ||
import org.opensearch.common.settings.Settings; | ||
|
||
/** | ||
* Functionality around settings that have been deprecated | ||
*/ | ||
public class DeprecatedSettings { | ||
|
||
static DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(DeprecatedSettings.class); | ||
|
||
/** | ||
* Checks for an deprecated key found in a setting, logs that it should be replaced with the another key | ||
*/ | ||
public static void checkForDeprecatedSetting(final Settings settings, final String legacySettingKey, final String validSettingKey) { | ||
if (settings.hasValue(legacySettingKey)) { | ||
DEPRECATION_LOGGER.deprecate(legacySettingKey, "Found deprecated setting '{}', please replace with '{}'", legacySettingKey, validSettingKey); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/test/java/org/opensearch/security/setting/DeprecatedSettingsTest.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,63 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.security.setting; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import org.opensearch.common.logging.DeprecationLogger; | ||
import org.opensearch.common.settings.Settings; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoInteractions; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
import static org.opensearch.security.setting.DeprecatedSettings.checkForDeprecatedSetting; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class DeprecatedSettingsTest { | ||
|
||
@Mock | ||
private DeprecationLogger logger; | ||
|
||
private DeprecationLogger original; | ||
|
||
@Before | ||
public void before() { | ||
original = DeprecatedSettings.DEPRECATION_LOGGER; | ||
DeprecatedSettings.DEPRECATION_LOGGER = logger; | ||
} | ||
|
||
@After | ||
public void after() { | ||
DeprecatedSettings.DEPRECATION_LOGGER = original; | ||
verifyNoMoreInteractions(logger); | ||
} | ||
|
||
@Test | ||
public void testCheckForDeprecatedSettingNoLegacy() { | ||
final Settings settings = Settings.builder().put("properKey", "value").build(); | ||
|
||
checkForDeprecatedSetting(settings, "legacyKey", "properKey"); | ||
|
||
verifyNoInteractions(logger); | ||
} | ||
|
||
@Test | ||
public void testCheckForDeprecatedSettingFoundLegacy() { | ||
final Settings settings = Settings.builder().put("legacyKey", "value").build(); | ||
|
||
checkForDeprecatedSetting(settings, "legacyKey", "properKey"); | ||
|
||
verify(logger).deprecate(eq("legacyKey"), anyString(), any()); | ||
} | ||
} |