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

luci-app-acme: render DNS API fields from the Structured Info #7515

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

stokito
Copy link
Contributor

@stokito stokito commented Dec 29, 2024

Maintainer: @tohojo

To show fields specific to a DNS API provider I made a list of all options and included them directly into the JS file.

The upcoming ACME.sh release all scripts now contain a Structured Info with list of options:

dns_alviy
Alviy.com
Site: Alviy.com
Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi2#dns_alviy
Options:
 Alviy_token API token. Get it from the https://cloud.alviy.com/token
Issues: github.com/acmesh-official/acme.sh/issues/5115

So once release we can make an RPC call to gather the info for all providers right from scripts and render it.

The PR adds the parsing and rendering part. Once the acmesh will be updated in the OpenWrt we can include the script and RPC call.
For now I just generated it and included as a file (slightly stripped to keep disk space).

We might use the file converted to a JSON but the info is really big and it's takes much less space and ram to have a JS parser right on UI.

CC @hgl @systemcrash @dannil @IamRPDev

@stokito stokito force-pushed the luci-app-acme-dnsapi_info branch from d873254 to 2735988 Compare December 29, 2024 20:57
Use for of.
Use let instead of var.
Fix missing ;
Make load to return an array of promises.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
The ACME.sh scripts have a description of all options.
In preparation to use it include it generated into the app itself and render.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
@stokito stokito force-pushed the luci-app-acme-dnsapi_info branch from 2735988 to 8e27306 Compare December 30, 2024 07:22
@tohojo
Copy link
Contributor

tohojo commented Dec 30, 2024

Neat! Feels like the dnsapi.info.txt file should be part of the acme.sh package, not the luci app, though?

Also, AFAICT the parser is not terribly robust against malformed entries (judging from the unconditional shift() calls)? Not sure how the javascript runtime will handle failures, but IMO the parser should be smart enough to just skip malformed entries instead of aborting the whole thing (which is what I'm assuming will happen if the code throws an exception?).

@systemcrash
Copy link
Contributor

Use JSON, whose handling is far more well-defined. But no, a more opaque format, so everything can be done in (ba)sh. Doesn't really matter where the file is, repo-wise, but if the GUI is the only thing that depends on it, here is its home.

@stokito
Copy link
Contributor Author

stokito commented Dec 30, 2024

The full parser with some tests is located here https://github.com/yurt-page/acmesh-parse-dnsapi-info

Right now we parsing own file that is 100% correct. Even now it will always parse to at least api Id and Name.

I'll try to check it later to improve error handling, maybe half of the parser can be replaced with a regexp :)

In the PR I added a stripped info version 16 Kb.
The full info version is 39 Kb and gzipped to 10 Kb.
Converted to JSON 115 Kb and gzipped to 12 Kb (see parsed.json).
The parser (dnsapi.js) is 3 KB but can be simplified to 1 Kb.

Maybe we can convert to JSON in shell but it's easier to do in JS, especially that we don't need for a full parsing (with Issues, Author fields).

@tohojo
Copy link
Contributor

tohojo commented Jan 2, 2025

The full parser with some tests is located here https://github.com/yurt-page/acmesh-parse-dnsapi-info

Right now we parsing own file that is 100% correct. Even now it will always parse to at least api Id and Name.

I'll try to check it later to improve error handling, maybe half of the parser can be replaced with a regexp :)

The main thing I'm after from a robustness perspective is that a malformed entry will just be skipped, but not interfere with the parsing of the rest of the file. Should be pretty straight forward to add a test for that :)

In the PR I added a stripped info version 16 Kb. The full info version is 39 Kb and gzipped to 10 Kb. Converted to JSON 115 Kb and gzipped to 12 Kb (see parsed.json). The parser (dnsapi.js) is 3 KB but can be simplified to 1 Kb.

Maybe we can convert to JSON in shell but it's easier to do in JS, especially that we don't need for a full parsing (with Issues, Author fields).

I don't have a strong opinion about whether the file should generated as JSON at build time, or just be a concatenation of the definitions from the plugin files as you are doing now. But the "at build time" thing is important, IMO. I.e., the file should not be manually generated and included in the Luci package, it should be generated at build time of the acme-acmesh-dnsapi package and included in that package. Otherwise we have to manually keep the list of providers in sync between the two packages, and avoiding that is (presumably) the whole point of having an automatic parser in the first place :)

@stokito
Copy link
Contributor Author

stokito commented Jan 2, 2025

malformed entry will just be skipped

The parsing is lenient. It may potentially improved for a future when we switch to the parsing of extracted info directly from scripts. The acme.sh already made a release that contains the dnsinfo so actually we do can update the package and switch to extracting. There was some minor problems and I fixed and reviewed all of them so after the next acmesh release we can switch to extracting.

The PR can be merged today.

@tohojo
Copy link
Contributor

tohojo commented Jan 3, 2025

The PR can be merged today.

Hmm, but why do it in this order? Seems to me that getting the extraction bits in place first, and the merging this afterwards makes more sense? :)

@stokito
Copy link
Contributor Author

stokito commented Jan 3, 2025 via email

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