Skip to content
Merged
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
Expand Up @@ -31,12 +31,17 @@ public interface PluginConfigVariable {
void setValue(Object updatedValue);

/**
* Refresh the secret value on demand
* Refresh the secret value on demand.
* <p>
* This call semantically means to refresh the value from the underlying data store. If that
* is not supported an implementation should perform a no-op.
*/
void refresh();

/**
* Returns if the variable is updatable.
* Returns if the variable is updatable from Data Prepper itself. This indicates
* that Data Prepper itself can update the actual value, not that the value itself can be
* updated from another system.
*
* @return true if this variable is updatable, false otherwise
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public void setValue(Object updatedValue) {

@Override
public void refresh() {
// No-op as this is immutable
throw new UnsupportedOperationException("ImmutablePluginConfigVariable doesn't support this operation");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,29 @@ void testTranslateJsonParserWithSPluginConfigVariableValue_when_non_secret_forma
assertFalse(pluginConfigVariableInstance.isUpdatable());
}

@Test
void testImmutablePluginConfigVariable_refresh_does_not_throw() throws IOException {
final String testSecretReference = UUID.randomUUID().toString();
final JsonParser jsonParser = JSON_FACTORY.createParser(String.format("\"%s\"", testSecretReference));
jsonParser.nextToken();
objectUnderTest = new VariableExpander(OBJECT_MAPPER, Set.of(pluginConfigValueTranslator));
final Object actualResult = objectUnderTest.translate(jsonParser, PluginConfigVariable.class);
PluginConfigVariable pluginConfigVariableInstance = (PluginConfigVariable) actualResult;
pluginConfigVariableInstance.refresh();
assertThat(pluginConfigVariableInstance.getValue().toString(), equalTo(testSecretReference));
}

@Test
void testImmutablePluginConfigVariable_setValue_throws() throws IOException {
final String testSecretReference = UUID.randomUUID().toString();
final JsonParser jsonParser = JSON_FACTORY.createParser(String.format("\"%s\"", testSecretReference));
jsonParser.nextToken();
objectUnderTest = new VariableExpander(OBJECT_MAPPER, Set.of(pluginConfigValueTranslator));
final Object actualResult = objectUnderTest.translate(jsonParser, PluginConfigVariable.class);
PluginConfigVariable pluginConfigVariableInstance = (PluginConfigVariable) actualResult;
assertThrows(UnsupportedOperationException.class, () -> pluginConfigVariableInstance.setValue("new-value"));
}

@Test
void testTranslateJsonParserWithSPluginConfigVariableValue_translate_failure() throws IOException {
final String testSecretKey = "testSecretKey";
Expand Down
Loading