Skip to content

Commit

Permalink
feat: client add mTLS
Browse files Browse the repository at this point in the history
Signed-off-by: Zufar Dhiyaullhaq <[email protected]>
  • Loading branch information
zufardhiyaulhaq committed Oct 6, 2024
1 parent a0fdf88 commit 5d4c9ed
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"context"
"crypto/tls"
"log"
"net/http"

pbcloudevents "github.com/cloudevents/sdk-go/binding/format/protobuf/v2"
cloudevents "github.com/cloudevents/sdk-go/v2"
Expand All @@ -18,6 +20,13 @@ func main() {
log.Fatalf("failed to create protocol: %s", err.Error())
}

// Load the certificate
p.Client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
Certificates: []tls.Certificate{loadCertificate()},
},
}

c, err := cloudevents.NewClient(p, cloudevents.WithTimeNow(), cloudevents.WithUUIDs())
if err != nil {
log.Fatalf("failed to create client, %v", err)
Expand All @@ -44,3 +53,11 @@ func main() {
}
}
}

func loadCertificate() tls.Certificate {
cert, err := tls.LoadX509KeyPair("path/to/certificate.crt", "path/to/private.key")
if err != nil {
log.Fatalf("failed to load certificate: %v", err)
}
return cert
}

0 comments on commit 5d4c9ed

Please sign in to comment.