Skip to content

Commit 356cd22

Browse files
authored
Merge pull request #66 from coreruleset/add-debugging
feat: add `--debug` flag and additional information
2 parents 52b2f0d + af5a961 commit 356cd22

6 files changed

Lines changed: 145 additions & 56 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Flags:
1919
-b, --bind string address to bind to (default "0.0.0.0")
2020
-h, --help help for albedo
2121
-p, --port int port to listen on (default 8080)
22+
--debug log debug information
2223
```
2324

2425
## Usage as a library
@@ -87,4 +88,9 @@ endpoints:
8788
- response status codes must lie in the range of [100,599]
8889
- the names and values of headers must be valid according to the HTTP specification;
8990
invalid headers will be dropped
91+
- path: /inspect
92+
methods: [any]
93+
contentType: any
94+
description: |
95+
Logs debug information about the received request, such as headers and body size.
9096
```

cmd/root.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cmd
22

33
import (
44
"context"
5+
"log/slog"
6+
"os"
57

68
"github.com/coreruleset/albedo/server"
79
"github.com/spf13/cobra"
@@ -18,19 +20,23 @@ func NewRootCommand() *cobra.Command {
1820
Short: "HTTP reflector and black hole",
1921
RunE: runE,
2022
}
21-
port := new(int)
22-
binding := new(string)
23-
rootCmd.PersistentFlags().IntVarP(port, "port", "p", 8080, "port to listen on")
24-
rootCmd.PersistentFlags().StringVarP(binding, "bind", "b", "0.0.0.0", "address to bind to")
23+
rootCmd.PersistentFlags().IntP("port", "p", 8080, "port to listen on")
24+
rootCmd.PersistentFlags().StringP("bind", "b", "0.0.0.0", "address to bind to")
25+
rootCmd.PersistentFlags().Bool("debug", false, "Log debugging information")
2526

2627
return rootCmd
2728
}
2829

2930
func runE(cmd *cobra.Command, _ []string) error {
3031
port, _ := cmd.Flags().GetInt("port")
3132
binding, _ := cmd.Flags().GetString("bind")
33+
debug, _ := cmd.Flags().GetBool("debug")
34+
if debug {
35+
handler := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})
36+
logger := slog.New(handler)
37+
slog.SetDefault(logger)
38+
}
3239

33-
_ = server.Start(binding, port)
34-
40+
server.Start(binding, port)
3541
return nil
3642
}

go.sum

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
2-
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
31
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
42
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
53
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
@@ -16,18 +14,10 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH
1614
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
1715
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
1816
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
19-
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
20-
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
21-
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
22-
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
2317
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
2418
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
25-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
26-
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
2719
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
2820
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
29-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
30-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3121
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
3222
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3323
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

server/capabilities.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ endpoints:
4848
methods: [PUT]
4949
contentType: any
5050
description: |
51-
Discards endpoint configurations previously created via "/configure_reflection"
51+
Discards endpoint configurations previously created via "/configure_reflection"
52+
- path: /inspect
53+
methods: [any]
54+
contentType: any
55+
description: |
56+
Logs debug information about the received request, such as headers and body size.

0 commit comments

Comments
 (0)