58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"time"
|
|
|
|
"git.nevets.tech/Keys/CertManager/internal"
|
|
pb "git.nevets.tech/Keys/CertManager/proto/v1"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
)
|
|
|
|
var (
|
|
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
|
|
caFile = flag.String("ca_file", "", "The file containing the CA root cert file")
|
|
serverAddr = flag.String("addr", "localhost:50051", "The server address in the format of host:port")
|
|
serverHostOverride = flag.String("server_host_override", "x.test.example.com", "The server name used to verify the hostname returned by the TLS handshake")
|
|
)
|
|
|
|
func SendHook(domain string) {
|
|
conn, err := grpc.NewClient(
|
|
"unix:///run/certman.sock",
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
)
|
|
if err != nil {
|
|
log.Fatalf("fail to dial: %v", err)
|
|
}
|
|
defer conn.Close()
|
|
client := pb.NewHookServiceClient(conn)
|
|
|
|
hooks, err := internal.PostPullHooks(domain)
|
|
if err != nil {
|
|
fmt.Printf("Error getting hooks: %v\n", err)
|
|
return
|
|
}
|
|
|
|
for _, hook := range hooks {
|
|
sendHook(client, hook)
|
|
}
|
|
}
|
|
|
|
func sendHook(client pb.HookServiceClient, hook *pb.Hook) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
res, err := client.ExecuteHook(ctx, &pb.ExecuteHookRequest{Hook: hook})
|
|
if err != nil {
|
|
fmt.Printf("Error executing hook: %v\n", err)
|
|
return
|
|
}
|
|
|
|
if res.GetError() != "" {
|
|
fmt.Printf("Error executing hook: %s\n", res.GetError())
|
|
}
|
|
}
|