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

Add ability to return application version from new admin endpoint and wiremock standalone cli #2453

Merged

Conversation

leeturner
Copy link
Contributor

This PR provides the ability for the application to read the current version and return this version from a new admin endpoint and the cli for wiremock standalone.

The current version is copied to a file in the resources folder using the same filesWithVersion mechanism as other files referenced in the build script. The version is also added to the jar manifest files via the build script.

The PR adds a new GET admin endpoint at the following url - __admin/version. By default this returns a simple json payload with the version information. If the caller sends an Accept header with text/plain the version information is returned as a text response.

If used on the cli via java -jar wiremock-standalone-3.2.0.jar --version the version information will be output and the application will then exit.

One area that I am not sure about is how the open api files are updated so at the moment the new version admin endpoint is not referenced in there.

Submitter checklist

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • Recommended: If you participate in Hacktoberfest 2023, make sure you're signed up there and in the WireMock form
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • [] For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org

…dd a new version properties file to the resources so we can use this in the app to return the version.
…ion numbers via the build tasks. Test version stays the same so we can continue to validate the version number in our tests
… to be made to return the version. The response defaults to json but a simple text/plain response can be sent if the client adds the Accept header of 'text/plain'
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

LGTM, just one minor suggestion

import java.util.Properties;

public class Version {
public static String getCurrentVersion() {
Copy link
Member

Choose a reason for hiding this comment

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

How about caching it in a static variable? Java resource loading is heavy, and such unprotected endpoint may be exploited for various kinds of DDoS attempts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds great. Thank you for the suggestion. I have added simple caching of the version as suggested. If we add any other version information to the Version class we can add more sophisticated caching but for now this should do

Copy link
Member

Choose a reason for hiding this comment

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

I've just merged a change with a Lazy utility class. This might be a nice way to do this (and is thread safe FWIW).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, I'll take a look at that and update the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated to the Lazy class. Nice little utility class 👍

… from the classpath. If we add any other version information to the Version class we can add more sophisticated caching but for now this should do
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

Needs Tom, fine with me

@oleg-nenashev oleg-nenashev added the needs-tom Tom's Train Project :) label Oct 31, 2023
@tomakehurst tomakehurst merged commit e8c5d7c into wiremock:master Nov 10, 2023
7 checks passed
Marvin9 pushed a commit to Marvin9/wiremock that referenced this pull request Nov 20, 2023
… wiremock standalone cli (wiremock#2453)

* Add the Implementation name and version to the manifest files.  Also add a new version properties file to the resources so we can use this in the app to return the version.

* New version properties files that are updated with all the other version numbers via the build tasks.  Test version stays the same so we can continue to validate the version number in our tests

* Version class that reads in the value from the version.properties file and returns the version as a String

* Add a new version route to the admin interface to allow a GET request to be made to return the version.  The response defaults to json but a simple text/plain response can be sent if the client adds the Accept header of 'text/plain'

* Formatting fix

* Adds the version cli option to the standalone version of wiremock

* If the version cli option is set, output the current wiremock version and then exit.

* Use constants and enums instead of strings for content type and mime type

* Add the Accept header to the static types for future use

* Run spotless apply

* Add simple caching of the version so we don't have to keep pulling it from the classpath. If we add any other version information to the Version class we can add more sophisticated caching but for now this should do

* Update the version number so it matches the latest releases

* Update the Version class to use the new Lazy utility class to lazily load the properties in a thread safe way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants