Sfoglia il codice sorgente

Refactor debug utility

Herman Slatman 3 anni fa
parent
commit
edee01c80c
4 ha cambiato i file con 20 aggiunte e 5 eliminazioni
  1. 1 1
      acme/api/handler.go
  2. 2 2
      acme/challenge.go
  3. 4 2
      acme/db/nosql/challenge.go
  4. 13 0
      utils/debug/q/debug.go

+ 1 - 1
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 {

+ 2 - 2
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

+ 4 - 2
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 {

+ 13 - 0
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...)
+}