web_version.rego 800 B

12345678910111213141516171819202122232425
  1. package web.version
  2. import future.keywords
  3. POLICY_ID := "web_version"
  4. POLICY_VERSION := "v0.0.1"
  5. POLICY_SEVERITY := "low"
  6. latest_stable_version := "0.50.0"
  7. POLICY_TITLE := sprintf("The web version for application %s/%s should be at least v%s", [input.namespace, input.name, latest_stable_version])
  8. POLICY_SUCCESS_MESSAGE := sprintf("Success: web version for %s/%s is up-to-date", [input.namespace, input.name])
  9. trimmedVersion := trim_left(input.version, "v")
  10. # semver.compare returns -1 if latest_stable_version < trimmedVersion
  11. allow if semver.compare(latest_stable_version, trimmedVersion) == -1
  12. FAILURE_MESSAGE contains msg if {
  13. not allow
  14. msg := sprintf("Failed: latest stable version is %s, but %s/%s is on %s", [latest_stable_version, input.namespace, input.name, trimmedVersion])
  15. }