Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Commit 46ff163

Browse files
author
Yevgeny Pats
committed
add firestore public client
1 parent 3d846c6 commit 46ff163

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

client/client.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package client
22

33
import (
4+
"context"
5+
"google.golang.org/api/option"
6+
"google.golang.org/grpc"
47
"net/http"
58
"time"
69

710
"cloud.google.com/go/firestore"
811
)
912

1013
const FuzzitEndpoint = "https://app.fuzzit.dev"
11-
const Version = "v2.4.53"
14+
const Version = "v2.4.54"
1215

1316
type Target struct {
1417
Name string `firestore:"target_name"`
@@ -61,19 +64,27 @@ type FuzzitClient struct {
6164
fuzzerFilename string // this is mainly used by the agent
6265
}
6366

64-
func NewUnAuthenticatedClient() *FuzzitClient {
65-
c := &FuzzitClient{}
66-
c.httpClient = &http.Client{Timeout: 120 * time.Second}
67-
return c
68-
}
69-
7067
func NewFuzzitClient(apiKey string) (*FuzzitClient, error) {
68+
ctx := context.Background()
69+
7170
c := &FuzzitClient{}
7271
c.httpClient = &http.Client{Timeout: 120 * time.Second}
7372
c.ApiKey = apiKey
74-
err := c.refreshToken()
73+
74+
conn, err := grpc.Dial("firestore.googleapis.com", grpc.WithInsecure())
75+
if err != nil {
76+
return nil, err
77+
}
78+
79+
firestoreClient, err := firestore.NewClient(ctx, "fuzzit-b5fbf", option.WithGRPCConn(conn))
80+
c.firestoreClient = firestoreClient
7581
if err != nil {
7682
return nil, err
7783
}
84+
85+
if err := c.refreshToken(); err != nil {
86+
return nil, err
87+
}
88+
7889
return c, nil
7990
}

client/commands_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import (
88
)
99

1010
func TestDownloadAndExtractCorpus(t *testing.T) {
11-
unAuthenticatedClient := NewUnAuthenticatedClient()
11+
unAuthenticatedClient, err := NewFuzzitClient("")
12+
if err != nil {
13+
t.Fatal(err)
14+
}
1215
unAuthenticatedClient.Org = "fuzzitdev"
1316

1417
authenticatedClient, err := NewFuzzitClient(os.Getenv("FUZZIT_API_KEY"))
@@ -54,7 +57,10 @@ func TestDownloadAndExtractCorpus(t *testing.T) {
5457
}
5558

5659
func TestCreateLocalJob(t *testing.T) {
57-
unAuthenticatedClient := NewUnAuthenticatedClient()
60+
unAuthenticatedClient, err := NewFuzzitClient("")
61+
if err != nil {
62+
t.Fatal(err)
63+
}
5864
unAuthenticatedClient.Org = "fuzzitdev"
5965

6066
authenticatedClient, err := NewFuzzitClient(os.Getenv("FUZZIT_API_KEY"))

cmd/root.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,9 @@ var rootCmd = &cobra.Command{
3535
PersistentPreRun: func(cmd *cobra.Command, args []string) {
3636
apiKey := viper.GetString("api-key")
3737
var err error
38-
if apiKey != "" {
39-
gFuzzitClient, err = client.NewFuzzitClient(apiKey)
40-
if err != nil {
41-
log.Fatalln(err)
42-
}
43-
} else {
44-
gFuzzitClient = client.NewUnAuthenticatedClient()
38+
gFuzzitClient, err = client.NewFuzzitClient(apiKey)
39+
if err != nil {
40+
log.Fatalln(err)
4541
}
4642
},
4743
}

0 commit comments

Comments
 (0)