This repository has been archived by the owner on Apr 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
client.go
93 lines (80 loc) · 2.78 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package client
import (
"context"
"google.golang.org/api/option"
"google.golang.org/grpc"
"net/http"
"time"
"cloud.google.com/go/firestore"
)
const FuzzitEndpoint = "https://app.fuzzit.dev"
const Version = "v2.4.77"
type Target struct {
Name string `firestore:"target_name"`
PublicCorpus bool `firestore:"public_corpus"`
}
type Job struct {
TargetId string `firestore:"target_id"`
Args string `firestore:"args"`
Type string `firestore:"type"`
Engine string `firestore:"engine"`
Host string `firestore:"host"`
Revision string `firestore:"revision"`
Branch string `firestore:"branch"`
CPUs string `firestore:"cpus"`
Memory string `firestore:"memory"`
EnvironmentVariables []string `firestore:"environment_variables"`
Completed uint16 `firestore:"completed"`
Status string `firestore:"status"`
Namespace string `firestore:"namespace"`
StartedAt time.Time `firestore:"started_at,serverTimestamp"`
OrgId string `firestore:"org_id"`
}
type crash struct {
TargetName string `firestore:"target_name"`
PodId string `firestore:"pod_id"`
JobId string `firestore:"job_id"`
TargetId string `firestore:"target_id"`
OrgId string `firestore:"org_id"`
ExitCode uint32 `firestore:"exit_code"`
Type string `firestore:"type"`
Time time.Time `firestore:"time,serverTimestamp"`
V2 bool `firestore:"v2"`
LastLines string `firestore:"last_lines"`
}
type FuzzitClient struct {
Org string
Namespace string
ApiKey string
CustomToken string
Kind string `json:"kind"`
IdToken string `json:"idToken"`
RefreshToken string `json:"refreshToken"`
ExpiresIn string `json:"expiresIn"`
LastRefresh int64
firestoreClient *firestore.Client
httpClient *http.Client
currentJob Job // this is mainly used by the agent
jobId string // this is mainly used by the agent
updateDB bool // this is mainly used by the agent
fuzzerFilename string // this is mainly used by the agent
}
func NewFuzzitClient(apiKey string) (*FuzzitClient, error) {
ctx := context.Background()
c := &FuzzitClient{}
c.httpClient = &http.Client{Timeout: 120 * time.Second}
c.ApiKey = apiKey
conn, err := grpc.Dial("firestore.googleapis.com", grpc.WithInsecure())
if err != nil {
return nil, err
}
firestoreClient, err := firestore.NewClient(ctx, "fuzzit-b5fbf", option.WithGRPCConn(conn))
c.firestoreClient = firestoreClient
if err != nil {
return nil, err
}
if err := c.refreshToken(); err != nil {
return nil, err
}
return c, nil
}