Configuration Injection module
Edition |
Incubator (services) |
||
Issues |
Coming soon! |
||
Git |
|||
Latest |
1.2
|
The Configuration Injection module lets you create and modify Magnolia configuration through a Magnolia property when Magnolia starts up. This can come in handy when running Magnolia in a container or when you want to modify the configuration of a Magnolia instance on starting up.
You can:
-
Set your Magnolia license key
-
Enable or disable publication receivers
-
Add nodes in the config workspace
-
Set or modify properties of nodes in the config workspace
-
Bootstrap content from a file into any workspace
-
Change the ordering of nodes
This module is at the INCUBATOR level. |
Installing with Maven
Maven is the easiest way to install the module. Add the following to your bundle:
<dependency>
<groupId>info.magnolia.services</groupId>
<artifactId>config-injection</artifactId>
<version>1.2</version>
</dependency>
Usage
The configuration to changed or added is specified in the Magnolia property magnolia.config.inject. The value of the property is read and one or more startup tasks are created and executed when the Configuration Injection module is started.
The format of the magnolia.config.inject value is:
magnolia.config.inject = <config change>;<config change>;...;<config change> (1)
1 | The configuration changes are executed in the order they are defined in magnolia.config.inject. Config changes are separated by ';'. |
Config changes come in two flavors: creating a node in the config workspace and setting a property value of a node in the config workspace. |
Creating a node
You can create a node in the config workspace by adding a config change like this:
createPath:<node path>(,<node type>)
where:
<node path>
is the absolute path (e.g. /foo/bar/newnode
) to the node to be created. You must specify the node path.
If the node already exists, the task will not modify the node and will execute successfully.
|
Setting a property
You can add or modify properties of a node in the config works space like this:
setProperty:<node path>,<property name>,<property value>
where:
<node path>
is the absolute path (e.g. /foo/bar/mynode
) to the node of the property to be added or modified. You must specify the node path.
If the no node exists at the specified path, an error will be thrown when the set property task is executed. |
Bootstrapping a file
You can specify a bootstrap file to be loaded into Magnolia like this:
bootstrapFile:<path to file>
where:
<path to file>
is the location of the bootstrap file. You must specify the file path.
The bootstrap file name must follow the Magnolia bootstrap file name convention:
or
You can create bootstrap files by selecting a node and selecting the "export" action in Magnolia apps. |
Move a node before a sibling
The format of a config change to move a node before a sibling is:
moveBefore:<node path>,<sibling node name>
where:
<node path>
is the absolute path (e.g. /foo/bar/mynode
) to the node to be moved. You must specify the node path.
If no sibling node does not exist, node will not be moved. |
Move a node after a sibling
The format of a config change to move a node after a sibling is:
moveAfter:<node path>,<sibling node name>
where:
<node path>
is the absolute path (e.g. /foo/bar/mynode
) to the node to be moved. You must specify the node path.
If no sibling node does not exist, node will not be moved. |
Example
Here’s an example configuration injection that will set the Magnolia license details on startup when included in the JVM invocation:
-Dmagnolia.inject.config="createPath:/modules/enterprise/license\;setProperty:/modules/enterprise/license,owner,andrew.warinner@magnolia-cms.com\;setProperty:/modules/enterprise/license,key,NotARealMagnoliaLicenseKey“
This will:
.
- Create the node /modules/enterprise/license
if it does not already exist
- Set the owner property of /modules/enterprise/license
to andrew.warinner@magnolia-cms.com
.
- Set the key property of /modules/enterprise/license
to "NotARealMagnoliaLicenseKey"
.
There are a couple of things to note about this example:
-
The semicolons in the system property value must be escaped (preceded by a backslash) for the Java property to be correctly interpreted by the JVM by the shell.
-
The system property value is enclosed in double quotes to ensure is is correctly interpreted by the shell.