Skip to content

feat: template tag to encode hex to base64#6211

Merged
jackkav merged 2 commits intoKong:developfrom
nbgraham:feat/encode-hex-to-base64
Jan 29, 2024
Merged

feat: template tag to encode hex to base64#6211
jackkav merged 2 commits intoKong:developfrom
nbgraham:feat/encode-hex-to-base64

Conversation

@nbgraham
Copy link
Contributor

@nbgraham nbgraham commented Jul 28, 2023

Adds a new "kind" to the existing bae64 encoding template tag to support encoding from hex values to base 64.

I have a use-case for passing in hex strings as bytes to gRPC and the sender client expects base64 encoded strings, which makes it very difficult to test.

The diff is really not that big, I just pulled out the base64tag into it's own object so I could export it for testing. I added comments with the changed lines.

Comment on lines +63 to +64
} else if (kind === hex) {
return Buffer.from(text, 'hex').toString('base64');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New

run(_context, action, kind, text) {
text = text || '';
invariant(action === encode || action === decode, 'invalid action');
invariant(kind === normal || kind === url || kind === hex, 'invalid kind');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New

Comment on lines +73 to +74
if (kind === hex) {
return Buffer.from(text, 'base64').toString('hex');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New

return Buffer.from(text, 'base64').toString('utf8');
}
}
throw new Error('unknown options');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New

Comment on lines +18 to +23
const encode = 'encode';
const decode = 'decode';

const normal = 'normal';
const url = 'url';
const hex = 'hex';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New

@jackkav
Copy link
Contributor

jackkav commented Aug 1, 2023

@nbgraham Thanks for this contribution, I'm planning a revision of the autocomplete menu soon and will try to address this PR as part of or after I have completed the revision.

@nbgraham nbgraham marked this pull request as draft August 3, 2023 22:26
@CLAassistant
Copy link

CLAassistant commented Jan 2, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ jackkav
❌ nbgraham
You have signed the CLA already but the status is still pending? Let us recheck it.

@jackkav jackkav force-pushed the feat/encode-hex-to-base64 branch from 7062680 to 9037697 Compare January 29, 2024 13:08
@jackkav jackkav marked this pull request as ready for review January 29, 2024 13:17
@jackkav
Copy link
Contributor

jackkav commented Jan 29, 2024

Thanks for your contribution @nbgraham I've removed the testing abstraction to keep the prod code easier to read and added a finder to the test. Removed some conditions to allow fall through to work and eliminate code.

@jackkav jackkav merged commit 2d0042a into Kong:develop Jan 29, 2024
jackkav added a commit to jackkav/insomnia that referenced this pull request Mar 13, 2024
* feat: template tag to encode hex to base64

* review, flatten, simplify

---------

Co-authored-by: jackkav <jackkav@gmail.com>
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