Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.24

- name: Test and audit
run: make tidy audit test

- name: Build
run: go build -v ./...
run: make build

- name: Test
run: go test -v ./...
- name: Check no dirty
run: make no-dirty
37 changes: 36 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,53 @@

.PHONY: all
all: tidy build test audit
@echo "all done"


.PHONY: build
build:
@echo "building..."
go build -v ./...


.PHONY: test
test:
go test ./...


.PHONY: tidy
tidy:
@echo "tidy and fmt..."
go mod tidy -v
go fmt ./...


.PHONY: audit
audit:
@echo "running audit checks..."
go mod verify
go vet ./...
go list -m all
go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./...
go run golang.org/x/vuln/cmd/govulncheck@latest ./...


no-dirty:
@echo "checking for uncommitted changes..."
git diff --exit-code
git diff --cached --exit-code


.PHONY: example
example:
go run ./_examples/up-and-down


.PHONY: acme-like
acme-like:
go run ./_examples/acme-like


.PHONY: list-records
list-records:
go run ./_examples/list-records

96 changes: 96 additions & 0 deletions _examples/acme-cleanup/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package main

import (
"context"
"fmt"
"os"
"os/signal"
"strings"
"sync"
"time"

"github.com/libdns/libdns"
"github.com/libdns/loopia"
)

func exitOnError(err error) {
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
}

func main() {
user := os.Getenv("LOOPIA_USER")
password := os.Getenv("LOOPIA_PASSWORD")
zone := os.Getenv("ZONE")
if zone == "" {
fmt.Fprintf(os.Stderr, "ZONE not set\n")
os.Exit(1)
}

if user == "" {
exitOnError(fmt.Errorf("user is not set"))
}

if password == "" {
exitOnError(fmt.Errorf("password is not set"))
}

fmt.Printf("zone: %s, user: %s\n", zone, user)

var wg sync.WaitGroup
wg.Add(1)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
go show(ctx, &wg, zone, user, password)

// Wait for SIGINT.
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt)
go func() {
<-sig
cancel()
}()

wg.Wait()
fmt.Println("Done!")
}

func show(ctx context.Context, wg *sync.WaitGroup, zone, user, password string) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
p := &loopia.Provider{
Username: user,
Password: password,
}
fmt.Println("getting records")
resAll, err := p.GetRecords(ctx, zone)
exitOnError(err)
printRecords("All records", resAll)
toDelete := []libdns.Record{}
for _, r := range resAll {
rr := r.RR()
if rr.Type == "TXT" && strings.Contains(rr.Name, "_acme-challenge") {
toDelete = append(toDelete, r)
}
}

if len(toDelete) > 0 {
fmt.Println("deleting records")
res, err := p.DeleteRecords(ctx, zone, toDelete)
if err != nil {
fmt.Printf(" error deleting %s\n", err)
} else {
printRecords("Deleted records", res)
}
}

wg.Done()
}

func printRecords(title string, records []libdns.Record) {
fmt.Println(title)
for i, r := range records {
fmt.Printf(" [%d] %+v\n", i, r)
}
}
10 changes: 8 additions & 2 deletions _examples/acme-like/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ func main() {
if password == "" {
exitOnError(fmt.Errorf("password is not set"))
}
host := "test.app"
if len(os.Args) > 1 && os.Args[1] != "" {
host = os.Args[1]
}

name := "_acme-challenge." + host

fmt.Printf("zone: %s, user: %s\n", zone, user)
fmt.Printf("zone: %s, user: %s, host: %s\n", zone, user, host)
p := &loopia.Provider{
Username: user,
Password: password,
Expand All @@ -43,7 +49,7 @@ func main() {
fmt.Println("appending")
res, err := p.AppendRecords(ctx, zone,
[]libdns.Record{
{Name: "_acme-challenge.test", Type: "TXT", Value: "Zgu7tw287LB-LpXyTHYLeROag9-4CLHnM77zvTEvH6o"},
libdns.TXT{Name: name, Text: "Zgu7tw287LB-LpXyTHYLeROag9-4CLHnM77zvTEvH6o"},
})
exitOnError(err)
printRecords("after append", res)
Expand Down
Loading