MCPcopy Create free account
hub / github.com/evenh/intercert / watchForEvents

Function watchForEvents

client/tasks.go:22–56  ·  view source on GitHub ↗

Listen for events from the server, indicating that a certificate has been renewed with ACME

(domains []string, client api.CertificateIssuerClient)

Source from the content-addressed store, hash-verified

20
21// Listen for events from the server, indicating that a certificate has been renewed with ACME
22func watchForEvents(domains []string, client api.CertificateIssuerClient) func() {
23 return func() {
24 // TODO: Automatic resubscribe when a stream dies for some reason (e.g. server goes down)
25 renewalStream, err := client.OnCertificateRenewal(context.Background(), &api.CertificateRenewalNotificationRequest{
26 DnsNames: domains,
27 })
28
29 if err != nil {
30 log.Fatalf("Could not subscribe to renewal events: %v", err)
31 os.Exit(1)
32 }
33
34 log.Infof("Listening for certificate renewal events")
35
36 go func() {
37 for {
38 in, err := renewalStream.Recv()
39
40 if err == io.EOF {
41 break
42 }
43
44 if err != nil {
45 log.Warnf("Got error while listening for renewal events: %v", err)
46 break
47 }
48
49 log.Infof("Got notice from server that certificate for %s has been renewed. Queuing up re-fetch!", in.DnsName)
50 job := NewCertReq(in.DnsName, true)
51 job.Submit()
52 }
53 }()
54
55 }
56}
57
58// Check that every cert from the config is present in the file system
59func ensureCertsFromConfig(storage *CertStorage, wantedDomains []string) func() {

Callers 1

configureTasksFunction · 0.85

Calls 4

SubmitMethod · 0.95
NewCertReqFunction · 0.85
OnCertificateRenewalMethod · 0.65
RecvMethod · 0.65

Tested by

no test coverage detected