Projects STRLCPY syft Commits 26c201f7
🤬
  • ■ ■ ■ ■ ■ ■
    syft/pkg/cataloger/binary/cataloger_test.go
    skipped 239 lines
    240 240   },
    241 241   },
    242 242   {
    243  - name: "positive-argocd-2.5.11",
    244  - fixtureDir: "test-fixtures/classifiers/dynamic/argocd-2.5.11",
    245  - expected: pkg.Package{
    246  - Name: "argocd",
    247  - Version: "2.5.11",
    248  - Type: "binary",
    249  - PURL: "pkg:golang/github.com/argoproj/[email protected]",
    250  - Locations: locations("argocd"),
    251  - Metadata: metadata("argocd"),
    252  - },
    253  - },
    254  - {
    255  - name: "positive-argocd-2.6.4",
    256  - fixtureDir: "test-fixtures/classifiers/dynamic/argocd-2.6.4",
    257  - expected: pkg.Package{
    258  - Name: "argocd",
    259  - Version: "2.6.4",
    260  - Type: "binary",
    261  - PURL: "pkg:golang/github.com/argoproj/[email protected]",
    262  - Locations: locations("argocd"),
    263  - Metadata: metadata("argocd"),
    264  - },
    265  - },
    266  - {
    267 243   name: "positive-helm-3.11.1",
    268 244   fixtureDir: "test-fixtures/classifiers/dynamic/helm-3.11.1",
    269 245   expected: pkg.Package{
    skipped 15 lines
    285 261   PURL: "pkg:golang/helm.sh/[email protected]",
    286 262   Locations: locations("helm"),
    287 263   Metadata: metadata("helm"),
    288  - },
    289  - },
    290  - {
    291  - name: "positive-kubectl-1.24.11",
    292  - fixtureDir: "test-fixtures/classifiers/dynamic/kubectl-1.24.11",
    293  - expected: pkg.Package{
    294  - Name: "kubectl",
    295  - Version: "1.24.11",
    296  - Type: "binary",
    297  - PURL: "pkg:golang/k8s.io/[email protected]",
    298  - Locations: locations("kubectl"),
    299  - Metadata: metadata("kubectl"),
    300  - },
    301  - },
    302  - {
    303  - name: "positive-kubectl-1.25.7",
    304  - fixtureDir: "test-fixtures/classifiers/dynamic/kubectl-1.25.7",
    305  - expected: pkg.Package{
    306  - Name: "kubectl",
    307  - Version: "1.25.7",
    308  - Type: "binary",
    309  - PURL: "pkg:golang/k8s.io/[email protected]",
    310  - Locations: locations("kubectl"),
    311  - Metadata: metadata("kubectl"),
    312  - },
    313  - },
    314  - {
    315  - name: "positive-kubectl-1.26.2",
    316  - fixtureDir: "test-fixtures/classifiers/dynamic/kubectl-1.26.2",
    317  - expected: pkg.Package{
    318  - Name: "kubectl",
    319  - Version: "1.26.2",
    320  - Type: "binary",
    321  - PURL: "pkg:golang/k8s.io/[email protected]",
    322  - Locations: locations("kubectl"),
    323  - Metadata: metadata("kubectl"),
    324  - },
    325  - },
    326  - {
    327  - name: "positive-kustomize-4.5.7",
    328  - fixtureDir: "test-fixtures/classifiers/dynamic/kustomize-4.5.7",
    329  - expected: pkg.Package{
    330  - Name: "kustomize",
    331  - Version: "4.5.7",
    332  - Type: "binary",
    333  - PURL: "pkg:golang/sigs.k8s.io/[email protected]",
    334  - Locations: locations("kustomize"),
    335  - Metadata: metadata("kustomize"),
    336  - },
    337  - },
    338  - {
    339  - name: "positive-kustomize-5.0.0",
    340  - fixtureDir: "test-fixtures/classifiers/dynamic/kustomize-5.0.0",
    341  - expected: pkg.Package{
    342  - Name: "kustomize",
    343  - Version: "5.0.0",
    344  - Type: "binary",
    345  - PURL: "pkg:golang/sigs.k8s.io/[email protected]",
    346  - Locations: locations("kustomize"),
    347  - Metadata: metadata("kustomize"),
    348 264   },
    349 265   },
    350 266   {
    skipped 628 lines
  • ■ ■ ■ ■ ■ ■
    syft/pkg/cataloger/binary/default_classifiers.go
    skipped 46 lines
    47 47   CPEs: singleCPE("cpe:2.3:a:golang:go:*:*:*:*:*:*:*:*"),
    48 48   },
    49 49   {
    50  - Class: "argocd",
    51  - FileGlob: "**/argocd",
    52  - EvidenceMatcher: fileContentsVersionMatcher(
    53  - `(?m)common\.version=(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
    54  - Package: "argocd",
    55  - PURL: mustPURL("pkg:golang/github.com/argoproj/argo-cd@version"),
    56  - CPEs: singleCPE("cpe:2.3:a:argoproj:argocd:*:*:*:*:*:*:*"),
    57  - },
    58  - {
    59 50   Class: "helm",
    60 51   FileGlob: "**/helm",
    61 52   EvidenceMatcher: fileContentsVersionMatcher(
    skipped 1 lines
    63 54   Package: "helm",
    64 55   PURL: mustPURL("pkg:golang/helm.sh/helm@version"),
    65 56   CPEs: singleCPE("cpe:2.3:a:helm:helm:*:*:*:*:*:*:*"),
    66  - },
    67  - {
    68  - Class: "kustomize",
    69  - FileGlob: "**/kustomize",
    70  - EvidenceMatcher: fileContentsVersionMatcher(
    71  - `(?m)version=kustomize/v(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
    72  - Package: "kustomize",
    73  - PURL: mustPURL("pkg:golang/sigs.k8s.io/kustomize@version"),
    74  - CPEs: singleCPE("cpe:2.3:a:kustomize:kustomize:*:*:*:*:*:*:*"),
    75  - },
    76  - {
    77  - Class: "kubectl",
    78  - FileGlob: "**/kubectl",
    79  - EvidenceMatcher: fileContentsVersionMatcher(
    80  - `(?m)\x00v(?P<version>[0-9]+\.[0-9]+\.[0-9]+)\x00`),
    81  - Package: "kubectl",
    82  - PURL: mustPURL("pkg:golang/k8s.io/kubectl@version"),
    83  - CPEs: singleCPE("cpe:2.3:a:kubectl:kubectl:*:*:*:*:*:*:*"),
    84 57   },
    85 58   {
    86 59   Class: "redis-binary",
    skipped 212 lines
  • ■ ■ ■ ■ ■ ■
    syft/pkg/cataloger/binary/test-fixtures/Makefile
    skipped 6 lines
    7 7   classifiers/dynamic/ruby-library-3.2.1 \
    8 8   classifiers/dynamic/ruby-library-2.7.7 \
    9 9   classifiers/dynamic/ruby-library-2.6.10 \
    10  - classifiers/dynamic/argocd-2.5.11 \
    11  - classifiers/dynamic/argocd-2.6.4 \
    12 10   classifiers/dynamic/helm-3.11.1 \
    13 11   classifiers/dynamic/helm-3.10.3 \
    14  - classifiers/dynamic/kubectl-1.24.11 \
    15  - classifiers/dynamic/kubectl-1.25.7 \
    16  - classifiers/dynamic/kubectl-1.26.2 \
    17  - classifiers/dynamic/kustomize-4.5.7 \
    18  - classifiers/dynamic/kustomize-5.0.0 \
    19 12   classifiers/dynamic/consul-1.15.2
    20 13   
    21 14   
    skipped 67 lines
    89 82   /usr/local/lib/libruby.so.2.6 \
    90 83   $@/libruby.so.2.6
    91 84   
    92  -classifiers/dynamic/argocd-2.5.11:
    93  - $(eval $@_image := "argoproj/argocd:v2.5.11@sha256:d1062935b3256ec69422843ebcb50debb54fd389436961586000c8ce6ee7f249")
    94  - ./get-image-file.sh $($@_image) \
    95  - /usr/local/bin/argocd \
    96  - $@/argocd
    97  - 
    98  -classifiers/dynamic/argocd-2.6.4:
    99  - $(eval $@_image := "argoproj/argocd:v2.6.4@sha256:61fcbba187ff53c00696cb580edf70cada59c45cf399d8477631acf43cf522ee")
    100  - ./get-image-file.sh $($@_image) \
    101  - /usr/local/bin/argocd \
    102  - $@/argocd
    103  - 
    104 85  classifiers/dynamic/helm-3.11.1:
    105 86   $(eval $@_image := "alpine/helm:3.11.1@sha256:8628e3695fb743a8b9de89626f1b7a221280c2152c0e288c2504e59b68233e8b")
    106 87   ./get-image-file.sh $($@_image) \
    skipped 5 lines
    112 93   ./get-image-file.sh $($@_image) \
    113 94   /usr/local/bin/helm \
    114 95   $@/helm
    115  - 
    116  -classifiers/dynamic/kubectl-1.24.11:
    117  - $(eval $@_image := "bitnami/kubectl:1.24.11@sha256:79d60c5ac8a1dc84e2c39f56d8e8cc0053159b5ed88f283bdf8fbda1ee86c8bc")
    118  - ./get-image-file.sh $($@_image) \
    119  - /opt/bitnami/kubectl/bin/kubectl \
    120  - $@/kubectl
    121  - 
    122  -classifiers/dynamic/kubectl-1.25.7:
    123  - $(eval $@_image := "bitnami/kubectl:1.25.7@sha256:d7b00dbfdc6d8890aefe40edfb6c1d4c90cbb6c978794bb51a21744edc34ba7a")
    124  - ./get-image-file.sh $($@_image) \
    125  - /opt/bitnami/kubectl/bin/kubectl \
    126  - $@/kubectl
    127  - 
    128  -classifiers/dynamic/kubectl-1.26.2:
    129  - $(eval $@_image := "line/kubectl-kustomize:1.26.2-5.0.0@sha256:9ee3b4a9a21f0777fc1d8c64208290f818a2e68c5e9e892e931621bda089bf06")
    130  - ./get-image-file.sh $($@_image) \
    131  - /usr/local/bin/kubectl \
    132  - $@/kubectl
    133  - 
    134  -classifiers/dynamic/kustomize-4.5.7:
    135  - $(eval $@_image := "argoproj/argocd:v2.6.4@sha256:61fcbba187ff53c00696cb580edf70cada59c45cf399d8477631acf43cf522ee")
    136  - ./get-image-file.sh $($@_image) \
    137  - /usr/local/bin/kustomize \
    138  - $@/kustomize
    139  - 
    140  -classifiers/dynamic/kustomize-5.0.0:
    141  - $(eval $@_image := "line/kubectl-kustomize:1.26.2-5.0.0@sha256:9ee3b4a9a21f0777fc1d8c64208290f818a2e68c5e9e892e931621bda089bf06")
    142  - ./get-image-file.sh $($@_image) \
    143  - /usr/local/bin/kustomize \
    144  - $@/kustomize
    145 96   
    146 97  classifiers/dynamic/consul-1.15.2:
    147 98   $(eval $@_image := "hashicorp/consul:1.15.2@sha256:c2169f3bb18dd947ae8eb5f6766896695c71fb439f050a3343e0007d895615b8")
    skipped 13 lines
  • ■ ■ ■ ■
    syft/pkg/cataloger/golang/package.go
    skipped 17 lines
    18 18   
    19 19   licenses, err := c.licenses.getLicenses(resolver, dep.Path, dep.Version)
    20 20   if err != nil {
    21  - log.Tracef("error getting licenses for package: %s %v", dep.Path, err)
     21 + log.Tracef("error getting licenses for golang package: %s %v", dep.Path, err)
    22 22   }
    23 23   
    24 24   p := pkg.Package{
    skipped 53 lines
  • ■ ■ ■ ■ ■
    syft/pkg/cataloger/golang/parse_go_binary.go
    skipped 7 lines
    8 8   "errors"
    9 9   "fmt"
    10 10   "io"
     11 + "regexp"
    11 12   "runtime/debug"
    12 13   "strings"
    13 14   "time"
    skipped 20 lines
    34 35   // devel is used to recognize the current default version when a golang main distribution is built
    35 36   // https://github.com/golang/go/issues/29228 this issue has more details on the progress of being able to
    36 37   // inject the correct version into the main module of the build process
     38 + 
     39 + knownBuildFlagPatterns = []*regexp.Regexp{
     40 + regexp.MustCompile(`(?m)\.([gG]it)?([bB]uild)?[vV]ersion=(\S+/)*(?P<version>v?\d+.\d+.\d+[-\w]*)`),
     41 + regexp.MustCompile(`(?m)\.([tT]ag)=(\S+/)*(?P<version>v?\d+.\d+.\d+[-\w]*)`),
     42 + }
    37 43  )
    38 44   
    39 45  const devel = "(devel)"
    skipped 31 lines
    71 77   gbs,
    72 78   location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
    73 79   )
    74  - if main.Version == devel {
    75  - if version, ok := gbs["vcs.revision"]; ok {
    76  - if timestamp, ok := gbs["vcs.time"]; ok {
    77  - //NOTE: err is ignored, because if parsing fails
    78  - // we still use the empty Time{} struct to generate an empty date, like 00010101000000
    79  - // for consistency with the pseudo-version format: https://go.dev/ref/mod#pseudo-versions
    80  - ts, _ := time.Parse(time.RFC3339, timestamp)
    81  - if len(version) >= 12 {
    82  - version = version[:12]
    83  - }
    84  - version = module.PseudoVersion("", "", ts, version)
     80 + 
     81 + if main.Version != devel {
     82 + return main
     83 + }
     84 + 
     85 + version, hasVersion := gbs["vcs.revision"]
     86 + timestamp, hasTimestamp := gbs["vcs.time"]
     87 + 
     88 + if hasVersion {
     89 + if hasTimestamp {
     90 + //NOTE: err is ignored, because if parsing fails
     91 + // we still use the empty Time{} struct to generate an empty date, like 00010101000000
     92 + // for consistency with the pseudo-version format: https://go.dev/ref/mod#pseudo-versions
     93 + ts, _ := time.Parse(time.RFC3339, timestamp)
     94 + if len(version) >= 12 {
     95 + version = version[:12]
     96 + }
     97 + 
     98 + var ldflags string
     99 + if metadata, ok := main.Metadata.(pkg.GolangBinMetadata); ok {
     100 + ldflags = metadata.BuildSettings["-ldflags"]
     101 + }
     102 + 
     103 + majorVersion, fullVersion := extractVersionFromLDFlags(ldflags)
     104 + if fullVersion != "" {
     105 + // we've found a specific version from the ldflags! use it as the version.
     106 + // why not combine that with the pseudo version (e.g. v1.2.3-0.20210101000000-abcdef123456)?
     107 + // short answer: we're assuming that if a specific semver was provided in the ldflags that
     108 + // there is a matching vcs tag to match that could be referenced. This assumption could
     109 + // be incorrect in terms of the go.mod contents, but is not incorrect in terms of the logical
     110 + // version of the package.
     111 + version = fullVersion
     112 + } else {
     113 + version = module.PseudoVersion(majorVersion, fullVersion, ts, version)
    85 114   }
    86  - main.Version = version
    87  - main.PURL = packageURL(main.Name, main.Version)
    88  - main.SetID()
    89 115   }
     116 + 
     117 + main.Version = version
     118 + main.PURL = packageURL(main.Name, main.Version)
     119 + 
     120 + main.SetID()
    90 121   }
    91 122   
    92 123   return main
     124 +}
     125 + 
     126 +func extractVersionFromLDFlags(ldflags string) (majorVersion string, fullVersion string) {
     127 + if ldflags == "" {
     128 + return "", ""
     129 + }
     130 + 
     131 + for _, pattern := range knownBuildFlagPatterns {
     132 + groups := internal.MatchNamedCaptureGroups(pattern, ldflags)
     133 + v, ok := groups["version"]
     134 + 
     135 + if !ok {
     136 + continue
     137 + }
     138 + 
     139 + fullVersion = v
     140 + if !strings.HasPrefix(v, "v") {
     141 + fullVersion = fmt.Sprintf("v%s", v)
     142 + }
     143 + components := strings.Split(v, ".")
     144 + 
     145 + if len(components) == 0 {
     146 + continue
     147 + }
     148 + 
     149 + majorVersion = strings.TrimPrefix(components[0], "v")
     150 + return majorVersion, fullVersion
     151 + }
     152 + 
     153 + return "", ""
    93 154  }
    94 155   
    95 156  // getArchs finds a binary architecture by two ways:
    skipped 143 lines
  • ■ ■ ■ ■ ■ ■
    syft/pkg/cataloger/golang/parse_go_binary_test.go
    skipped 298 lines
    299 299   expected: []pkg.Package{unmodifiedMain},
    300 300   },
    301 301   {
    302  - name: "parse main mod and replace devel version",
     302 + name: "parse main mod and replace devel pseudo version and ldflags exists (but contains no version)",
     303 + arch: archDetails,
     304 + mod: &debug.BuildInfo{
     305 + GoVersion: goCompiledVersion,
     306 + Main: debug.Module{Path: "github.com/anchore/syft", Version: "(devel)"},
     307 + Settings: []debug.BuildSetting{
     308 + {Key: "GOARCH", Value: archDetails},
     309 + {Key: "GOOS", Value: "darwin"},
     310 + {Key: "GOAMD64", Value: "v1"},
     311 + {Key: "vcs.revision", Value: "41bc6bb410352845f22766e27dd48ba93aa825a4"},
     312 + {Key: "vcs.time", Value: "2022-10-14T19:54:57Z"},
     313 + {Key: "-ldflags", Value: `build -ldflags="-w -s -extldflags '-static' -X blah=foobar`},
     314 + },
     315 + },
     316 + expected: []pkg.Package{
     317 + {
     318 + Name: "github.com/anchore/syft",
     319 + Language: pkg.Go,
     320 + Type: pkg.GoModulePkg,
     321 + Version: "v0.0.0-20221014195457-41bc6bb41035",
     322 + PURL: "pkg:golang/github.com/anchore/[email protected]",
     323 + Locations: source.NewLocationSet(
     324 + source.NewLocationFromCoordinates(
     325 + source.Coordinates{
     326 + RealPath: "/a-path",
     327 + FileSystemID: "layer-id",
     328 + },
     329 + ).WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
     330 + ),
     331 + MetadataType: pkg.GolangBinMetadataType,
     332 + Metadata: pkg.GolangBinMetadata{
     333 + GoCompiledVersion: goCompiledVersion,
     334 + Architecture: archDetails,
     335 + BuildSettings: map[string]string{
     336 + "GOARCH": archDetails,
     337 + "GOOS": "darwin",
     338 + "GOAMD64": "v1",
     339 + "vcs.revision": "41bc6bb410352845f22766e27dd48ba93aa825a4",
     340 + "vcs.time": "2022-10-14T19:54:57Z",
     341 + "-ldflags": `build -ldflags="-w -s -extldflags '-static' -X blah=foobar`,
     342 + },
     343 + MainModule: "github.com/anchore/syft",
     344 + },
     345 + },
     346 + },
     347 + },
     348 + {
     349 + name: "parse main mod and replace devel version with one from ldflags",
     350 + arch: archDetails,
     351 + mod: &debug.BuildInfo{
     352 + GoVersion: goCompiledVersion,
     353 + Main: debug.Module{Path: "github.com/anchore/syft", Version: "(devel)"},
     354 + Settings: []debug.BuildSetting{
     355 + {Key: "GOARCH", Value: archDetails},
     356 + {Key: "GOOS", Value: "darwin"},
     357 + {Key: "GOAMD64", Value: "v1"},
     358 + {Key: "vcs.revision", Value: "41bc6bb410352845f22766e27dd48ba93aa825a4"},
     359 + {Key: "vcs.time", Value: "2022-10-14T19:54:57Z"},
     360 + {Key: "-ldflags", Value: `build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0`},
     361 + },
     362 + },
     363 + expected: []pkg.Package{
     364 + {
     365 + Name: "github.com/anchore/syft",
     366 + Language: pkg.Go,
     367 + Type: pkg.GoModulePkg,
     368 + Version: "v0.79.0",
     369 + PURL: "pkg:golang/github.com/anchore/[email protected]",
     370 + Locations: source.NewLocationSet(
     371 + source.NewLocationFromCoordinates(
     372 + source.Coordinates{
     373 + RealPath: "/a-path",
     374 + FileSystemID: "layer-id",
     375 + },
     376 + ).WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
     377 + ),
     378 + MetadataType: pkg.GolangBinMetadataType,
     379 + Metadata: pkg.GolangBinMetadata{
     380 + GoCompiledVersion: goCompiledVersion,
     381 + Architecture: archDetails,
     382 + BuildSettings: map[string]string{
     383 + "GOARCH": archDetails,
     384 + "GOOS": "darwin",
     385 + "GOAMD64": "v1",
     386 + "vcs.revision": "41bc6bb410352845f22766e27dd48ba93aa825a4",
     387 + "vcs.time": "2022-10-14T19:54:57Z",
     388 + "-ldflags": `build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0`,
     389 + },
     390 + MainModule: "github.com/anchore/syft",
     391 + },
     392 + },
     393 + },
     394 + },
     395 + {
     396 + name: "parse main mod and replace devel version with a pseudo version",
    303 397   arch: archDetails,
    304 398   mod: &debug.BuildInfo{
    305 399   GoVersion: goCompiledVersion,
    skipped 207 lines
    513 607   }
    514 608  }
    515 609   
     610 +func Test_extractVersionFromLDFlags(t *testing.T) {
     611 + tests := []struct {
     612 + name string
     613 + ldflags string
     614 + wantMajorVersion string
     615 + wantFullVersion string
     616 + }{
     617 + {
     618 + name: "empty ldflags",
     619 + ldflags: "",
     620 + },
     621 + {
     622 + name: "syft ldflags",
     623 + ldflags: ` build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0 -X github.com/anchore/syft/internal/version.gitCommit=b2b332e8b2b66af0905e98b54ebd713a922be1a8 -X github.com/anchore/syft/internal/version.buildDate=2023-04-21T16:20:25Z -X github.com/anchore/syft/internal/version.gitDescription=v0.79.0 "`,
     624 + wantMajorVersion: "0",
     625 + wantFullVersion: "v0.79.0",
     626 + },
     627 + {
     628 + name: "kubectl ldflags",
     629 + ldflags: ` build -asmflags=all=-trimpath=/workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes
     630 + build -compiler=gc
     631 + build -gcflags="all=-trimpath=/workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes "
     632 + build -ldflags="all=-X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.buildDate=2023-04-12T12:16:51Z' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.buildDate=2023-04-12T12:16:51Z' -X 'k8s.io/client-go/pkg/version.buildDate=2023-04-12T12:16:51Z' -X 'k8s.io/component-base/version.buildDate=2023-04-12T12:16:51Z' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitCommit=a1a87a0a2bcd605820920c6b0e618a8ab7d117d4' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitCommit=a1a87a0a2bcd605820920c6b0e618a8ab7d117d4' -X 'k8s.io/client-go/pkg/version.gitCommit=a1a87a0a2bcd605820920c6b0e618a8ab7d117d4' -X 'k8s.io/component-base/version.gitCommit=a1a87a0a2bcd605820920c6b0e618a8ab7d117d4' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitTreeState=clean' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitTreeState=clean' -X 'k8s.io/client-go/pkg/version.gitTreeState=clean' -X 'k8s.io/component-base/version.gitTreeState=clean' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitVersion=v1.25.9' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitVersion=v1.25.9' -X 'k8s.io/client-go/pkg/version.gitVersion=v1.25.9' -X 'k8s.io/component-base/version.gitVersion=v1.25.9' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitMajor=1' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitMajor=1' -X 'k8s.io/client-go/pkg/version.gitMajor=1' -X 'k8s.io/component-base/version.gitMajor=1' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitMinor=25' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitMinor=25' -X 'k8s.io/client-go/pkg/version.gitMinor=25' -X 'k8s.io/component-base/version.gitMinor=25' -s -w"`,
     633 + wantMajorVersion: "1",
     634 + wantFullVersion: "v1.25.9",
     635 + },
     636 + {
     637 + name: "nerdctl ldflags",
     638 + ldflags: ` build -ldflags="-s -w -X github.com/containerd/nerdctl/pkg/version.Version=v1.3.1 -X github.com/containerd/nerdctl/pkg/version.Revision=b224b280ff3086516763c7335fc0e0997aca617a"`,
     639 + wantMajorVersion: "1",
     640 + wantFullVersion: "v1.3.1",
     641 + },
     642 + {
     643 + name: "limactl ldflags",
     644 + ldflags: ` build -ldflags="-s -w -X github.com/lima-vm/lima/pkg/version.Version=v0.15.1"`,
     645 + wantMajorVersion: "0",
     646 + wantFullVersion: "v0.15.1",
     647 + },
     648 + {
     649 + name: "terraform ldflags",
     650 + ldflags: ` build -ldflags="-w -s -X 'github.com/hashicorp/terraform/version.Version=1.4.6' -X 'github.com/hashicorp/terraform/version.Prerelease='"`,
     651 + wantMajorVersion: "1",
     652 + wantFullVersion: "v1.4.6",
     653 + },
     654 + {
     655 + name: "kube-apiserver ldflags",
     656 + ldflags: ` build -asmflags=all=-trimpath=/workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes
     657 + build -buildmode=exe
     658 + build -compiler=gc
     659 + build -gcflags="all=-trimpath=/workspace/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes "
     660 + build -ldflags="all=-X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.buildDate=2023-04-14T13:14:42Z' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.buildDate=2023-04-14T13:14:42Z' -X 'k8s.io/client-go/pkg/version.buildDate=2023-04-14T13:14:42Z' -X 'k8s.io/component-base/version.buildDate=2023-04-14T13:14:42Z' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitCommit=4c9411232e10168d7b050c49a1b59f6df9d7ea4b' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitCommit=4c9411232e10168d7b050c49a1b59f6df9d7ea4b' -X 'k8s.io/client-go/pkg/version.gitCommit=4c9411232e10168d7b050c49a1b59f6df9d7ea4b' -X 'k8s.io/component-base/version.gitCommit=4c9411232e10168d7b050c49a1b59f6df9d7ea4b' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitTreeState=clean' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitTreeState=clean' -X 'k8s.io/client-go/pkg/version.gitTreeState=clean' -X 'k8s.io/component-base/version.gitTreeState=clean' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitVersion=v1.27.1' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitVersion=v1.27.1' -X 'k8s.io/client-go/pkg/version.gitVersion=v1.27.1' -X 'k8s.io/component-base/version.gitVersion=v1.27.1' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitMajor=1' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitMajor=1' -X 'k8s.io/client-go/pkg/version.gitMajor=1' -X 'k8s.io/component-base/version.gitMajor=1' -X 'k8s.io/kubernetes/vendor/k8s.io/client-go/pkg/version.gitMinor=27' -X 'k8s.io/kubernetes/vendor/k8s.io/component-base/version.gitMinor=27' -X 'k8s.io/client-go/pkg/version.gitMinor=27' -X 'k8s.io/component-base/version.gitMinor=27' -s -w"`,
     661 + wantMajorVersion: "1",
     662 + wantFullVersion: "v1.27.1",
     663 + },
     664 + {
     665 + name: "prometheus ldflags",
     666 + ldflags: ` build -ldflags="-X github.com/prometheus/common/version.Version=2.44.0 -X github.com/prometheus/common/version.Revision=1ac5131f698ebc60f13fe2727f89b115a41f6558 -X github.com/prometheus/common/version.Branch=HEAD -X github.com/prometheus/common/version.BuildUser=root@739e8181c5db -X github.com/prometheus/common/version.BuildDate=20230514-06:18:11 -extldflags '-static'"
     667 + build -tags=netgo,builtinassets,stringlabels`,
     668 + wantMajorVersion: "2",
     669 + wantFullVersion: "v2.44.0",
     670 + },
     671 + {
     672 + name: "influxdb ldflags",
     673 + ldflags: ` build -ldflags="-s -w -X main.version=v2.7.1 -X main.commit=407fa622e9 -X main.date=2023-04-28T13:24:27Z -linkmode=external -extld=/musl/x86_64/bin/musl-gcc -extldflags '-fno-PIC -static-pie -Wl,-z,stack-size=8388608'"
     674 + build -tags=assets,sqlite_foreign_keys,sqlite_json,static_build,noasm`,
     675 + wantMajorVersion: "2",
     676 + wantFullVersion: "v2.7.1",
     677 + },
     678 + {
     679 + name: "gitea ldflags",
     680 + ldflags: ` build -ldflags=" -X \"main.MakeVersion=GNU Make 4.1\" -X \"main.Version=1.19.3\" -X \"main.Tags=bindata sqlite sqlite_unlock_notify\" "`,
     681 + wantMajorVersion: "1",
     682 + wantFullVersion: "v1.19.3",
     683 + },
     684 + {
     685 + name: "docker sbom cli ldflags",
     686 + ldflags: ` build -ldflags="-w -s -extldflags '-static' -X github.com/docker/sbom-cli-plugin/internal/version.version=0.6.1-SNAPSHOT-02cf1c8 -X github.com/docker/sbom-cli-plugin/internal/version.gitCommit=02cf1c888ad6662109ac6e3be618392514a56316 -X github.com/docker/sbom-cli-plugin/internal/version.gitDescription=v0.6.1-dirty "`,
     687 + wantMajorVersion: "0",
     688 + wantFullVersion: "v0.6.1-SNAPSHOT-02cf1c8",
     689 + },
     690 + {
     691 + name: "docker scout ldflags",
     692 + ldflags: ` build -ldflags="-w -s -extldflags '-static' -X github.com/docker/scout-cli-plugin/internal.version=0.10.0 "`,
     693 + wantMajorVersion: "0",
     694 + wantFullVersion: "v0.10.0",
     695 + },
     696 + {
     697 + name: "influx telegraf ldflags",
     698 + ldflags: ` build -ldflags="-w -s -X github.com/influxdata/telegraf/internal.Commit=a3a884a1 -X github.com/influxdata/telegraf/internal.Branch=HEAD -X github.com/influxdata/telegraf/internal.Version=1.26.2"`,
     699 + wantMajorVersion: "1",
     700 + wantFullVersion: "v1.26.2",
     701 + },
     702 + {
     703 + name: "argocd ldflags",
     704 + ldflags: ` build -ldflags="-X github.com/argoproj/argo-cd/v2/common.version=2.7.2 -X github.com/argoproj/argo-cd/v2/common.buildDate=2023-05-12T14:06:49Z -X github.com/argoproj/argo-cd/v2/common.gitCommit=cbee7e6011407ed2d1066c482db74e97e0cc6bdb -X github.com/argoproj/argo-cd/v2/common.gitTreeState=clean -X github.com/argoproj/argo-cd/v2/common.kubectlVersion=v0.24.2 -extldflags=\"-static\""`,
     705 + wantMajorVersion: "2",
     706 + wantFullVersion: "v2.7.2",
     707 + },
     708 + {
     709 + name: "kustomize ldflags",
     710 + ldflags: ` build -ldflags="-s -X sigs.k8s.io/kustomize/api/provenance.version=kustomize/v4.5.7 -X sigs.k8s.io/kustomize/api/provenance.gitCommit=56d82a8378dfc8dc3b3b1085e5a6e67b82966bd7 -X sigs.k8s.io/kustomize/api/provenance.buildDate=2022-08-02T16:35:54Z "`,
     711 + wantMajorVersion: "4",
     712 + wantFullVersion: "v4.5.7",
     713 + },
     714 + //////////////////////////////////////////////////////////////////
     715 + // negative cases
     716 + {
     717 + name: "hugo ldflags",
     718 + ldflags: ` build -ldflags="-s -w -X github.com/gohugoio/hugo/common/hugo.vendorInfo=gohugoio"`,
     719 + },
     720 + {
     721 + name: "ghostunnel ldflags",
     722 + ldflags: ` build -ldflags="-X main.version=77d9aaa"`,
     723 + },
     724 + {
     725 + name: "opa ldflags",
     726 + ldflags: `build -ldflags=" -X github.com/open-policy-agent/opa/version.Hostname=9549178459bc"`,
     727 + },
     728 + ///////////////////////////////////////////////////////////////////
     729 + // trickier cases
     730 + {
     731 + name: "macvlan plugin for cri-o ldflags",
     732 + ldflags: ` build -ldflags="-extldflags -static -X github.com/containernetworking/plugins/pkg/utils/buildversion.BuildVersion=v1.2.0"`,
     733 + wantMajorVersion: "1",
     734 + wantFullVersion: "v1.2.0",
     735 + },
     736 + {
     737 + name: "coder ldflags",
     738 + ldflags: ` build -ldflags="-s -w -X 'github.com/coder/coder/buildinfo.tag=0.23.4'"`,
     739 + wantMajorVersion: "0",
     740 + wantFullVersion: "v0.23.4",
     741 + },
     742 + ///////////////////////////////////////////////////////////////////
     743 + // don't know how to handle these... yet
     744 + //{
     745 + // // package name: pkgName: "github.com/krakendio/krakend-ce/v2",
     746 + // name: "krakenD ldflags",
     747 + // ldflags: ` build -ldflags="-X github.com/luraproject/lura/v2/core.KrakendVersion=2.3.2 -X github.com/luraproject/lura/v2/core.GoVersion=1.20.4 -X github.com/luraproject/lura/v2/core.GlibcVersion=GLIBC-2.31_(debian-11) "`,
     748 + // wantMajorVersion: "2.3.2",
     749 + // wantFullVersion: "v2.3.2",
     750 + //},
     751 + //{
     752 + // // package name: pkgName: "github.com/krakendio/krakend-ce/v2",
     753 + // name: "krakenD ldflags -- answer embedded in the middle",
     754 + // ldflags: ` build -ldflags=" -X github.com/luraproject/lura/v2/core.GoVersion=1.20.4 -X github.com/luraproject/lura/v2/core.KrakendVersion=2.3.2 -X github.com/luraproject/lura/v2/core.GlibcVersion=GLIBC-2.31_(debian-11) "`,
     755 + // wantMajorVersion: "2.3.2",
     756 + // wantFullVersion: "v2.3.2",
     757 + //},
     758 + }
     759 + for _, tt := range tests {
     760 + t.Run(tt.name, func(t *testing.T) {
     761 + gotMajorVersion, gotFullVersion := extractVersionFromLDFlags(tt.ldflags)
     762 + assert.Equal(t, tt.wantMajorVersion, gotMajorVersion, "unexpected major version")
     763 + assert.Equal(t, tt.wantFullVersion, gotFullVersion, "unexpected full version")
     764 + })
     765 + }
     766 +}
     767 + 
Please wait...
Page is in error, reload to recover