Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: transform not handling base64/binary values correctly #1325

Closed
dreamorosi opened this issue Feb 22, 2023 · 1 comment · Fixed by #1326
Closed

Bug: transform not handling base64/binary values correctly #1325

dreamorosi opened this issue Feb 22, 2023 · 1 comment · Fixed by #1326
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped parameters This item relates to the Parameters Utility

Comments

@dreamorosi
Copy link
Contributor

Expected Behaviour

Based on the discussion had in aws-powertools/powertools-lambda-python#1796 when working with AppConfig, the transforms JSON & binary should respectively return an object and a string, i.e.

const configProfileFeatureFlag = new CfnConfigurationProfile(this, "configProfileFeatureFlag", {
  name: "test-config-profile-feature-flag",
  applicationId: application.ref,
  locationUri: "hosted",
  type: "AWS.AppConfig.FeatureFlags",
});

const configVersionFeatureFlag = new CfnHostedConfigurationVersion(this, "configVersionFeatureFlag", {
  applicationId: application.ref,
  configurationProfileId: configProfileFeatureFlag.ref,
  contentType: 'application/json',
  content: JSON.stringify({
  "version": "1",
  "flags": {
    myFeatureFlag: {
      name: "myFeatureFlag",
    }
  },
  values: {
      myFeatureFlag: {
         enabled: true,
      }
    }
  }),
});

when retrieved with await getAppConfig('my-feature-flag', { transform: 'json' });, should return:

"myFeatureFlag": {
  "enabled": true,
}

while:

const configProfilePlainText = new CfnConfigurationProfile(this, "configProfilePlainText", {
  name: "test-config-profile-plain-text",
  applicationId: application.ref,
  locationUri: "hosted",
  type: "AWS.Freeform",
});

// Base64-encoded value
const value = toBase64(new TextEncoder().encode('test'));

const configVersionPlainText = new CfnHostedConfigurationVersion(this, "configVersionPlainText", {
  applicationId: application.ref,
  configurationProfileId: configProfilePlainText.ref,
  content: value,
  contentType: "text/plain",
});

when retrieved with await getAppConfig('my-feature-flag', { transform: 'binary' });, should return test.

Essentially, the provider and transformer should transparently handle the fact that AppConfig always returns an Uint8Array and subsequently apply the transform when one is provided.

Current Behaviour

Currently the transformer would decode the binary only when transform: "binary" is specified and when doing so it would skip the base64 decoding.

This would also result in never being able to use the JSON transform because when attempting to parse the JSON the value was still a binary.

Code snippet

See above.

Possible Solution

No response

Steps to Reproduce

See above as well as linked discussion/isssue.

AWS Lambda Powertools for TypeScript version

latest

AWS Lambda function runtime

18.x

Packaging format used

Npm

Execution logs

No response

@dreamorosi dreamorosi added bug Something isn't working parameters This item relates to the Parameters Utility confirmed The scope is clear, ready for implementation labels Feb 22, 2023
@dreamorosi dreamorosi self-assigned this Feb 22, 2023
@dreamorosi dreamorosi added this to the Parameters - Beta release milestone Feb 22, 2023
@github-actions
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release This item has been merged and will be released soon label Feb 22, 2023
@dreamorosi dreamorosi added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon confirmed The scope is clear, ready for implementation labels Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This item is complete and has been merged/shipped parameters This item relates to the Parameters Utility
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant