Skip to content

Commit

Permalink
fix nebula-cert json printing
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDoanRivian committed Oct 10, 2024
1 parent f1fca4d commit cdf3713
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cmd/nebula-cert/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,19 @@ func printCert(args []string, out io.Writer, errOut io.Writer) error {
var qrBytes []byte
part := 0

var jsonCerts []cert.Certificate

for {
c, rawCert, err = cert.UnmarshalCertificateFromPEM(rawCert)
if err != nil {
return fmt.Errorf("error while unmarshaling cert: %s", err)
}

if *pf.json {
b, _ := json.Marshal(c)
out.Write(b)
out.Write([]byte("\n"))

jsonCerts = append(jsonCerts, c)
} else {
out.Write([]byte(c.String()))
out.Write([]byte("\n"))
_, _ = out.Write([]byte(c.String()))
_, _ = out.Write([]byte("\n"))
}

if *pf.outQRPath != "" {
Expand All @@ -80,6 +79,12 @@ func printCert(args []string, out io.Writer, errOut io.Writer) error {
part++
}

if *pf.json {
b, _ := json.Marshal(jsonCerts)
_, _ = out.Write(b)
_, _ = out.Write([]byte("\n"))
}

if *pf.outQRPath != "" {
b, err := qrcode.Encode(string(qrBytes), qrcode.Medium, -5)
if err != nil {
Expand Down

0 comments on commit cdf3713

Please sign in to comment.