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

Commit 4e805bb

Browse files
author
Yevgeny Pats
committed
FUZZIT_API_KEY now supports environment variable + sanity is regression now
1 parent 15bf7dd commit 4e805bb

File tree

10 files changed

+149
-117
lines changed

10 files changed

+149
-117
lines changed

.goreleaser.yml

+74-74
Original file line numberDiff line numberDiff line change
@@ -59,77 +59,77 @@ brews:
5959
# Default is empty.
6060
description: "Continuous Fuzzing Made Simple."
6161

62-
snapcrafts:
63-
-
64-
# You can change the name of the package.
65-
# Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}`
66-
# name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
67-
68-
name: fuzzit
69-
70-
# Wether to publish the snap to the snapcraft store.
71-
# Remember you need to `snapcraft login` first.
72-
# Defaults to false.
73-
publish: true
74-
75-
# Single-line elevator pitch for your amazing snap.
76-
# 79 char long at most.
77-
summary: Software to integrate continuous fuzzing to c/c++/go/rust projects.
78-
79-
description: Continuous fuzzing as a service made simple with fuzzit.
80-
81-
# A guardrail to prevent you from releasing a snap to all your users before
82-
# it is ready.
83-
# `devel` will let you release only to the `edge` and `beta` channels in the
84-
# store. `stable` will let you release also to the `candidate` and `stable`
85-
# channels. More info about channels here:
86-
# https://snapcraft.io/docs/reference/channels
87-
grade: stable
88-
89-
# Snaps can be setup to follow three different confinement policies:
90-
# `strict`, `devmode` and `classic`. A strict confinement where the snap
91-
# can only read and write in its own namespace is recommended. Extra
92-
# permissions for strict snaps can be declared as `plugs` for the app, which
93-
# are explained later. More info about confinement here:
94-
# https://snapcraft.io/docs/reference/confinement
95-
confinement: strict
96-
97-
# Your app's license, based on SPDX license expressions: https://spdx.org/licenses
98-
# Default is empty.
99-
license: Apache-2.0
100-
101-
# A snap of type base to be used as the execution environment for this snap.
102-
# Valid values are:
103-
# * bare - Empty base snap;
104-
# * core - Ubuntu Core 16;
105-
# * core18 - Ubuntu Core 18.
106-
# Default is empty.
107-
base: core18
108-
109-
# Each binary built by GoReleaser is an app inside the snap. In this section
110-
# you can declare extra details for those binaries. It is optional.
111-
apps:
112-
113-
# The name of the app must be the same name as the binary built or the snapcraft name.
114-
fuzzit:
115-
116-
# If your app requires extra permissions to work outside of its default
117-
# confined space, declare them here.
118-
# You can read the documentation about the available plugs and the
119-
# things they allow:
120-
# https://snapcraft.io/docs/reference/interfaces.
121-
plugs: ["network", "personal-files"]
122-
123-
# Bash completion snippet. More information about completion here:
124-
# https://docs.snapcraft.io/tab-completion-for-snaps.
125-
# completer: drumroll-completion.bash
126-
127-
# Allows plugs to be configured. Plugs like system-files and personal-files
128-
# require this.
129-
# Default is empty.
130-
plugs:
131-
personal-files:
132-
read:
133-
- $HOME/.fuzzit.cache
134-
write:
135-
- $HOME/.fuzzit.cache
62+
#snapcrafts:
63+
# -
64+
# # You can change the name of the package.
65+
# # Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}`
66+
# # name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
67+
#
68+
# name: fuzzit
69+
#
70+
# # Wether to publish the snap to the snapcraft store.
71+
# # Remember you need to `snapcraft login` first.
72+
# # Defaults to false.
73+
# publish: true
74+
#
75+
# # Single-line elevator pitch for your amazing snap.
76+
# # 79 char long at most.
77+
# summary: Software to integrate continuous fuzzing to c/c++/go/rust projects.
78+
#
79+
# description: Continuous fuzzing as a service made simple with fuzzit.
80+
#
81+
# # A guardrail to prevent you from releasing a snap to all your users before
82+
# # it is ready.
83+
# # `devel` will let you release only to the `edge` and `beta` channels in the
84+
# # store. `stable` will let you release also to the `candidate` and `stable`
85+
# # channels. More info about channels here:
86+
# # https://snapcraft.io/docs/reference/channels
87+
# grade: stable
88+
#
89+
# # Snaps can be setup to follow three different confinement policies:
90+
# # `strict`, `devmode` and `classic`. A strict confinement where the snap
91+
# # can only read and write in its own namespace is recommended. Extra
92+
# # permissions for strict snaps can be declared as `plugs` for the app, which
93+
# # are explained later. More info about confinement here:
94+
# # https://snapcraft.io/docs/reference/confinement
95+
# confinement: strict
96+
#
97+
# # Your app's license, based on SPDX license expressions: https://spdx.org/licenses
98+
# # Default is empty.
99+
# license: Apache-2.0
100+
#
101+
# # A snap of type base to be used as the execution environment for this snap.
102+
# # Valid values are:
103+
# # * bare - Empty base snap;
104+
# # * core - Ubuntu Core 16;
105+
# # * core18 - Ubuntu Core 18.
106+
# # Default is empty.
107+
# base: core18
108+
#
109+
# # Each binary built by GoReleaser is an app inside the snap. In this section
110+
# # you can declare extra details for those binaries. It is optional.
111+
# apps:
112+
#
113+
# # The name of the app must be the same name as the binary built or the snapcraft name.
114+
# fuzzit:
115+
#
116+
# # If your app requires extra permissions to work outside of its default
117+
# # confined space, declare them here.
118+
# # You can read the documentation about the available plugs and the
119+
# # things they allow:
120+
# # https://snapcraft.io/docs/reference/interfaces.
121+
# plugs: ["network", "personal-files"]
122+
#
123+
# # Bash completion snippet. More information about completion here:
124+
# # https://docs.snapcraft.io/tab-completion-for-snaps.
125+
# # completer: drumroll-completion.bash
126+
#
127+
# # Allows plugs to be configured. Plugs like system-files and personal-files
128+
# # require this.
129+
# # Default is empty.
130+
# plugs:
131+
# personal-files:
132+
# read:
133+
# - $HOME/.fuzzit.cache
134+
# write:
135+
# - $HOME/.fuzzit.cache

