Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): add version endpoint #4869

Merged
merged 10 commits into from
Aug 20, 2023

Conversation

nikpivkin
Copy link
Contributor

@nikpivkin nikpivkin commented Jul 25, 2023

Description

Added an endpoint to get the trivy and db versions.

Example output:

curl -s 0.0.0.0:8080/version | jq
{
  "Version": "dev",
  "VulnerabilityDB": {
    "Version": 2,
    "NextUpdate": "2023-07-25T14:15:29.876639806Z",
    "UpdatedAt": "2023-07-25T08:15:29.876640206Z",
    "DownloadedAt": "2023-07-25T09:36:25.599004Z"
  },
  "JavaDB": {
    "Version": 1,
    "NextUpdate": "2023-07-28T01:03:52.169192565Z",
    "UpdatedAt": "2023-07-25T01:03:52.169192765Z",
    "DownloadedAt": "2023-07-25T09:37:48.906152Z"
  },
  "PolicyBundle": {
    "Digest": "sha256:829832357626da2677955e3b427191212978ba20012b6eaa03229ca28569ae43",
    "DownloadedAt": "2023-07-23T11:40:33.122462Z"
  }
}

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@nikpivkin
Copy link
Contributor Author

nikpivkin commented Jul 25, 2023

@knqyf263 Have an idea where we can place the version.go file? I have temporarily added this to the utils package.

Is this a suitable place in the documentation where we can add information about endpoints?

@knqyf263
Copy link
Collaborator

knqyf263 commented Jul 25, 2023

@knqyf263 Have an idea where we can place the version.go file? I have temporarily added this to the utils package.

We may want to add a new package version. Then, can we move this variable to the package?

version = "dev"

We also need to update the version embedding.

- -X main.version={{.Version}}

Is this a suitable place in the documentation where we can add information about endpoints?

Yes.

@nikpivkin nikpivkin marked this pull request as ready for review July 26, 2023 07:44
)

var (
Version = "dev"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to make it read-only.

Suggested change
Version = "dev"
version = "dev"

Then, can we add Version() string or AppVersion() string?

PolicyBundle *policy.Metadata `json:",omitempty"`
}

func formatDbMetadata(title string, meta metadata.Metadata) string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: https://github.com/golang/go/wiki/CodeReviewComments#initialisms

Suggested change
func formatDbMetadata(title string, meta metadata.Metadata) string {
func formatDBMetadata(title string, meta metadata.Metadata) string {

return output
}

func BuildVersionInfo(appVersion string, cacheDir string) VersionInfo {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
func BuildVersionInfo(appVersion string, cacheDir string) VersionInfo {
func NewVersionInfo(appVersion string, cacheDir string) VersionInfo {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we need to pass appVersion here? There is a version info in this package?

Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to update magefile

return fmt.Sprintf("-s -w -X=main.version=%s", ver), nil

@nikpivkin nikpivkin requested a review from knqyf263 August 4, 2023 14:37
@knqyf263 knqyf263 added this pull request to the merge queue Aug 20, 2023
Merged via the queue into aquasecurity:main with commit d442176 Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add version endpoint to trivy server
3 participants