Skip to content

Commit 42599e4

Browse files
authored
fix flag initialization and naming (#1950)
Signed-off-by: pxp928 <[email protected]>
1 parent 4204cb0 commit 42599e4

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

cmd/guaccollect/cmd/osv.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ you have access to read and write to the respective blob store.`,
8686
viper.GetString("interval"),
8787
viper.GetBool("service-poll"),
8888
viper.GetBool("publish-to-queue"),
89-
viper.GetInt("daysSinceLastScan"),
89+
viper.GetInt("last-scan"),
9090
)
9191
if err != nil {
9292
fmt.Printf("unable to validate flags: %v\n", err)
@@ -232,5 +232,16 @@ func initializeNATsandCertifier(ctx context.Context, blobAddr, pubsubAddr string
232232
}
233233

234234
func init() {
235+
set, err := cli.BuildFlags([]string{"interval",
236+
"last-scan", "header-file"})
237+
if err != nil {
238+
fmt.Fprintf(os.Stderr, "failed to setup flag: %v", err)
239+
os.Exit(1)
240+
}
241+
osvCmd.PersistentFlags().AddFlagSet(set)
242+
if err := viper.BindPFlags(osvCmd.PersistentFlags()); err != nil {
243+
fmt.Fprintf(os.Stderr, "failed to bind flags: %v", err)
244+
os.Exit(1)
245+
}
235246
rootCmd.AddCommand(osvCmd)
236247
}

cmd/guaccollect/cmd/root.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ func init() {
3737
"service-poll",
3838
"enable-prometheus",
3939
"publish-to-queue",
40-
"interval",
41-
"daysSinceLastScan",
4240
"gql-addr",
4341
})
4442
if err != nil {

cmd/guaccollect/cmd/scorecard.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/Khan/genqlient/graphql"
2626
"github.com/guacsec/guac/pkg/certifier"
2727
"github.com/guacsec/guac/pkg/certifier/certify"
28-
"github.com/guacsec/guac/pkg/certifier/components/root_package"
28+
sc "github.com/guacsec/guac/pkg/certifier/components/source"
2929
"github.com/guacsec/guac/pkg/certifier/scorecard"
3030
"github.com/guacsec/guac/pkg/cli"
3131
"github.com/guacsec/guac/pkg/logging"
@@ -46,6 +46,8 @@ type scorecardOptions struct {
4646
interval time.Duration
4747
// enable/disable message publish to queue
4848
publishToQueue bool
49+
// setting "daysSinceLastScan" to 0 does not check the timestamp on the scorecard that exist
50+
daysSinceLastScan int
4951
}
5052

5153
var scorecardCmd = &cobra.Command{
@@ -75,6 +77,7 @@ you have access to read and write to the respective blob store.`,
7577
viper.GetString("interval"),
7678
viper.GetBool("service-poll"),
7779
viper.GetBool("publish-to-queue"),
80+
viper.GetInt("last-scan"),
7881
)
7982
if err != nil {
8083
fmt.Printf("unable to validate flags: %v\n", err)
@@ -111,13 +114,13 @@ you have access to read and write to the respective blob store.`,
111114
httpClient := http.Client{Transport: transport}
112115
gqlclient := graphql.NewClient(opts.graphqlEndpoint, &httpClient)
113116

114-
sourceQueryFunc, err := getSourceQuery(gqlclient)
117+
query, err := sc.NewCertifier(gqlclient, opts.daysSinceLastScan)
115118
if err != nil {
116-
logger.Errorf("error: %v", err)
119+
logger.Errorf("unable to create source query: %v\n", err)
117120
os.Exit(1)
118121
}
119122

120-
initializeNATsandCertifier(ctx, opts.blobAddr, opts.pubsubAddr, opts.poll, opts.publishToQueue, opts.interval, sourceQueryFunc())
123+
initializeNATsandCertifier(ctx, opts.blobAddr, opts.pubsubAddr, opts.poll, opts.publishToQueue, opts.interval, query)
121124
},
122125
}
123126

@@ -128,7 +131,7 @@ func validateScorecardFlags(
128131
blobAddr,
129132
interval string,
130133
poll bool,
131-
pubToQueue bool) (scorecardOptions, error) {
134+
pubToQueue bool, daysSince int) (scorecardOptions, error) {
132135

133136
var opts scorecardOptions
134137

@@ -144,17 +147,22 @@ func validateScorecardFlags(
144147
return opts, fmt.Errorf("failed to parser duration with error: %w", err)
145148
}
146149
opts.interval = i
150+
opts.daysSinceLastScan = daysSince
147151

148152
return opts, nil
149153
}
150154

151-
func getSourceQuery(client graphql.Client) (func() certifier.QueryComponents, error) {
152-
return func() certifier.QueryComponents {
153-
packageQuery := root_package.NewPackageQuery(client, 0)
154-
return packageQuery
155-
}, nil
156-
}
157-
158155
func init() {
156+
set, err := cli.BuildFlags([]string{"interval",
157+
"last-scan", "header-file"})
158+
if err != nil {
159+
fmt.Fprintf(os.Stderr, "failed to setup flag: %v", err)
160+
os.Exit(1)
161+
}
162+
scorecardCmd.PersistentFlags().AddFlagSet(set)
163+
if err := viper.BindPFlags(scorecardCmd.PersistentFlags()); err != nil {
164+
fmt.Fprintf(os.Stderr, "failed to bind flags: %v", err)
165+
os.Exit(1)
166+
}
159167
rootCmd.AddCommand(scorecardCmd)
160168
}

guac.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ blob-addr: file:///tmp/blobstore?no_tmp_dir=true
2727
# certifier interval
2828
interval: 20m
2929
# days since the last vulnerability scan was run. 0 means only run once
30-
daysSinceLastScan: 0
30+
last-scan: 0
3131

3232
# CSub setup
3333
csub-addr: localhost:2782

pkg/cli/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func init() {
100100

101101
set.StringP("interval", "i", "5m", "if polling set interval, m, h, s, etc.")
102102

103-
set.IntP("daysSinceLastScan", "l", 0, "days since the last vulnerability scan was run. 0 means only run once")
103+
set.IntP("last-scan", "l", 0, "days since the last vulnerability scan was run. Default 0 means only run once")
104104

105105
set.BoolP("cert-good", "g", false, "enable to certifyGood, otherwise defaults to certifyBad")
106106
set.BoolP("package-name", "n", false, "if type is package, enable if attestation is at package-name level (for all versions), defaults to specific version")

0 commit comments

Comments
 (0)