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 @@ -57,8 +57,47 @@ public <T> T translate(final JsonParser jsonParser, final Class<T> destinationTy

})
.findFirst()
.orElseGet(() -> objectMapper.convertValue(rawValue, destinationType));
.orElseGet(() -> {
// This change is to support any call
// to validate the secret with a placeholder secret expression like "AWS_SECRET_EXPRESSION"
// which is not of a secrets expression that we would check (filter check above fails) but
// still expects an instance of PluginConfigVariable object returned
if (destinationType.equals(PluginConfigVariable.class)) {
return destinationType.cast(new ImmutablePluginConfigVariable(rawValue));
}
return objectMapper.convertValue(rawValue, destinationType);
});
}
return objectMapper.readValue(jsonParser, destinationType);
}

private static class ImmutablePluginConfigVariable implements PluginConfigVariable {
private final Object rawValue;

private ImmutablePluginConfigVariable(final Object rawValue) {
this.rawValue = rawValue;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we throw new UnsupportedOperationException()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Added it.

@Override
public Object getValue() {
return rawValue;
}

@Override
public void setValue(Object updatedValue) {
throw new UnsupportedOperationException("ImmutablePluginConfigVariable doesn't support this operation");
}

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

@Override
public boolean isUpdatable() {
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -177,6 +181,20 @@ public boolean isUpdatable() {
assertThat(actualResult, equalTo(mockPluginConfigVariable));
}

@Test
void testTranslateJsonParserWithSPluginConfigVariableValue_when_non_secret_format_is_given() 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);
assertNotNull(actualResult);
assertInstanceOf(PluginConfigVariable.class, actualResult);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have assertions on getValue, and isUpdatable, etc.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, added additional assertions

PluginConfigVariable pluginConfigVariableInstance = (PluginConfigVariable) actualResult;
assertEquals(testSecretReference, pluginConfigVariableInstance.getValue().toString());
assertFalse(pluginConfigVariableInstance.isUpdatable());
}

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