Skip to content

Commit

Permalink
Fix the logger issue
Browse files Browse the repository at this point in the history
  • Loading branch information
atkrad committed May 16, 2023
1 parent b80e460 commit 2a2afc6
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 71 deletions.
21 changes: 14 additions & 7 deletions internal/app/wait4x/cmd/dns/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package dns

import (
"errors"
"github.com/go-logr/logr"
"github.com/spf13/cobra"
"wait4x.dev/v2/checker/dns"
"wait4x.dev/v2/waiter"
Expand All @@ -34,14 +35,14 @@ func NewACommand() *cobra.Command {
return nil
},
Example: `
# Check A existence
wait4x dns A wait4x.dev
# Check A existence
wait4x dns A wait4x.dev
# Check A is wait4x.dev
wait4x dns A wait4x.dev 172.67.154.180
# Check A is wait4x.dev
wait4x dns A wait4x.dev 172.67.154.180
# Check A by defined nameserver
wait4x dns A wait4x.dev 172.67.154.180 -n gordon.ns.cloudflare.com
# Check A by defined nameserver
wait4x dns A wait4x.dev 172.67.154.180 -n gordon.ns.cloudflare.com
`,
RunE: runA,
}
Expand All @@ -53,9 +54,13 @@ func runA(cmd *cobra.Command, args []string) error {
interval, _ := cmd.Flags().GetDuration("interval")
timeout, _ := cmd.Flags().GetDuration("timeout")
invertCheck, _ := cmd.Flags().GetBool("invert-check")

nameserver, _ := cmd.Flags().GetString("nameserver")

logger, err := logr.FromContext(cmd.Context())
if err != nil {
return err
}

address := args[0]
var expectedValue string
if len(args) == 2 {
Expand All @@ -67,10 +72,12 @@ func runA(cmd *cobra.Command, args []string) error {
dns.WithExpectedValue(expectedValue),
dns.WithNameServer(nameserver),
)

return waiter.WaitContext(cmd.Context(),
dc,
waiter.WithTimeout(timeout),
waiter.WithInterval(interval),
waiter.WithInvertCheck(invertCheck),
waiter.WithLogger(logger),
)
}
21 changes: 14 additions & 7 deletions internal/app/wait4x/cmd/dns/aaaa.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package dns

import (
"errors"
"github.com/go-logr/logr"
"github.com/spf13/cobra"
"wait4x.dev/v2/checker/dns"
"wait4x.dev/v2/waiter"
Expand All @@ -34,14 +35,14 @@ func NewAAAACommand() *cobra.Command {
return nil
},
Example: `
# Check AAAA existence
wait4x dns AAAA wait4x.dev
# Check AAAA existence
wait4x dns AAAA wait4x.dev
# Check AAAA is wait4x.dev
wait4x dns AAAA wait4x.dev '2606:4700:3033::ac43:9ab4'
# Check AAAA is wait4x.dev
wait4x dns AAAA wait4x.dev '2606:4700:3033::ac43:9ab4'
# Check AAAA by defined nameserver
wait4x dns AAAA wait4x.dev '2606:4700:3033::ac43:9ab4' -n gordon.ns.cloudflare.com
# Check AAAA by defined nameserver
wait4x dns AAAA wait4x.dev '2606:4700:3033::ac43:9ab4' -n gordon.ns.cloudflare.com
`,
RunE: runAAAA,
}
Expand All @@ -53,9 +54,13 @@ func runAAAA(cmd *cobra.Command, args []string) error {
interval, _ := cmd.Flags().GetDuration("interval")
timeout, _ := cmd.Flags().GetDuration("timeout")
invertCheck, _ := cmd.Flags().GetBool("invert-check")

nameserver, _ := cmd.Flags().GetString("nameserver")

logger, err := logr.FromContext(cmd.Context())
if err != nil {
return err
}

address := args[0]
var expectedValue string
if len(args) == 2 {
Expand All @@ -67,10 +72,12 @@ func runAAAA(cmd *cobra.Command, args []string) error {
dns.WithExpectedValue(expectedValue),
dns.WithNameServer(nameserver),
)

return waiter.WaitContext(cmd.Context(),
dc,
waiter.WithTimeout(timeout),
waiter.WithInterval(interval),
waiter.WithInvertCheck(invertCheck),
waiter.WithLogger(logger),
)
}
21 changes: 14 additions & 7 deletions internal/app/wait4x/cmd/dns/cname.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package dns

import (
"errors"
"github.com/go-logr/logr"
"github.com/spf13/cobra"
"wait4x.dev/v2/checker/dns"
"wait4x.dev/v2/waiter"
Expand All @@ -34,14 +35,14 @@ func NewCNAMECommand() *cobra.Command {
return nil
},
Example: `
# Check CNAME existence
wait4x dns CNAME 172.67.154.180
# Check CNAME existence
wait4x dns CNAME 172.67.154.180
# Check CNAME is wait4x.dev
wait4x dns CNAME 172.67.154.180 wait4x.dev
# Check CNAME is wait4x.dev
wait4x dns CNAME 172.67.154.180 wait4x.dev
# Check CNAME by defined nameserver
wait4x dns CNAME 172.67.154.180 -n gordon.ns.cloudflare.com
# Check CNAME by defined nameserver
wait4x dns CNAME 172.67.154.180 -n gordon.ns.cloudflare.com
`,
RunE: runCNAME,
}
Expand All @@ -53,9 +54,13 @@ func runCNAME(cmd *cobra.Command, args []string) error {
interval, _ := cmd.Flags().GetDuration("interval")
timeout, _ := cmd.Flags().GetDuration("timeout")
invertCheck, _ := cmd.Flags().GetBool("invert-check")

nameserver, _ := cmd.Flags().GetString("nameserver")

logger, err := logr.FromContext(cmd.Context())
if err != nil {
return err
}

address := args[0]
var expectedValue string
if len(args) == 2 {
Expand All @@ -67,10 +72,12 @@ func runCNAME(cmd *cobra.Command, args []string) error {
dns.WithExpectedValue(expectedValue),
dns.WithNameServer(nameserver),
)

return waiter.WaitContext(cmd.Context(),
dc,
waiter.WithTimeout(timeout),
waiter.WithInterval(interval),
waiter.WithInvertCheck(invertCheck),
waiter.WithLogger(logger),
)
}
31 changes: 3 additions & 28 deletions internal/app/wait4x/cmd/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,16 @@
package dns

import (
"errors"

"github.com/spf13/cobra"
)

func NewDNSCommand(parent *cobra.Command) *cobra.Command {
func NewDNSCommand() *cobra.Command {
command := &cobra.Command{
Use: "dns COMMAND [flags] [--command [args...]]",
Use: "dns",
Short: "Check DNS records",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("ADDRESS is required argument for the dns command")
}

return nil
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
err := parent.PersistentPreRunE(cmd, args)
if err != nil {
return err
}

return nil
},
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
err := parent.PersistentPostRunE(cmd, args)
if err != nil {
return err
}

return nil
},
}

command.Flags().String("nameserver", "", " Address of the nameserver to send packets to")
command.PersistentFlags().String("nameserver", "", " Address of the nameserver to send packets to")

command.AddCommand(NewACommand())
command.AddCommand(NewAAAACommand())
Expand Down
21 changes: 14 additions & 7 deletions internal/app/wait4x/cmd/dns/mx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package dns

import (
"errors"
"github.com/go-logr/logr"
"github.com/spf13/cobra"
"wait4x.dev/v2/checker/dns"
"wait4x.dev/v2/waiter"
Expand All @@ -34,14 +35,14 @@ func NewMXCommand() *cobra.Command {
return nil
},
Example: `
# Check MX existence
wait4x dns MX wait4x.dev
# Check MX existence
wait4x dns MX wait4x.dev
# Check MX is wait4x.dev
wait4x dns MX wait4x.dev 'route1.mx.cloudflare.net'
# Check MX is wait4x.dev
wait4x dns MX wait4x.dev 'route1.mx.cloudflare.net'
# Check MX by defined nameserver
wait4x dns MX wait4x.dev 'route1.mx.cloudflare.net.' -n gordon.ns.cloudflare.com
# Check MX by defined nameserver
wait4x dns MX wait4x.dev 'route1.mx.cloudflare.net.' -n gordon.ns.cloudflare.com
`,
RunE: runMX,
}
Expand All @@ -53,9 +54,13 @@ func runMX(cmd *cobra.Command, args []string) error {
interval, _ := cmd.Flags().GetDuration("interval")
timeout, _ := cmd.Flags().GetDuration("timeout")
invertCheck, _ := cmd.Flags().GetBool("invert-check")

nameserver, _ := cmd.Flags().GetString("nameserver")

logger, err := logr.FromContext(cmd.Context())
if err != nil {
return err
}

address := args[0]
var expectedValue string
if len(args) == 2 {
Expand All @@ -67,10 +72,12 @@ func runMX(cmd *cobra.Command, args []string) error {
dns.WithExpectedValue(expectedValue),
dns.WithNameServer(nameserver),
)

return waiter.WaitContext(cmd.Context(),
dc,
waiter.WithTimeout(timeout),
waiter.WithInterval(interval),
waiter.WithInvertCheck(invertCheck),
waiter.WithLogger(logger),
)
}
21 changes: 14 additions & 7 deletions internal/app/wait4x/cmd/dns/ns.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package dns

import (
"errors"
"github.com/go-logr/logr"
"github.com/spf13/cobra"
"wait4x.dev/v2/checker/dns"
"wait4x.dev/v2/waiter"
Expand All @@ -34,14 +35,14 @@ func NewNSCommand() *cobra.Command {
return nil
},
Example: `
# Check NS existence
wait4x dns NS wait4x.dev
# Check NS existence
wait4x dns NS wait4x.dev
# Check NS is wait4x.dev
wait4x dns NS wait4x.dev 'emma.ns.cloudflare.com'
# Check NS is wait4x.dev
wait4x dns NS wait4x.dev 'emma.ns.cloudflare.com'
# Check NS by defined nameserver
wait4x dns NS wait4x.dev 'emma.ns.cloudflare.com' -n gordon.ns.cloudflare.com
# Check NS by defined nameserver
wait4x dns NS wait4x.dev 'emma.ns.cloudflare.com' -n gordon.ns.cloudflare.com
`,
RunE: runNS,
}
Expand All @@ -53,9 +54,13 @@ func runNS(cmd *cobra.Command, args []string) error {
interval, _ := cmd.Flags().GetDuration("interval")
timeout, _ := cmd.Flags().GetDuration("timeout")
invertCheck, _ := cmd.Flags().GetBool("invert-check")

nameserver, _ := cmd.Flags().GetString("nameserver")

logger, err := logr.FromContext(cmd.Context())
if err != nil {
return err
}

address := args[0]
var expectedValue string
if len(args) == 2 {
Expand All @@ -67,10 +72,12 @@ func runNS(cmd *cobra.Command, args []string) error {
dns.WithExpectedValue(expectedValue),
dns.WithNameServer(nameserver),
)

return waiter.WaitContext(cmd.Context(),
dc,
waiter.WithTimeout(timeout),
waiter.WithInterval(interval),
waiter.WithInvertCheck(invertCheck),
waiter.WithLogger(logger),
)
}
20 changes: 13 additions & 7 deletions internal/app/wait4x/cmd/dns/txt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package dns

import (
"errors"
"github.com/go-logr/logr"
"github.com/spf13/cobra"
"wait4x.dev/v2/checker/dns"
"wait4x.dev/v2/waiter"
Expand All @@ -34,14 +35,14 @@ func NewTXTCommand() *cobra.Command {
return nil
},
Example: `
# Check TXT existence
wait4x dns TXT wait4x.dev
# Check TXT existence
wait4x dns TXT wait4x.dev
# Check TXT is wait4x.dev
wait4x dns TXT wait4x.dev 'include:_spf.mx.cloudflare.net'
# Check TXT is wait4x.dev
wait4x dns TXT wait4x.dev 'include:_spf.mx.cloudflare.net'
# Check TXT by defined nameserver
wait4x dns TXT wait4x.dev 'include:_spf.mx.cloudflare.net' -n gordon.ns.cloudflare.com
# Check TXT by defined nameserver
wait4x dns TXT wait4x.dev 'include:_spf.mx.cloudflare.net' -n gordon.ns.cloudflare.com
`,
RunE: runTXT,
}
Expand All @@ -53,9 +54,13 @@ func runTXT(cmd *cobra.Command, args []string) error {
interval, _ := cmd.Flags().GetDuration("interval")
timeout, _ := cmd.Flags().GetDuration("timeout")
invertCheck, _ := cmd.Flags().GetBool("invert-check")

nameserver, _ := cmd.Flags().GetString("nameserver")

logger, err := logr.FromContext(cmd.Context())
if err != nil {
return err
}

address := args[0]
var expectedValue string
if len(args) == 2 {
Expand All @@ -72,5 +77,6 @@ func runTXT(cmd *cobra.Command, args []string) error {
waiter.WithTimeout(timeout),
waiter.WithInterval(interval),
waiter.WithInvertCheck(invertCheck),
waiter.WithLogger(logger),
)
}
2 changes: 1 addition & 1 deletion internal/app/wait4x/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func NewRootCommand() *cobra.Command {
func Execute() {
rootCmd := NewRootCommand()
rootCmd.AddCommand(NewTCPCommand())
rootCmd.AddCommand(dns.NewDNSCommand(rootCmd))
rootCmd.AddCommand(dns.NewDNSCommand())
rootCmd.AddCommand(NewHTTPCommand())
rootCmd.AddCommand(NewPostgresqlCommand())
rootCmd.AddCommand(NewMysqlCommand())
Expand Down

0 comments on commit 2a2afc6

Please sign in to comment.