Beim Einbetten einer Go-Anwendung kann der Befehl der Anchore-Syft-Bibliothek nicht mehrmals aufgerufen werden

PHPz
Freigeben: 2024-02-08 20:42:04
nach vorne
1120 Leute haben es durchsucht

嵌入 Go 应用程序时无法多次调用 Anchore syft 库命令

Frageninhalt

Ich versuche, die Anchore-Syft-Bibliothek in meine Go-Anwendung einzubetten, um CycloneDX-SBOMs für mehrere Container zu generieren. Die folgende Funktion wird beim ersten Aufruf einwandfrei ausgeführt, aber wenn Execute im Cobra-Befehl aufgerufen wird, schlagen nachfolgende Aufrufe mit einem Fehler fehl.

func generateCycloneDX(ociArchiveName string, jsonOutputName string) {
    syftId := clio.Identification{Name: "syft"}
    syftCommand := cli.Command(syftId)
    syftCommand.SetArgs([]string{ociArchiveName, "-o", jsonOutputName})
    err := syftCommand.Execute()
    if err != nil {
        panic(err)
    }
}
Nach dem Login kopieren

Der Fehler ist

panic: replace existing redaction store (probably unintentional)

goroutine 1 [running]:
github.com/anchore/syft/internal/redact.Set(...)
        go/pkg/mod/github.com/anchore/[email protected]/internal/redact/redact.go:11
github.com/anchore/syft/cmd/syft/cli.create.func2(0xc000490a90?)
        go/pkg/mod/github.com/anchore/[email protected]/cmd/syft/cli/cli.go:64 +0x1a5
github.com/anchore/clio.(*application).runInitializers(0xc0013bc1a0)
        go/pkg/mod/github.com/anchore/[email protected]/application.go:110 +0x66
github.com/anchore/clio.(*application).PostLoad(0xc0013bc1a0)
        go/pkg/mod/github.com/anchore/[email protected]/application.go:105 +0xbb
github.com/anchore/fangs.postLoad({0x1f81f40?, 0xc0013bc1a0?, 0xc0013bc1a0?})
        go/pkg/mod/github.com/anchore/[email protected]/load.go:201 +0x1e5
github.com/anchore/fangs.loadConfig({{0x26109f8, 0x349e4e0}, {0x1ff3df6, 0x4}, {0x2004cda, 0xc}, {0x0, 0x0}, {0xc002b25e30, 0x5, ...}}, ...)
        go/pkg/mod/github.com/anchore/[email protected]/load.go:80 +0x7d1
github.com/anchore/fangs.Load({{0x26109f8, 0x349e4e0}, {0x1ff3df6, 0x4}, {0x2004cda, 0xc}, {0x0, 0x0}, {0xc002b25e30, 0x5, ...}}, ...)
        go/pkg/mod/github.com/anchore/[email protected]/load.go:16 +0x74
github.com/anchore/clio.(*application).loadConfigs(0xc0013bc1a0, 0xc000033870?, {0xc0004909f0, 0x1, 0xc0013b2700?})
        go/pkg/mod/github.com/anchore/[email protected]/application.go:95 +0x1a5
github.com/anchore/clio.(*application).setupCommand.func1.(*application).Setup.func1(0x4?, {0xd631f2?, 0xc0013b2700?, 0xc000033af0?})
        go/pkg/mod/github.com/anchore/[email protected]/application.go:74 +0x45
github.com/anchore/clio.(*application).setupCommand.func1(0xc0013b2700?, {0xc002e20870, 0x1, 0x3})
        go/pkg/mod/github.com/anchore/[email protected]/application.go:316 +0x82
github.com/spf13/cobra.(*Command).execute(0xc000845200, {0xc002e20660, 0x3, 0x3})
        go/pkg/mod/github.com/spf13/[email protected]/command.go:925 +0x7f6
github.com/spf13/cobra.(*Command).ExecuteC(0xc000845200)
        go/pkg/mod/github.com/spf13/[email protected]/command.go:1068 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
        go/pkg/mod/github.com/spf13/[email protected]/command.go:992
Nach dem Login kopieren

Ich finde keine Möglichkeit, den Cobra-Befehl zurückzusetzen, sodass er mehrmals aufgerufen werden kann. Ist es möglich?


Richtige Antwort


Ich habe die Anchore-Community kontaktiert und sie konnten mein Problem lösen.

Ich muss die Syft-Bibliothek direkt verwenden, nicht über den Cobra-Befehl.

Beispiele finden Sie unter https://www.php.cn/link/3b13b1eb44b05f57735764786fab9c2c

Vielen Dank, Christopher Phillips

Das obige ist der detaillierte Inhalt vonBeim Einbetten einer Go-Anwendung kann der Befehl der Anchore-Syft-Bibliothek nicht mehrmals aufgerufen werden. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Quelle:stackoverflow.com
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!