Skip to content

Commit 59a7fe6

Browse files
committed
Modularity(?)
Reviewed-on: https://git.froth.zone/sam/awl/pulls/77
1 parent 61ddbb3 commit 59a7fe6

14 files changed

+98
-296
lines changed

.github/ISSUE_TEMPLATE/bug.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Steps to reproduce the behavior:
1717
A clear and concise description of what you expected to happen.
1818

1919
**Screenshots / Logs**
20+
```
2021
Add `-v=4` and add the debug logs to the report here:
22+
```
2123

2224
**System information (please complete the following information):**
2325

.github/pull_request_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Please check the following:
44
55
1. Make sure you are targeting the `master` branch.
6-
2. Make sure that you test and format your contributions: `make test && make lint`
6+
2. Make sure that you test and format your contributions: `make full_test && make lint`
77
3. Describe what your pull request does and which issue you're targeting (if any)
88
99
-->

GNUmakefile

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ endif
1212
$(PROG): $(SOURCES)
1313
$(GO) build -o $(EXE) $(GOFLAGS) .
1414

15-
16-
ifeq ($(OS),Windows_NT)
1715
## install: installs awl
16+
ifeq ($(OS),Windows_NT)
1817
install:
1918
$(GO) install $(GOFLAGS) .
2019
else

