From edee01c80c639623b3433853d139cf458a55b2a8 Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Thu, 26 Jan 2023 13:41:01 +0100 Subject: [PATCH] Refactor debug utility --- acme/api/handler.go | 2 +- acme/challenge.go | 4 ++-- acme/db/nosql/challenge.go | 6 ++++-- utils/debug/q/debug.go | 13 +++++++++++++ 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 utils/debug/q/debug.go diff --git a/acme/api/handler.go b/acme/api/handler.go index 8f3b51db..ca5de02e 100644 --- a/acme/api/handler.go +++ b/acme/api/handler.go @@ -10,13 +10,13 @@ import ( "time" "github.com/go-chi/chi" - "github.com/ryboe/q" "github.com/smallstep/certificates/acme" "github.com/smallstep/certificates/api" "github.com/smallstep/certificates/api/render" "github.com/smallstep/certificates/authority" "github.com/smallstep/certificates/authority/provisioner" + "github.com/smallstep/certificates/utils/debug/q" ) func link(url, typ string) string { diff --git a/acme/challenge.go b/acme/challenge.go index 9eca34a5..72d8d171 100644 --- a/acme/challenge.go +++ b/acme/challenge.go @@ -26,11 +26,11 @@ import ( "time" "github.com/fxamacker/cbor/v2" - "github.com/smallstep/certificates/authority/provisioner" "go.step.sm/crypto/jose" "go.step.sm/crypto/pemutil" - "github.com/ryboe/q" + "github.com/smallstep/certificates/authority/provisioner" + "github.com/smallstep/certificates/utils/debug/q" ) type ChallengeType string diff --git a/acme/db/nosql/challenge.go b/acme/db/nosql/challenge.go index 05d23a1f..bb1c4080 100644 --- a/acme/db/nosql/challenge.go +++ b/acme/db/nosql/challenge.go @@ -6,9 +6,11 @@ import ( "time" "github.com/pkg/errors" - "github.com/ryboe/q" - "github.com/smallstep/certificates/acme" + "github.com/smallstep/nosql" + + "github.com/smallstep/certificates/acme" + "github.com/smallstep/certificates/utils/debug/q" ) type dbChallenge struct { diff --git a/utils/debug/q/debug.go b/utils/debug/q/debug.go new file mode 100644 index 00000000..e12c73cd --- /dev/null +++ b/utils/debug/q/debug.go @@ -0,0 +1,13 @@ +package q + +import ( + ryboeq "github.com/ryboe/q" +) + +func Q(v ...interface{}) { + // TODO(hs): do or do not call ryboeq.Q based on e.g. debug flag, + // runtime (go run vs. build), based on compiled or not. Goal would be + // to not debug in prod builds at all times. Ideally, never leave a leftover + // call to q.Q in the code, so panic if there is? + ryboeq.Q(v...) +}