Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error and exit when initialization fails #1674

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/guaccollect/cmd/deps_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ you have access to read and write to the respective blob store.`,
// Register collector
depsDevCollector, err := deps_dev.NewDepsCollector(ctx, opts.dataSource, opts.poll, opts.retrieveDependencies, 30*time.Second)
if err != nil {
logger.Errorf("unable to register oci collector: %v", err)
logger.Fatalf("unable to register oci collector: %v", err)
}
err = collector.RegisterDocumentCollector(depsDevCollector, deps_dev.DepsCollector)
if err != nil {
logger.Errorf("unable to register oci collector: %v", err)
logger.Fatalf("unable to register oci collector: %v", err)
}
if opts.enablePrometheus {
go func() {
Expand Down
7 changes: 3 additions & 4 deletions cmd/guaccollect/cmd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ you have access to read and write to the respective blob store.`,
fileCollector := file.NewFileCollector(ctx, opts.path, opts.poll, 30*time.Second)
err = collector.RegisterDocumentCollector(fileCollector, file.FileCollector)
if err != nil {
logger.Errorf("unable to register file collector: %v", err)
logger.Fatalf("unable to register file collector: %v", err)
}

initializeNATsandCollector(ctx, opts.pubsubAddr, opts.blobAddr)
Expand Down Expand Up @@ -121,16 +121,15 @@ func initializeNATsandCollector(ctx context.Context, pubsubAddr string, blobAddr
// TODO: pass in credentials file for NATS secure login
jetStream := emitter.NewJetStream(pubsubAddr, "", "")
if err := jetStream.JetStreamInit(ctx); err != nil {
logger.Errorf("jetStream initialization failed with error: %v", err)
os.Exit(1)
logger.Fatalf("jetStream initialization failed with error: %v", err)
}
defer jetStream.Close()
}

// initialize blob store
blobStore, err := blob.NewBlobStore(ctx, blobAddr)
if err != nil {
logger.Errorf("unable to connect to blog store: %v", err)
logger.Fatalf("unable to connect to blog store: %v", err)
}

// initialize pubsub
Expand Down
10 changes: 5 additions & 5 deletions cmd/guaccollect/cmd/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ you have access to read and write to the respective blob store.`,
// GITHUB_TOKEN is the default token name
ghc, err := githubclient.NewGithubClient(ctx, os.Getenv("GITHUB_TOKEN"))
if err != nil {
logger.Errorf("unable to create github client: %v", err)
logger.Fatalf("unable to create github client: %v", err)
}

// Register collector
Expand All @@ -129,11 +129,11 @@ you have access to read and write to the respective blob store.`,

