Skip to content

Commit

Permalink
add -debug flag to cmd/aws-sign-request
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisaaronland committed Mar 28, 2024
1 parent 9d61aa9 commit 53c7192
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ Usage of ./bin/aws-sign-request:
If empty then the value of the region associated with the AWS config/credentials will be used.
-credentials-uri string
A valid aaronland/go-aws-auth config URI.
-debug
Enable verbose debug logging to STDOUT.
-do
If true then execute the signed request and output the response to STDOUT.
-header value
Expand Down
10 changes: 9 additions & 1 deletion cmd/aws-sign-request/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/aaronland/go-aws-auth"
"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"github.com/aws/smithy-go/logging"
"github.com/sfomuseum/go-flags/multi"
)

Expand All @@ -30,6 +31,7 @@ func main() {
var method string
var uri string
var do bool
var debug bool

flag.StringVar(&api_signing_name, "api-signing-name", "", "The name the API uses to identify the service the request is scoped to.")
flag.StringVar(&api_signing_region, "api-signing-region", "", "If empty then the value of the region associated with the AWS config/credentials will be used.")
Expand All @@ -39,6 +41,7 @@ func main() {
flag.StringVar(&credentials_uri, "credentials-uri", "", "A valid aaronland/go-aws-auth config URI.")
flag.BoolVar(&do, "do", false, "If true then execute the signed request and output the response to STDOUT.")
flag.Var(&headers, "header", "Zero or more HTTP headers to assign to the request in the form of key=value.")
flag.BoolVar(&debug, "debug", false, "Enable verbose debug logging to STDOUT.")

flag.Parse()

Expand Down Expand Up @@ -97,7 +100,12 @@ func main() {
req.Header.Set(h.Key(), h.Value().(string))
}

signer := v4.NewSigner()
signer := v4.NewSigner(func(opts *v4.SignerOptions) {
if debug {
opts.LogSigning = true
opts.Logger = logging.NewStandardLogger(os.Stdout)
}
})

err = signer.SignHTTP(ctx, creds, req, body_sha256, api_signing_name, api_signing_region, time.Now())

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/iam v1.31.3
github.com/aws/aws-sdk-go-v2/service/ssm v1.49.4
github.com/aws/aws-sdk-go-v2/service/sts v1.28.5
github.com/aws/smithy-go v1.20.1
github.com/go-ini/ini v1.67.0
github.com/sfomuseum/go-flags v0.10.0
github.com/sfomuseum/iso8601duration v1.1.0
Expand All @@ -24,6 +25,5 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.6 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.3 // indirect
github.com/aws/smithy-go v1.20.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
)

0 comments on commit 53c7192

Please sign in to comment.