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

Calling to_string() method on some data #689

Open
dandyvica opened this issue Dec 21, 2024 · 5 comments
Open

Calling to_string() method on some data #689

dandyvica opened this issue Dec 21, 2024 · 5 comments

Comments

@dandyvica
Copy link

Hi @sunng87

Thanks for your amazing work.

Suppose you have a data structure which is mapped to the following JSON:

{
  "name": ".",
  "type": "RRSIG",
  "class": "IN",
  "ttl": 172800,
  "rd_length": 275,
  "rdata": {
    "type_covered": "DNSKEY",
    "algorithm": "RSASHA256",
    "labels": 0,
    "ttl": 172800,
    "sign_expiration": "20250110000000",
    "sign_inception": "20241220000000",
    "name": ".",
    "signature":  "blabla"
  }

The rdata field is a Rust structure for which the to_string() exists. Is it possible to code a helper to call that to_string() method in a template ?
The rdata field is not always the same (actually an enum).

Thanks !

@sunng87
Copy link
Owner

sunng87 commented Dec 23, 2024

hello @dandyvica , handlebars uses serde_json's Value as internal type system because the original handlebarsjs is based on JavaScript. So it has no access to rdata's to_string when rendering a template. My idea is to implement a custom serde Serializer that serializes rdata as a string field and calls to_string there.

@dandyvica
Copy link
Author

@sunng87 Thanks for your answer. I already have such a custom Serializer, but I don't know how to express it in the handlebars template file. Any hint ?

@sunng87
Copy link
Owner

sunng87 commented Dec 29, 2024

@dandyvica you can just try {{rdata}} and see output

@dandyvica
Copy link
Author

It's weird because in some cases, the to_string() method seems to be called and result is right, other cases just prints out object:

contact.zonetransfer.me. TXT <[Remember to call or email Pippa on +44 123 4567890 or [email protected] when making DNS changes]>
dc-office.zonetransfer.me. A <143.228.181.132>
deadbeef.zonetransfer.me. AAAA <dead:beaf::>
dr.zonetransfer.me. LOC <[object]>
DZC.zonetransfer.me. TXT <[AbCdEfG]>
email.zonetransfer.me. NAPTR <[object]>
email.zonetransfer.me. A <74.125.206.26>
Hello.zonetransfer.me. TXT <[Hi to Josh and all his class]>
home.zonetransfer.me. A <127.0.0.1>
Info.zonetransfer.me. TXT <[ZoneTransfer.me service provided by Robin Wood - [email protected]. See http://digi.ninja/projects/zonetransferme.php for more information.]>
internal.zonetransfer.me. NS <intns1.zonetransfer.me.>
internal.zonetransfer.me. NS <intns2.zonetransfer.me.>
intns1.zonetransfer.me. A <81.4.108.41>
intns2.zonetransfer.me. A <167.88.42.94>
office.zonetransfer.me. A <4.23.39.254>
ipv6actnow.org.zonetransfer.me. AAAA <2001:67c:2e8:11::c100:1332>
owa.zonetransfer.me. A <207.46.197.32>
robinwood.zonetransfer.me. TXT <[Robin Wood]>
rp.zonetransfer.me. RP <[object]>
sip.zonetransfer.me. NAPTR <[object]>
sqli.zonetransfer.me. TXT <[&#x27; or 1&#x3D;1 --]>
sshock.zonetransfer.me. TXT <[() { :]}; echo ShellShocked]>
staging.zonetransfer.me. CNAME <www.sydneyoperahouse.com.>
alltcpportsopen.firewall.test.zonetransfer.me. A <127.0.0.1>

Original template is:

{{#each messages}}
{{#each response.answer}}
{{name}} {{type}} <{{rdata}}>
{{/each}}
{{/each}}

@sunng87
Copy link
Owner

sunng87 commented Jan 6, 2025

Do you have other variants of rdata field? When it renders [object] it means it's a json object.

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

No branches or pull requests

2 participants