README.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@ newer RFC query types, such as DNS-over-HTTPS and DNS-over-QUIC.
2424
Grab a prebuilt binary from the
2525
[release](https://git.froth.zone/sam/awl/releases) section.
2626

27+
### Package Managers
28+
29+
- AUR: [awl-dns-git](https://aur.archlinux.org/packages/awl-dns-git)
30+
2731
### From source
2832

2933
Dependencies:
3034

3135
- Go >= 1.18
32-
- GNU/BSD make or Plan 9 mk
36+
- GNU/BSD make or Plan 9 mk (if using the makefile/mkfile)
3337

34-
Make sure to recursively clone the repo:
38+
Using `go install` (recommended):
3539

3640
```sh
37-
git clone --recursive https://git.froth.zone/sam/awl
41+
go install git.froth.zone/sam/awl@latest
3842
```
3943

4044
Using the makefile:
@@ -44,12 +48,6 @@ make
4448
sudo make install
4549
```
4650

47-
Alternatively, using `go install`:
48-
49-
```sh
50-
go install git.froth.zone/sam/awl@latest
51-
```
52-
5351
## Contributing
5452

5553
Send a [pull request](https://git.froth.zone/sam/awl/pulls) our way. Prefer

cli/misc.go

+16-15
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
// ParseMiscArgs parses the wildcard arguments, drill style.
1717
// Only one command is supported at a time, so any extra information overrides previous.
1818
func ParseMiscArgs(args []string, opts *util.Options) error {
19-
var err error
20-
2119
for _, arg := range args {
2220
r, ok := dns.StringToType[strings.ToUpper(arg)]
2321

@@ -31,15 +29,15 @@ func ParseMiscArgs(args []string, opts *util.Options) error {
3129
switch {
3230
case strings.HasPrefix(arg, "tls://"):
3331
opts.TLS = true
34-
opts.Request.Server = arg[6:]
32+
opts.Request.Server = strings.TrimPrefix(opts.Request.Server, "tls://")
3533
opts.Logger.Info("DNS-over-TLS implicitly set")
3634
case strings.HasPrefix(arg, "https://"):
3735
opts.HTTPS = true
3836
opts.Request.Server = arg
3937
opts.Logger.Info("DNS-over-HTTPS implicitly set")
4038
case strings.HasPrefix(arg, "quic://"):
4139
opts.QUIC = true
42-
opts.Request.Server = arg[7:]
40+
opts.Request.Server = strings.TrimPrefix(opts.Request.Server, "quic://")
4341
opts.Logger.Info("DNS-over-QUIC implicitly set.")
4442
case strings.HasPrefix(arg, "sdns://"):
4543
opts.DNSCrypt = true
@@ -52,14 +50,15 @@ func ParseMiscArgs(args []string, opts *util.Options) error {
5250
// Dig-style +queries
5351
case strings.HasPrefix(arg, "+"):
5452
opts.Logger.Info(arg, "detected as a dig query")
55-
err = ParseDig(strings.ToLower(arg[1:]), opts)
5653

57-
if err != nil {
54+
if err := ParseDig(strings.ToLower(arg[1:]), opts); err != nil {
5855
return err
5956
}
6057

6158
// Domain names
6259
case strings.Contains(arg, "."):
60+
var err error
61+
6362
opts.Logger.Info(arg, "detected as a domain name")
6463
opts.Request.Name, err = idna.ToASCII(arg)
6564

@@ -74,6 +73,8 @@ func ParseMiscArgs(args []string, opts *util.Options) error {
7473

7574
// Domain?
7675
default:
76+
var err error
77+
7778
opts.Logger.Info(arg, "is unknown. Assuming domain")
7879
opts.Request.Name, err = idna.ToASCII(arg)
7980

@@ -89,16 +90,14 @@ func ParseMiscArgs(args []string, opts *util.Options) error {
8990
opts.Request.Name = "."
9091

9192
if opts.Request.Type == 0 {
93+
opts.Logger.Info("Query not specified, making an \"NS\" query")
9294
opts.Request.Type = dns.StringToType["NS"]
9395
}
94-
} else {
96+
} else if opts.Request.Type == 0 {
9597
opts.Logger.Info("Query not specified, making an \"A\" query")
96-
97-
if opts.Request.Type == 0 {
98-
opts.Request.Type = dns.StringToType["A"]
99-
}
98+
opts.Request.Type = dns.StringToType["A"]
10099
}
101-
//
100+
102101
if opts.Request.Server == "" {
103102
opts.Logger.Info("Server not specified, selecting a default")
104103
// Set "defaults" for each if there is no input
@@ -113,7 +112,7 @@ func ParseMiscArgs(args []string, opts *util.Options) error {
113112
case opts.QUIC:
114113
opts.Request.Server = "dns.adguard.com"
115114
default:
116-
//nolint:govet // This shadow is intentional
115+
var err error
117116
resolv, err := conf.GetDNSConfig()
118117

119118
if err != nil {
@@ -150,8 +149,10 @@ func ParseMiscArgs(args []string, opts *util.Options) error {
150149

151150
opts.Logger.Info("DNS server set to", opts.Request.Server)
152151

153-
// Make reverse adresses proper addresses
152+
// Make reverse addresses proper addresses
154153
if opts.Reverse {
154+
var err error
155+
155156
opts.Logger.Info("Making reverse DNS query proper *.arpa domain")
156157

157158
if dns.TypeToString[opts.Request.Type] == "A" {
@@ -168,7 +169,7 @@ func ParseMiscArgs(args []string, opts *util.Options) error {
168169
if !strings.HasSuffix(opts.Request.Name, ".") {
169170
opts.Request.Name = fmt.Sprintf("%s.", opts.Request.Name)
170171

171-
opts.Logger.Debug("Domain made canonical")
172+
opts.Logger.Info("Domain made canonical")
172173
}
173174

174175
return nil

conf/plan9.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2+
//go:build plan9
23

34
package conf
45

56
import (
67
"errors"
8+
"fmt"
9+
"os"
710
"strings"
811

912
"github.com/miekg/dns"
1013
)
1114

12-
// GetPlan9Config gets DNS information from Plan 9, because it's different from UNIX and Windows.
15+
// GetDNSConfig gets DNS information from Plan 9, because it's different from UNIX and Windows.
1316
// Plan 9 stores its network data in /net/ndb, which seems to be formatted a specific way
1417
// Yoink it and use it.
1518
//
1619
// See ndb(7).
17-
func GetPlan9Config(str string) (*dns.ClientConfig, error) {
20+
func GetDNSConfig() (*dns.ClientConfig, error) {
21+
dat, err := os.ReadFile("/net/ndb")
22+
if err != nil {
23+
return nil, fmt.Errorf("read ndb: %w", err)
24+
}
25+
26+
str := string(dat)
27+
1828
str = strings.ReplaceAll(str, "\n", "")
1929
spl := strings.FieldsFunc(str, splitChars)
2030

conf/plan9_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2+
//go:build plan9
23

34
package conf_test
45

@@ -11,6 +12,9 @@ import (
1112

1213
func TestGetPlan9Config(t *testing.T) {
1314
t.Parallel()
15+
if runtime.GOOS != "plan9" {
16+
t.Skip("Not running Plan 9, skipping")
17+
}
1418

1519
ndbs := []struct {
1620
in string

conf/unix.go

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
//go:build !windows
2+
//go:build unix || (!windows && !plan9 && !js && !zos)
3+
4+
// FIXME: Can remove the or on the preprocessor when Go 1.18 becomes obsolete
35

46
package conf
57

68
import (
79
"fmt"
8-
"os"
9-
"runtime"
1010

1111
"github.com/miekg/dns"
1212
)
1313

1414
// GetDNSConfig gets the DNS configuration, either from /etc/resolv.conf or somewhere else.
1515
func GetDNSConfig() (*dns.ClientConfig, error) {
16-
if runtime.GOOS == "plan9" {
17-
dat, err := os.ReadFile("/net/ndb")
18-
if err != nil {
19-
return nil, fmt.Errorf("plan9 ndb: %w", err)
20-
}
21-
22-
return GetPlan9Config(string(dat))
23-
} else {
24-
conf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
25-
if err != nil {
26-
return nil, fmt.Errorf("unix config: %w", err)
27-
}
28-
29-
return conf, nil
16+
conf, err := dns.ClientConfigFromFile("/etc/resolv.conf")
17+
if err != nil {
18+
return nil, fmt.Errorf("unix config: %w", err)
3019
}
20+
21+
return conf, nil
3122
}

conf/unix_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause
2-
//go:build !windows
2+
//go:build unix || (!windows && !plan9 && !js && !zos)
3+
4+
// FIXME: Can remove the or on the preprocessor when Go 1.18 becomes obsolete
35

46
package conf_test
57

@@ -12,8 +14,8 @@ import (
1214
)
1315

1416
func TestNonWinConfig(t *testing.T) {
15-
if runtime.GOOS == "windows" {
16-
t.Skip("Running Windows, skipping")
17+
if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
18+
t.Skip("Not running Unix-like, skipping")
1719
}
1820

1921
conf, err := conf.GetDNSConfig()

conf/win_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
)
1313

1414
func TestWinConfig(t *testing.T) {
15+
t.Parallel()
16+
1517
if runtime.GOOS != "windows" {
1618
t.Skip("Not running Windows, skipping")
1719
}

go.mod

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,17 @@ require (
2020
github.com/ameshkov/dnsstamps v1.0.3 // indirect
2121
github.com/golang/mock v1.6.0 // indirect
2222
github.com/google/go-cmp v0.5.8 // indirect
23+
github.com/kr/pretty v0.3.0 // indirect
2324
github.com/marten-seemann/qtls-go1-19 v0.1.0 // indirect
24-
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
25+
golang.org/x/exp v0.0.0-20220827204233-334a2380cb91 // indirect
2526
)
2627

2728
require (
28-
github.com/cheekybits/genny v1.0.0 // indirect
2929
github.com/fsnotify/fsnotify v1.5.4 // indirect
3030
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
31-
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
32-
github.com/marten-seemann/qtls-go1-17 v0.1.2 // indirect
3331
github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect
3432
github.com/nxadm/tail v1.4.8 // indirect
3533
github.com/onsi/ginkgo v1.16.5 // indirect
36-
github.com/stretchr/testify v1.8.0 // indirect
3734
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d // indirect
3835
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
3936
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261

0 commit comments

Comments
 (0)