Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commands and tokens

rjrudin edited this page Dec 23, 2015 · 4 revisions

One of the primary jobs of a Command implementation is to read JSON/XML files from a project directory and then pass this data off to an appropriate Manager class, which then handles making an HTTP call to the appropriate Management REST API endpoint.

Many of these JSON/XML files can contain data that is based off properties in a build tool, such as the name of an application or user passwords - in effect, the configuration is externalized. For example, if the name of an application is "my-app", it's typical for the app servers and databases associated with this application to start with "my-app" - e.g. "my-app-content", "my-app-modules", "my-app-triggers". If the name were to change, it's of course preferable to be able to change one property and have all of the configuration files be updated based on the new name vs having to change each configuration file manually.

Replacing tokens

To support this, the AbstractCommand base implementation of the Command interface depends on an instance of TokenReplacer. A TokenReplacer is used to replace tokens - which can be any string - in the JSON/XML that's read from a project file. This provides a mechanism for injecting external configuration - such as a set of Gradle properties - into each of the configuration files.

The DefaultTokenReplacer class provides a basic set of replacements for common things such as the application's database names and port numbers.

Custom tokens

You can also provide custom tokens to DefaultTokenReplacer via the "customTokens" map in AppConfig. DefaultTokenReplacer will look for any map key within a JSON/XML file and replace it with the value of the key.

Clone this wiki locally