iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >嵌入 Go 应用程序时无法多次调用 Anchore syft 库命令
  • 647
分享到

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

2024-02-08 20:02:39 647人浏览 薄情痞子
摘要

问题内容 我正在尝试将 Anchore syft 库嵌入到我的 Go 应用程序中,以便为多个容器生成 CycloneDX SBOM。下面的函数在第一次调用时执行良好,但当在 cobra

问题内容

我正在尝试将 Anchore syft 库嵌入到我的 Go 应用程序中,以便为多个容器生成 CycloneDX SBOM。下面的函数在第一次调用时执行良好,但当在 cobra 命令上调用 Execute 时,后续调用会失败并出现错误。

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)
    }
}

错误是

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

我找不到重置 cobra 命令的方法,以便可以多次调用它。这可能吗?


正确答案


我联系了 Anchore 社区,他们能够解决我的问题。

我需要直接使用 Syft 库,而不是通过 cobra 命令。

示例请参见https://www.PHP.cn/link/3b13b1eb44b05f57735764786fab9c2c

非常感谢克里斯托弗·菲利普斯

以上就是嵌入 Go 应用程序时无法多次调用 Anchore syft 库命令的详细内容,更多请关注编程网其它相关文章!

--结束END--

本文标题: 嵌入 Go 应用程序时无法多次调用 Anchore syft 库命令

本文链接: https://www.lsjlt.com/news/562007.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作