Major Refactoring, Client can now be used as a library
Some checks failed
Build (artifact) / build (push) Failing after 1m3s
Some checks failed
Build (artifact) / build (push) Failing after 1m3s
This commit is contained in:
49
app/client/grpc.go
Normal file
49
app/client/grpc.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"git.nevets.tech/Keys/certman/app/shared"
|
||||
pb "git.nevets.tech/Keys/certman/proto/v1"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
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 := shared.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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user