Skip to content

Commit ecb23d3

Browse files
authored
version: Add OPA version to version output (#1798)
Fixes #1785 Signed-off-by: Charlie Egan <charlie_egan@apple.com>
1 parent 36401a2 commit ecb23d3

1 file changed

Lines changed: 23 additions & 18 deletions

File tree

pkg/version/version.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"cmp"
55
"runtime"
66
"strings"
7+
8+
opaversion "github.com/open-policy-agent/opa/v1/version"
79
)
810

911
const platform = runtime.GOOS + "/" + runtime.GOARCH
@@ -21,35 +23,38 @@ var (
2123

2224
// Info wraps the various version metadata values and provides a means of marshalling as JSON or pretty string.
2325
type Info struct {
24-
Version string `json:"version"`
25-
GoVersion string `json:"go_version"`
26-
Platform string `json:"platform"`
27-
Commit string `json:"commit"`
28-
Timestamp string `json:"timestamp"`
29-
Hostname string `json:"hostname"`
26+
Version string `json:"version"`
27+
GoVersion string `json:"go_version"`
28+
OPAVersion string `json:"opa_version"`
29+
Platform string `json:"platform"`
30+
Commit string `json:"commit"`
31+
Timestamp string `json:"timestamp"`
32+
Hostname string `json:"hostname"`
3033
}
3134

3235
func (vi Info) String() string {
3336
return strings.Join(
3437
[]string{
35-
"Version: " + vi.Version,
36-
"Go Version: " + vi.GoVersion,
37-
"Platform: " + vi.Platform,
38-
"Commit: " + vi.Commit,
39-
"Timestamp: " + vi.Timestamp,
40-
"Hostname: " + vi.Hostname,
38+
"Version: " + vi.Version,
39+
"Go Version: " + vi.GoVersion,
40+
"OPA Version: " + vi.OPAVersion,
41+
"Platform: " + vi.Platform,
42+
"Commit: " + vi.Commit,
43+
"Timestamp: " + vi.Timestamp,
44+
"Installed via: " + vi.Hostname,
4145
},
4246
"\n",
4347
) + "\n"
4448
}
4549

4650
func New() Info {
4751
return Info{
48-
Version: cmp.Or(Version, "unknown"),
49-
GoVersion: goVersion,
50-
Platform: platform,
51-
Commit: cmp.Or(Commit, "unknown"),
52-
Timestamp: cmp.Or(Timestamp, "unknown"),
53-
Hostname: cmp.Or(Hostname, "unknown"),
52+
Version: cmp.Or(Version, "unknown"),
53+
GoVersion: goVersion,
54+
OPAVersion: opaversion.Version,
55+
Platform: platform,
56+
Commit: cmp.Or(Commit, "unknown"),
57+
Timestamp: cmp.Or(Timestamp, "unknown"),
58+
Hostname: cmp.Or(Hostname, "unknown"),
5459
}
5560
}

0 commit comments

Comments
 (0)