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

Fix attest with --key #2551

Merged
merged 7 commits into from
Jan 31, 2024
Merged
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
Prev Previous commit
Next Next commit
wip - sync.Once hack
Signed-off-by: Will Murphy <will.murphy@anchore.com>
  • Loading branch information
willmurphyscode committed Jan 26, 2024
commit 2c1c2b947db54f87e4e2f8e83fa56f8d846f4c9f
16 changes: 10 additions & 6 deletions cmd/syft/internal/clio_setup_config.go
Original file line number Diff line number Diff line change
@@ -10,8 +10,11 @@ import (
"github.com/anchore/syft/internal/redact"
"io"
"os"
"sync"
)

var initOnce sync.Once

func AppClioSetupConfig(id clio.Identification, out io.Writer) *clio.SetupConfig {
clioCfg := clio.NewSetupConfig(id).
WithGlobalConfigFlag(). // add persistent -c <path> for reading an application config from
@@ -37,14 +40,15 @@ func AppClioSetupConfig(id clio.Identification, out io.Writer) *clio.SetupConfig
func(state *clio.State) error {
// clio is setting up and providing the bus, redact store, and logger to the application. Once loaded,
// we can hoist them into the internal packages for global use.
stereoscope.SetBus(state.Bus)
bus.Set(state.Bus)

redact.Set(state.RedactStore)
initOnce.Do(func() {
stereoscope.SetBus(state.Bus)
bus.Set(state.Bus)

log.Set(state.Logger)
stereoscope.SetLogger(state.Logger)
redact.Set(state.RedactStore)

log.Set(state.Logger)
stereoscope.SetLogger(state.Logger)
})
return nil
},
).
4 changes: 3 additions & 1 deletion cmd/syft/internal/commands/attest_test.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
"bytes"
"context"
"fmt"
"github.com/anchore/clio/testutils"

Check failure on line 7 in cmd/syft/internal/commands/attest_test.go

GitHub Actions / Benchmark tests

no required module provides package github.com/anchore/clio/testutils; to add it:

Check failure on line 7 in cmd/syft/internal/commands/attest_test.go

GitHub Actions / Benchmark tests

no required module provides package github.com/anchore/clio/testutils; to add it:

Check failure on line 7 in cmd/syft/internal/commands/attest_test.go

GitHub Actions / Unit tests

no required module provides package github.com/anchore/clio/testutils; to add it:
"github.com/anchore/syft/cmd/syft/internal"
"github.com/google/go-cmp/cmp"
"github.com/spf13/cobra"
@@ -278,6 +278,8 @@
Name: "syft",
Version: "testing",
}
cfg := internal.AppClioSetupConfig(id, io.Discard)
a := clio.New(*cfg)
tests := []struct {
name string
assertionFunc func(*testing.T, *cobra.Command, []string, ...any)
@@ -309,7 +311,7 @@
t.Setenv(k, v)
}
}
app := testutils.NewForTesting(t, internal.AppClioSetupConfig(id, io.Discard), tt.assertionFunc)
app := testutils.WrapForTesting(t, a, tt.assertionFunc)
cmd := Attest(app)
cmd.SetArgs(tt.args)
err := cmd.Execute()
Loading