-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add ability to return application version from new admin endpoint and wiremock standalone cli #2453
Conversation
…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
…e and returns the version as a String
… 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'
There was a problem hiding this 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() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 👍
…rn-application-version
… 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
There was a problem hiding this 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
…rn-application-version
…load the properties in a thread safe way.
… 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.
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 samefilesWithVersion
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 anAccept
header withtext/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
#help-contributing
or a project-specific channel like#wiremock-java