if opts.ownerRepoName != "" {
if !strings.Contains(opts.ownerRepoName, "/") {
logger.Errorf("owner-repo flag must be in the format <owner>/<repo>")
logger.Fatalf("owner-repo flag must be in the format <owner>/<repo>")
} else {
ownerRepoName := strings.Split(opts.ownerRepoName, "/")
if len(ownerRepoName) != 2 {
logger.Errorf("owner-repo flag must be in the format <owner>/<repo>")
logger.Fatalf("owner-repo flag must be in the format <owner>/<repo>")
}
collectorOpts = append(collectorOpts, github.WithOwner(ownerRepoName[0]))
collectorOpts = append(collectorOpts, github.WithRepo(ownerRepoName[1]))
Expand All @@ -142,11 +142,11 @@ you have access to read and write to the respective blob store.`,

githubCollector, err := github.NewGithubCollector(collectorOpts...)
if err != nil {
logger.Errorf("unable to create Github collector: %v", err)
logger.Fatalf("unable to create Github collector: %v", err)
}
err = collector.RegisterDocumentCollector(githubCollector, github.GithubCollector)
if err != nil {
logger.Errorf("unable to register Github collector: %v", err)
logger.Fatalf("unable to register Github collector: %v", err)
}

initializeNATsandCollector(ctx, opts.pubsubAddr, opts.blobAddr)
Expand Down
2 changes: 1 addition & 1 deletion cmd/guaccollect/cmd/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ you have access to read and write to the respective blob store.`,
ociCollector := oci.NewOCICollector(ctx, opts.dataSource, opts.poll, 30*time.Second)
err = collector.RegisterDocumentCollector(ociCollector, oci.OCICollector)
if err != nil {
logger.Errorf("unable to register oci collector: %v", err)
logger.Fatalf("unable to register oci collector: %v", err)
}

initializeNATsandCollector(ctx, opts.pubsubAddr, opts.blobAddr)
Expand Down
4 changes: 2 additions & 2 deletions cmd/guacingest/cmd/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func ingest(cmd *cobra.Command, args []string) {
// TODO: pass in credentials file for NATS secure login
jetStream := emitter.NewJetStream(opts.pubsubAddr, "", "")
if err := jetStream.JetStreamInit(ctx); err != nil {
logger.Errorf("jetStream initialization failed with error: %v", err)
logger.Fatalf("jetStream initialization failed with error: %v", err)
os.Exit(1)
}
defer jetStream.Close()
Expand All @@ -76,7 +76,7 @@ func ingest(cmd *cobra.Command, args []string) {
// initialize blob store
blobStore, err := blob.NewBlobStore(ctx, opts.blobAddr)
if err != nil {
logger.Errorf("unable to connect to blog store: %v", err)
logger.Fatalf("unable to connect to blog store: %v", err)
}

// initialize pubsub
Expand Down
4 changes: 2 additions & 2 deletions cmd/guacone/cmd/deps_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ var depsDevCmd = &cobra.Command{
// Register collector
depsDevCollector, err := deps_dev.NewDepsCollector(ctx, opts.dataSource, opts.poll, opts.retrieveDependencies, 30*time.Second)
if err != nil {
logger.Errorf("unable to register depsdev collector: %v", err)
logger.Fatalf("unable to register depsdev collector: %v", err)
}
if err := collector.RegisterDocumentCollector(depsDevCollector, deps_dev.DepsCollector); err != nil {
logger.Errorf("unable to register depsdev collector: %v", err)
logger.Fatalf("unable to register depsdev collector: %v", err)
}

totalNum := 0
Expand Down
6 changes: 3 additions & 3 deletions cmd/guacone/cmd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var filesCmd = &cobra.Command{
inmemory := inmemory.NewInmemoryProvider()
err = key.RegisterKeyProvider(inmemory, inmemory.Type())
if err != nil {
logger.Errorf("unable to register key provider: %v", err)
logger.Fatalf("unable to register key provider: %v", err)
}

if opts.keyPath != "" && opts.keyID != "" {
Expand All @@ -101,14 +101,14 @@ var filesCmd = &cobra.Command{
sigstoreAndKeyVerifier := sigstore_verifier.NewSigstoreAndKeyVerifier()
err = verifier.RegisterVerifier(sigstoreAndKeyVerifier, sigstoreAndKeyVerifier.Type())
if err != nil {
logger.Errorf("unable to register key provider: %v", err)
logger.Fatalf("unable to register key provider: %v", err)
}

// Register collector
fileCollector := file.NewFileCollector(ctx, opts.path, false, time.Second)
err = collector.RegisterDocumentCollector(fileCollector, file.FileCollector)
if err != nil {
logger.Errorf("unable to register file collector: %v", err)
logger.Fatalf("unable to register file collector: %v", err)
}

// initialize collectsub client
Expand Down
2 changes: 1 addition & 1 deletion cmd/guacone/cmd/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var ociCmd = &cobra.Command{
ociCollector := oci.NewOCICollector(ctx, opts.dataSource, false, 10*time.Minute)
err = collector.RegisterDocumentCollector(ociCollector, oci.OCICollector)
if err != nil {
logger.Errorf("unable to register oci collector: %v", err)
logger.Fatalf("unable to register oci collector: %v", err)
}

// initialize collectsub client
Expand Down
Loading