client/auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"google.golang.org/api/option"
1919
)
2020

21-
func (c *fuzzitClient) refreshToken() error {
21+
func (c *FuzzitClient) refreshToken() error {
2222
if c.IdToken == "" || (time.Now().Unix()-c.LastRefresh) > 60*45 {
2323
createCustomTokenEndpoint := fmt.Sprintf("%s/createCustomToken?api_key=%s", FuzzitEndpoint, url.QueryEscape(c.ApiKey))
2424
r, err := c.httpClient.Get(createCustomTokenEndpoint)

client/client.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type job struct {
4141
Job
4242
}
4343

44-
type fuzzitClient struct {
44+
type FuzzitClient struct {
4545
Org string
4646
Namespace string
4747
ApiKey string
@@ -55,8 +55,8 @@ type fuzzitClient struct {
5555
httpClient *http.Client
5656
}
5757

58-
func NewFuzzitClient(apiKey string) (*fuzzitClient, error) {
59-
c := &fuzzitClient{}
58+
func NewFuzzitClient(apiKey string) (*FuzzitClient, error) {
59+
c := &FuzzitClient{}
6060
c.httpClient = &http.Client{Timeout: 60 * time.Second}
6161
c.ApiKey = apiKey
6262
err := c.refreshToken()
@@ -66,8 +66,8 @@ func NewFuzzitClient(apiKey string) (*fuzzitClient, error) {
6666
return c, nil
6767
}
6868

69-
func LoadFuzzitFromCache() (*fuzzitClient, error) {
70-
c := &fuzzitClient{}
69+
func LoadFuzzitFromCache() (*FuzzitClient, error) {
70+
c := &FuzzitClient{}
7171
c.httpClient = &http.Client{Timeout: 60 * time.Second}
7272

7373
usr, err := user.Current()

client/commands.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
//"github.com/docker/docker/pkg/stdcopy"
2525
)
2626

27-
func (c *fuzzitClient) archiveFiles(files []string) (string, error) {
27+
func (c *FuzzitClient) archiveFiles(files []string) (string, error) {
2828
fuzzerPath := files[0]
2929
filename := filepath.Base(fuzzerPath)
3030
if !strings.HasSuffix(filename, ".tar.gz") {
@@ -56,7 +56,7 @@ func (c *fuzzitClient) archiveFiles(files []string) (string, error) {
5656
return fuzzerPath, nil
5757
}
5858

59-
func (c *fuzzitClient) DownloadSeed(dst string, target string) error {
59+
func (c *FuzzitClient) DownloadSeed(dst string, target string) error {
6060
storagePath := fmt.Sprintf("orgs/%s/targets/%s/seed", c.Org, target)
6161
err := c.downloadFile(dst, storagePath)
6262
if err != nil {
@@ -65,7 +65,7 @@ func (c *fuzzitClient) DownloadSeed(dst string, target string) error {
6565
return nil
6666
}
6767

68-
func (c *fuzzitClient) DownloadCorpus(dst string, target string) error {
68+
func (c *FuzzitClient) DownloadCorpus(dst string, target string) error {
6969
storagePath := fmt.Sprintf("orgs/%s/targets/%s/corpus.tar.gz", c.Org, target)
7070
err := c.downloadFile(dst, storagePath)
7171
if err != nil {
@@ -74,7 +74,7 @@ func (c *fuzzitClient) DownloadCorpus(dst string, target string) error {
7474
return nil
7575
}
7676

77-
func (c *fuzzitClient) DownloadFuzzer(dst string, target string, job string) error {
77+
func (c *FuzzitClient) DownloadFuzzer(dst string, target string, job string) error {
7878
storagePath := fmt.Sprintf("orgs/%s/targets/%s/jobs/%s/fuzzer", c.Org, target, job)
7979
err := c.downloadFile(dst, storagePath)
8080
if err != nil {
@@ -83,7 +83,7 @@ func (c *fuzzitClient) DownloadFuzzer(dst string, target string, job string) err
8383
return nil
8484
}
8585

86-
func (c *fuzzitClient) GetResource(resource string) error {
86+
func (c *FuzzitClient) GetResource(resource string) error {
8787
err := c.refreshToken()
8888
if err != nil {
8989
return err
@@ -140,7 +140,7 @@ func (c *fuzzitClient) GetResource(resource string) error {
140140
}
141141
}
142142

143-
func (c *fuzzitClient) CreateTarget(targetName string, seedPath string) (*firestore.DocumentRef, error) {
143+
func (c *FuzzitClient) CreateTarget(targetName string, seedPath string) (*firestore.DocumentRef, error) {
144144
err := c.refreshToken()
145145
if err != nil {
146146
return nil, err
@@ -174,7 +174,7 @@ func (c *fuzzitClient) CreateTarget(targetName string, seedPath string) (*firest
174174
return docRef, nil
175175
}
176176

177-
func (c *fuzzitClient) getRunShTar() (*os.File, error) {
177+
func (c *FuzzitClient) getRunShTar() (*os.File, error) {
178178
tmpfile, err := ioutil.TempFile("", "run.*.tar")
179179
if err != nil {
180180
log.Fatal(err)
@@ -209,7 +209,7 @@ func (c *fuzzitClient) getRunShTar() (*os.File, error) {
209209
return runShTar, nil
210210
}
211211

212-
func (c *fuzzitClient) CreateLocalJob(jobConfig Job, files []string) error {
212+
func (c *FuzzitClient) CreateLocalJob(jobConfig Job, files []string) error {
213213
ctx := context.Background()
214214
cli, err := client.NewClientWithOpts(client.FromEnv)
215215
if err != nil {
@@ -327,7 +327,7 @@ func (c *fuzzitClient) CreateLocalJob(jobConfig Job, files []string) error {
327327
return nil
328328
}
329329

330-
func (c *fuzzitClient) CreateJob(jobConfig Job, files []string) (*firestore.DocumentRef, error) {
330+
func (c *FuzzitClient) CreateJob(jobConfig Job, files []string) (*firestore.DocumentRef, error) {
331331
err := c.refreshToken()
332332
if err != nil {
333333
return nil, err

client/storage.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type storageLinkResponse struct {
1919
StorageLink string `json:"storage_link"`
2020
}
2121

22-
func (c *fuzzitClient) getStorageLink(storagePath string, action string) (string, error) {
22+
func (c *FuzzitClient) getStorageLink(storagePath string, action string) (string, error) {
2323
uri := fmt.Sprintf("https://app.fuzzit.dev/getStorageLinkV3?path=%s&api_key=%s&action=%s",
2424
url.QueryEscape(storagePath),
2525
url.QueryEscape(c.ApiKey),
@@ -42,7 +42,7 @@ func (c *fuzzitClient) getStorageLink(storagePath string, action string) (string
4242
return res.StorageLink, nil
4343
}
4444

45-
func (c *fuzzitClient) uploadFile(filePath string, storagePath string, contentType string, filename string) error {
45+
func (c *FuzzitClient) uploadFile(filePath string, storagePath string, contentType string, filename string) error {
4646
data, err := os.Open(filePath)
4747
if err != nil {
4848
return err
@@ -74,7 +74,7 @@ func (c *fuzzitClient) uploadFile(filePath string, storagePath string, contentTy
7474
return nil
7575
}
7676

77-
func (c *fuzzitClient) downloadFile(filePath string, storagePath string) error {
77+
func (c *FuzzitClient) downloadFile(filePath string, storagePath string) error {
7878
storageLink, err := c.getStorageLink(storagePath, "read")
7979
if err != nil {
8080
return err

cmd/create.go

+18
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,31 @@ limitations under the License.
1616
package cmd
1717

1818
import (
19+
"github.com/fuzzitdev/fuzzit/client"
1920
"github.com/spf13/cobra"
21+
"github.com/spf13/viper"
22+
"log"
2023
)
2124

2225
// createCmd represents the create command
2326
var createCmd = &cobra.Command{
2427
Use: "create",
2528
Short: "Create a new Target or a Job",
29+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
30+
apiKey := viper.GetString("api-key")
31+
var err error
32+
if apiKey != "" {
33+
gFuzzitClient, err = client.NewFuzzitClient(apiKey)
34+
if err != nil {
35+
log.Fatalln(err)
36+
}
37+
} else {
38+
gFuzzitClient, err = client.LoadFuzzitFromCache()
39+
if err != nil {
40+
log.Fatalln(err)
41+
}
42+
}
43+
},
2644
}
2745

2846
func init() {

cmd/get.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cmd
1818
import (
1919
"github.com/fuzzitdev/fuzzit/client"
2020
"github.com/spf13/cobra"
21+
"github.com/spf13/viper"
2122
"log"
2223
)
2324

@@ -31,12 +32,23 @@ var getCmd = &cobra.Command{
3132
./fuzzit get targets/<target_id>/jobs # retrieve all jobs for target
3233
./fuzzit get targets/<target_id>/jobs/<job_id> # retrieve specific job`,
3334
Args: cobra.ExactArgs(1),
34-
Run: func(cmd *cobra.Command, args []string) {
35-
c, err := client.LoadFuzzitFromCache()
36-
if err != nil {
37-
log.Fatal(err)
35+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
36+
apiKey := viper.GetString("api-key")
37+
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, err = client.LoadFuzzitFromCache()
45+
if err != nil {
46+
log.Fatalln(err)
47+
}
3848
}
39-
err = c.GetResource(args[0])
49+
},
50+
Run: func(cmd *cobra.Command, args []string) {
51+
err := gFuzzitClient.GetResource(args[0])
4052
if err != nil {
4153
log.Fatal(err)
4254
}

0 commit comments

Comments
 (0)