-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VAULT-20669: Add New Authenticated Endpoint for Version (#23740)
* add sys/internal/ui/version path * add read capability for sys/internal/ui/version in default policy * add changelog file * doc: add api-docs page for sys/internal/ui/version * add godoc for pathInternalUIVersion function * add tests for functions in version package * remove unreachable code * use closure to restore version at end of test function * use an example version in sample response * Update website/content/api-docs/system/internal-ui-version.mdx Co-authored-by: Sarah Chavis <[email protected]> * Apply suggestions from code review Co-authored-by: Sarah Chavis <[email protected]> * Update website/content/api-docs/system/internal-ui-version.mdx Co-authored-by: Sarah Chavis <[email protected]> * add copyright header to version_test.go --------- Co-authored-by: Sarah Chavis <[email protected]>
- Loading branch information
Showing
9 changed files
with
217 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:feature | ||
core: add sys/internal/ui/version endpoint | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package version | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func replaceVersion(v, vp string) func() { | ||
origV := Version | ||
origVP := VersionPrerelease | ||
|
||
Version = v | ||
VersionPrerelease = vp | ||
|
||
return func() { | ||
Version = origV | ||
VersionPrerelease = origVP | ||
} | ||
} | ||
|
||
func TestGetVersion(t *testing.T) { | ||
// This test cannot be parallelized because it messes with some global | ||
// variables that determine the version information. | ||
restoreVersionFunc := replaceVersion("1.2.3", "") | ||
defer restoreVersionFunc() | ||
|
||
// Test the general case | ||
vi := GetVersion() | ||
assert.Equal(t, "1.2.3", vi.Version) | ||
assert.Equal(t, "", vi.VersionPrerelease) | ||
assert.Equal(t, "", vi.VersionMetadata) | ||
assert.Equal(t, "", vi.Revision) | ||
assert.Equal(t, "", vi.BuildDate) | ||
|
||
// Test the git describe case | ||
origGitDescribe := GitDescribe | ||
GitDescribe = "git-describe" | ||
vi = GetVersion() | ||
assert.Equal(t, "git-describe", vi.Version) | ||
|
||
GitDescribe = origGitDescribe | ||
} | ||
|
||
func TestVersionNumber(t *testing.T) { | ||
// This test cannot be parallelized because it messes with some global | ||
// variables that determine the version information. | ||
restoreVersionFunc := replaceVersion("unknown", "unknown") | ||
defer restoreVersionFunc() | ||
|
||
// Test the unknown version case | ||
vi := GetVersion() | ||
assert.Equal(t, "(version unknown)", vi.VersionNumber()) | ||
|
||
replaceVersion("1.2.3", "") | ||
|
||
// Test the pre-release case | ||
vi = GetVersion() | ||
vi.VersionPrerelease = "rc1" | ||
assert.Equal(t, "1.2.3-rc1", vi.VersionNumber()) | ||
|
||
// Test the pre-release and metadata version case | ||
vi.VersionMetadata = "ent" | ||
assert.Equal(t, "1.2.3-rc1+ent", vi.VersionNumber()) | ||
|
||
// Test the metadata only version case | ||
vi.VersionPrerelease = "" | ||
assert.Equal(t, "1.2.3+ent", vi.VersionNumber()) | ||
} | ||
|
||
func TestFullVersionNumber(t *testing.T) { | ||
// This test cannot be parallelized because it messes with some global | ||
// variables that determine the version information. | ||
restoreVersionFunc := replaceVersion("unknown", "unknown") | ||
defer restoreVersionFunc() | ||
|
||
// Test the unknown version case | ||
vi := GetVersion() | ||
assert.Equal(t, "Vault (version unknown)", vi.FullVersionNumber(false)) | ||
|
||
// Test the no pre-release, metadata, revision, build date case | ||
replaceVersion("1.2.3", "") | ||
vi = GetVersion() | ||
assert.Equal(t, "Vault v1.2.3", vi.FullVersionNumber(false)) | ||
|
||
// Test the pre-release case | ||
vi.VersionPrerelease = "rc1" | ||
assert.Equal(t, "Vault v1.2.3-rc1", vi.FullVersionNumber(false)) | ||
|
||
// Test the metadata case | ||
vi.VersionPrerelease = "" | ||
vi.VersionMetadata = "ent" | ||
assert.Equal(t, "Vault v1.2.3+ent", vi.FullVersionNumber(false)) | ||
|
||
// Test the revision case | ||
vi.VersionMetadata = "" | ||
vi.Revision = "ab1234f" | ||
assert.Equal(t, "Vault v1.2.3 (ab1234f)", vi.FullVersionNumber(true)) | ||
|
||
// Test the build date case | ||
vi.BuildDate = "2023-10-20" | ||
assert.Equal(t, "Vault v1.2.3, built 2023-10-20", vi.FullVersionNumber(false)) | ||
|
||
// Test the case where all of the things are set | ||
vi.VersionPrerelease = "rc1" | ||
vi.VersionMetadata = "ent" | ||
assert.Equal(t, "Vault v1.2.3-rc1+ent (ab1234f), built 2023-10-20", vi.FullVersionNumber(true)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
layout: api | ||
page_title: /sys/internal/ui/version - HTTP API | ||
description: >- | ||
The `/sys/internal/ui/version` endpoint exposes the software version of Vault. | ||
--- | ||
|
||
# `/sys/internal/ui/version` | ||
|
||
The `/sys/internal/ui/version` endpoint exposes the Vault software version | ||
so the Vault UI can display the information to logged in users. | ||
|
||
Vault uses internal endpoints to provide information to the Vault UI | ||
and/or Vault CLI. Internal endpoints are explicitly intended to support | ||
Vault functionality, so we do not recommend them for general use | ||
and do not guarantee backwards compatibility across versions. | ||
|
||
## Get version | ||
|
||
Return the current software version of Vault. | ||
|
||
| Method | Path | | ||
| :----- | :------------------------- | | ||
| `GET` | `/sys/internal/ui/version` | | ||
|
||
### Sample request | ||
|
||
```shell-session | ||
$ curl \ | ||
--header "X-Vault-Token: ..." \ | ||
--request GET \ | ||
http://127.0.0.1:8200/v1/sys/internal/ui/version | ||
``` | ||
|
||
### Sample response | ||
|
||
```json | ||
{ | ||
"request_id": "d585b9be-9c6f-a05f-939b-490cf062ebbe", | ||
"lease_id": "", | ||
"renewable": false, | ||
"lease_duration": 0, | ||
"data": { | ||
"version": "1.16.0" | ||
}, | ||
"wrap_info": null, | ||
"warnings": null, | ||
"auth": null, | ||
"mount_type": "system" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters