Skip to content

Serialization fix when the expected type is PluginConfigVariable#5698

Merged
san81 merged 3 commits into
opensearch-project:mainfrom
san81:plugin-variable-serialize
May 17, 2025
Merged

Serialization fix when the expected type is PluginConfigVariable#5698
san81 merged 3 commits into
opensearch-project:mainfrom
san81:plugin-variable-serialize

Conversation

@san81

@san81 san81 commented May 16, 2025

Copy link
Copy Markdown
Collaborator

Description

Current logic is expecting the rawSecret value to be of a certain format to be able to convert to PluginConfigVariable type. But then the requested type is PluginConfigVariable but raw value is not passing the expression format check filter criteria, we are currently failing to serialize the value into the object type. This fix is to still return an instance of a requested type without any attached functionality. We will be avoiding the serialization issue with this fix.

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Santhosh Gandhe <1909520+san81@users.noreply.github.com>
@san81 san81 marked this pull request as ready for review May 16, 2025 19:27
// 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 PluginConfigVariable() {

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.

Rather than make an anonymous class, the code would be readable if you make a static inner class.

private static ImmutablePluginConfigVariable {
  private final Object rawValue;
  ImmutablePluginConfigVariable(Object rawValue) { ... }

  // similar code
}

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.

Moved to an private static immutable class for better readability

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


@Override
public void setValue(Object updatedValue) {

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.


@Test
void testTranslateJsonParserWithSPluginConfigVariableValue_when_non_secret_format_is_given() throws IOException {
final String testSecretReference = "not-in-aws-secrets-expression-format";

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.

Use a random UUID here. Also, this code should be generic beyond just AWS Secrets as it is part of core.

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.

Using random value now

san81 added 2 commits May 16, 2025 13:57
Signed-off-by: Santhosh Gandhe <1909520+san81@users.noreply.github.com>
Signed-off-by: Santhosh Gandhe <1909520+san81@users.noreply.github.com>
@san81 san81 requested a review from dlvenable May 16, 2025 21:47
@san81 san81 merged commit 143aa32 into opensearch-project:main May 17, 2025
44 of 47 checks passed
alparish pushed a commit to alparish/data-prepper that referenced this pull request May 22, 2025
…nsearch-project#5698)

* Serialization fix when the expected type is PluginConfigVariable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants