From ccf263c3bec0b962b3876de830b88e67a10be469 Mon Sep 17 00:00:00 2001 From: Torin Sandall Date: Mon, 9 Sep 2019 21:17:10 -0400 Subject: [PATCH] runtime: Add build commit to runtime info With #1715 we updated opa.runtime() to include the OPA semantic version in the output. This change extends that to include the build commit which is useful for development purposes. Signed-off-by: Torin Sandall --- docs/content/policy-reference.md | 2 +- internal/runtime/runtime.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/policy-reference.md b/docs/content/policy-reference.md index cb93e6bed6..de08fdb8bb 100644 --- a/docs/content/policy-reference.md +++ b/docs/content/policy-reference.md @@ -391,7 +391,7 @@ In order to trigger the use of HTTPs the user must provide one of the following ### OPA | Built-in | Description | | ------- |-------------| -| ``output := opa.runtime()`` | ``opa.runtime`` returns a JSON object ``output`` that describes the runtime environment where OPA is deployed. **Caution**: Policies that depend on the output of ``opa.runtime`` may return different answers depending on how OPA was started. If possible, prefer using an explicit `input` or `data` value instead of `opa.runtime`. The ``output`` of ``opa.runtime`` will include a ``"config"`` key if OPA was started with a configuration file. The ``output`` of ``opa.runtime`` will include a ``"env"`` key containing the environment variables that the OPA process was started with. The ``output`` of ``opa.runtime`` will include a ``"version"`` key containing the version of OPA. | +| ``output := opa.runtime()`` | ``opa.runtime`` returns a JSON object ``output`` that describes the runtime environment where OPA is deployed. **Caution**: Policies that depend on the output of ``opa.runtime`` may return different answers depending on how OPA was started. If possible, prefer using an explicit `input` or `data` value instead of `opa.runtime`. The ``output`` of ``opa.runtime`` will include a ``"config"`` key if OPA was started with a configuration file. The ``output`` of ``opa.runtime`` will include a ``"env"`` key containing the environment variables that the OPA process was started with. The ``output`` of ``opa.runtime`` will include ``"version"`` and ``"commit"`` keys containing the semantic version and build commit of OPA. | ### Debugging | Built-in | Description | diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go index b750da4586..39507c8150 100644 --- a/internal/runtime/runtime.go +++ b/internal/runtime/runtime.go @@ -51,8 +51,8 @@ func Term(params Params) (*ast.Term, error) { } obj.Insert(ast.StringTerm("env"), ast.NewTerm(env)) - obj.Insert(ast.StringTerm("version"), ast.StringTerm(version.Version)) + obj.Insert(ast.StringTerm("commit"), ast.StringTerm(version.Vcs)) return ast.NewTerm(obj), nil }