checker: add standalone interactive form and test target
Implement RenderForm/ParseForm for the zonemasterProvider under the standalone build tag, enabling browser-based interactive use. Also add a `make test` target that builds with the same tag.
This commit is contained in:
parent
2710dfb459
commit
5ba745982e
2 changed files with 74 additions and 2 deletions
7
Makefile
7
Makefile
|
|
@ -6,12 +6,12 @@ CHECKER_SOURCES := main.go $(wildcard checker/*.go)
|
|||
|
||||
GO_LDFLAGS := -X main.Version=$(CHECKER_VERSION)
|
||||
|
||||
.PHONY: all plugin docker clean
|
||||
.PHONY: all plugin docker test clean
|
||||
|
||||
all: $(CHECKER_NAME)
|
||||
|
||||
$(CHECKER_NAME): $(CHECKER_SOURCES)
|
||||
go build -ldflags "$(GO_LDFLAGS)" -o $@ .
|
||||
go build -tags standalone -ldflags "$(GO_LDFLAGS)" -o $@ .
|
||||
|
||||
plugin: $(CHECKER_NAME).so
|
||||
|
||||
|
|
@ -21,5 +21,8 @@ $(CHECKER_NAME).so: $(CHECKER_SOURCES) $(wildcard plugin/*.go)
|
|||
docker:
|
||||
docker build --build-arg CHECKER_VERSION=$(CHECKER_VERSION) -t $(CHECKER_IMAGE) .
|
||||
|
||||
test:
|
||||
go test -tags standalone ./...
|
||||
|
||||
clean:
|
||||
rm -f $(CHECKER_NAME) $(CHECKER_NAME).so
|
||||
|
|
|
|||
69
checker/interactive.go
Normal file
69
checker/interactive.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
//go:build standalone
|
||||
|
||||
package checker
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||
)
|
||||
|
||||
func (p *zonemasterProvider) RenderForm() []sdk.CheckerOptionField {
|
||||
return []sdk.CheckerOptionField{
|
||||
{
|
||||
Id: "domainName",
|
||||
Type: "string",
|
||||
Label: "Domain name to check",
|
||||
Placeholder: "example.com",
|
||||
Required: true,
|
||||
Description: "Fully-qualified domain name to submit to the Zonemaster engine.",
|
||||
},
|
||||
{
|
||||
Id: "profile",
|
||||
Type: "string",
|
||||
Label: "Profile",
|
||||
Placeholder: "default",
|
||||
Description: "Zonemaster test profile to apply (engine-defined; usually \"default\").",
|
||||
},
|
||||
{
|
||||
Id: "language",
|
||||
Type: "string",
|
||||
Label: "Result language",
|
||||
Placeholder: "en",
|
||||
Description: "Language for human-readable test messages (en, fr, de, es, sv, da, fi, nb, nl, pt).",
|
||||
},
|
||||
{
|
||||
Id: "zonemasterAPIURL",
|
||||
Type: "string",
|
||||
Label: "Zonemaster API URL",
|
||||
Placeholder: "https://zonemaster.net/api",
|
||||
Description: "JSON-RPC endpoint of the Zonemaster backend to query.",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (p *zonemasterProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error) {
|
||||
domainName := strings.TrimSpace(r.FormValue("domainName"))
|
||||
if domainName == "" {
|
||||
return nil, errors.New("domainName is required")
|
||||
}
|
||||
domainName = strings.TrimSuffix(domainName, ".")
|
||||
|
||||
opts := sdk.CheckerOptions{
|
||||
"domainName": domainName,
|
||||
}
|
||||
|
||||
if v := strings.TrimSpace(r.FormValue("profile")); v != "" {
|
||||
opts["profile"] = v
|
||||
}
|
||||
if v := strings.TrimSpace(r.FormValue("language")); v != "" {
|
||||
opts["language"] = v
|
||||
}
|
||||
if v := strings.TrimSpace(r.FormValue("zonemasterAPIURL")); v != "" {
|
||||
opts["zonemasterAPIURL"] = strings.TrimSuffix(v, "/")
|
||||
}
|
||||
|
||||
return opts, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue