Migrate to checker-sdk-go v1.3.0 with standalone build tag
The SDK split the HTTP server scaffolding into the new checker-sdk-go/checker/server subpackage and renamed CheckerInteractive to server.Interactive. Update main.go to import server and call server.New, switch the compile-time assertion to server.Interactive, and isolate the interactive form code behind the standalone build tag so plugin/builtin builds skip net/http entirely.
This commit is contained in:
parent
19296f4188
commit
eb7b6d1a90
7 changed files with 23 additions and 16 deletions
|
|
@ -6,7 +6,7 @@ WORKDIR /src
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN CGO_ENABLED=0 go build -ldflags "-X main.Version=${CHECKER_VERSION}" -o /checker-email-keys .
|
RUN CGO_ENABLED=0 go build -tags standalone -ldflags "-X main.Version=${CHECKER_VERSION}" -o /checker-email-keys .
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
COPY --from=builder /checker-email-keys /checker-email-keys
|
COPY --from=builder /checker-email-keys /checker-email-keys
|
||||||
|
|
|
||||||
7
Makefile
7
Makefile
|
|
@ -6,12 +6,12 @@ CHECKER_SOURCES := main.go $(wildcard checker/*.go)
|
||||||
|
|
||||||
GO_LDFLAGS := -X main.Version=$(CHECKER_VERSION)
|
GO_LDFLAGS := -X main.Version=$(CHECKER_VERSION)
|
||||||
|
|
||||||
.PHONY: all plugin docker clean
|
.PHONY: all plugin docker test clean
|
||||||
|
|
||||||
all: $(CHECKER_NAME)
|
all: $(CHECKER_NAME)
|
||||||
|
|
||||||
$(CHECKER_NAME): $(CHECKER_SOURCES)
|
$(CHECKER_NAME): $(CHECKER_SOURCES)
|
||||||
go build -ldflags "$(GO_LDFLAGS)" -o $@ .
|
go build -tags standalone -ldflags "$(GO_LDFLAGS)" -o $@ .
|
||||||
|
|
||||||
plugin: $(CHECKER_NAME).so
|
plugin: $(CHECKER_NAME).so
|
||||||
|
|
||||||
|
|
@ -21,5 +21,8 @@ $(CHECKER_NAME).so: $(CHECKER_SOURCES) $(wildcard plugin/*.go)
|
||||||
docker:
|
docker:
|
||||||
docker build --build-arg CHECKER_VERSION=$(CHECKER_VERSION) -t $(CHECKER_IMAGE) .
|
docker build --build-arg CHECKER_VERSION=$(CHECKER_VERSION) -t $(CHECKER_IMAGE) .
|
||||||
|
|
||||||
|
test:
|
||||||
|
go test -tags standalone ./...
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(CHECKER_NAME) $(CHECKER_NAME).so
|
rm -f $(CHECKER_NAME) $(CHECKER_NAME).so
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Definition is the package-level helper returned to the host by the
|
// Definition is the package-level helper returned to the host by the
|
||||||
// plugin entrypoint and used by sdk.NewServer via the provider's
|
// plugin entrypoint and used by server.New via the provider's
|
||||||
// CheckerDefinitionProvider implementation.
|
// CheckerDefinitionProvider implementation.
|
||||||
func Definition() *sdk.CheckerDefinition {
|
func Definition() *sdk.CheckerDefinition {
|
||||||
return &sdk.CheckerDefinition{
|
return &sdk.CheckerDefinition{
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
//go:build standalone
|
||||||
|
|
||||||
package checker
|
package checker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -5,14 +7,16 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
|
||||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
sdk "git.happydns.org/checker-sdk-go/checker"
|
||||||
|
"git.happydns.org/checker-sdk-go/checker/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RenderForm implements sdk.CheckerInteractive. It exposes the minimal
|
// RenderForm implements server.Interactive. It exposes the minimal
|
||||||
// inputs needed to bootstrap a standalone OPENPGPKEY/SMIMEA check: an
|
// inputs needed to bootstrap a standalone OPENPGPKEY/SMIMEA check: an
|
||||||
// email address (the local part is hashed into the owner name) and a
|
// email address (the local part is hashed into the owner name) and a
|
||||||
// kind selector. The DNS resolver and severity-tuning options mirror
|
// kind selector. The DNS resolver and severity-tuning options mirror
|
||||||
|
|
@ -63,7 +67,7 @@ func (p *emailKeyProvider) RenderForm() []sdk.CheckerOptionField {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseForm implements sdk.CheckerInteractive. It validates the inputs,
|
// ParseForm implements server.Interactive. It validates the inputs,
|
||||||
// resolves the DNS record matching the requested kind, and returns the
|
// resolves the DNS record matching the requested kind, and returns the
|
||||||
// CheckerOptions that Collect expects, including a synthesised service
|
// CheckerOptions that Collect expects, including a synthesised service
|
||||||
// envelope built from the live DNS answer.
|
// envelope built from the live DNS answer.
|
||||||
|
|
@ -102,7 +106,7 @@ func (p *emailKeyProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error
|
||||||
}
|
}
|
||||||
|
|
||||||
resolverOpt := strings.TrimSpace(r.FormValue(OptionResolver))
|
resolverOpt := strings.TrimSpace(r.FormValue(OptionResolver))
|
||||||
owner := dns.Fqdn(ownerHashHex(username) + "." + strings.TrimPrefix(prefix, ".") + "." + domain)
|
owner := dns.Fqdn(ownerHashHex(username) + "." + prefix + "." + domain)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(r.Context(), dnsTimeout*3)
|
ctx, cancel := context.WithTimeout(r.Context(), dnsTimeout*3)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
@ -160,12 +164,12 @@ func (p *emailKeyProvider) ParseForm(r *http.Request) (sdk.CheckerOptions, error
|
||||||
|
|
||||||
// parseFloatOr parses a decimal string, returning fallback on error.
|
// parseFloatOr parses a decimal string, returning fallback on error.
|
||||||
func parseFloatOr(s string, fallback float64) float64 {
|
func parseFloatOr(s string, fallback float64) float64 {
|
||||||
var f float64
|
f, err := strconv.ParseFloat(s, 64)
|
||||||
if _, err := fmt.Sscanf(s, "%f", &f); err != nil {
|
if err != nil {
|
||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile-time assertion that the provider implements the optional interface.
|
// Compile-time assertion that the provider implements the optional interface.
|
||||||
var _ sdk.CheckerInteractive = (*emailKeyProvider)(nil)
|
var _ server.Interactive = (*emailKeyProvider)(nil)
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -3,7 +3,7 @@ module git.happydns.org/checker-email-keys
|
||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.happydns.org/checker-sdk-go v1.1.0
|
git.happydns.org/checker-sdk-go v1.3.0
|
||||||
github.com/ProtonMail/go-crypto v1.1.0-alpha.0
|
github.com/ProtonMail/go-crypto v1.1.0-alpha.0
|
||||||
github.com/miekg/dns v1.1.72
|
github.com/miekg/dns v1.1.72
|
||||||
)
|
)
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -1,5 +1,5 @@
|
||||||
git.happydns.org/checker-sdk-go v1.1.0 h1:xgR39X1Mh+v481BHTDYHtGYFL1qRwldTsehazwSc67Y=
|
git.happydns.org/checker-sdk-go v1.3.0 h1:FG2kIhlJCzI0m35EhxSgn4UWc9M4ha6aZTeoChu4l7A=
|
||||||
git.happydns.org/checker-sdk-go v1.1.0/go.mod h1:aNAcfYFfbhvH9kJhE0Njp5GX0dQbxdRB0rJ0KvSC5nI=
|
git.happydns.org/checker-sdk-go v1.3.0/go.mod h1:aNAcfYFfbhvH9kJhE0Njp5GX0dQbxdRB0rJ0KvSC5nI=
|
||||||
github.com/ProtonMail/go-crypto v1.1.0-alpha.0 h1:nHGfwXmFvJrSR9xu8qL7BkO4DqTHXE9N5vPhgY2I+j0=
|
github.com/ProtonMail/go-crypto v1.1.0-alpha.0 h1:nHGfwXmFvJrSR9xu8qL7BkO4DqTHXE9N5vPhgY2I+j0=
|
||||||
github.com/ProtonMail/go-crypto v1.1.0-alpha.0/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
|
github.com/ProtonMail/go-crypto v1.1.0-alpha.0/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
|
||||||
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
|
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
|
||||||
|
|
|
||||||
6
main.go
6
main.go
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
emailkeys "git.happydns.org/checker-email-keys/checker"
|
emailkeys "git.happydns.org/checker-email-keys/checker"
|
||||||
sdk "git.happydns.org/checker-sdk-go/checker"
|
"git.happydns.org/checker-sdk-go/checker/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version is the standalone binary's version. Override with:
|
// Version is the standalone binary's version. Override with:
|
||||||
|
|
@ -20,8 +20,8 @@ func main() {
|
||||||
|
|
||||||
emailkeys.Version = Version
|
emailkeys.Version = Version
|
||||||
|
|
||||||
server := sdk.NewServer(emailkeys.Provider())
|
srv := server.New(emailkeys.Provider())
|
||||||
if err := server.ListenAndServe(*listenAddr); err != nil {
|
if err := srv.ListenAndServe(*listenAddr); err != nil {
|
||||||
log.Fatalf("server error: %v", err)
|
log.Fatalf("server error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue