Can we have dynamic parameters in the edge.json file Maven config plugin

Hi,

I was wondering if there is a way to parameterize the configuration defined in the edge.json file. For example take the api product configuration.

Can we parameterize the "environments" attribute value for apiProducts in edge.json and get the env from the profile we select for deployment/config?

The use case is where we promote the build from one env to another with the same edge.config file, currently it fails because we have to define the array of env in edge.config and it throws error for the missing env and we do not want to create seperate edge.json for each env.

1 1 347
1 REPLY 1

Hey Rahul,

You should be able to accomplish this using the Maven resources plugin. The general idea is that you could copy the source contents into a temporary location, and while doing so apply Maven's filtering. If you are using a multi-file configuration, then you'd copy the entire directory, or if you are using a single file config you'd just copy edge.json by itself.

In the example below, I have my multi-file config under a directory called "config" (sitting next to the "apiproxy" directory). Using the maven resources plugin, I am able to copy the contents of both

<PROJECT_DIR>/apiproxy/*
<PROJECT_DIR>/config/*

into

<PROJECT_DIR>/target/apiproxy/*
<PROJECT_DIR>/target/config/*


When the files are copied, maven scans inside each file and replaces every string delimited by the '@' with the proper value. (this is because I specified that @ is the delimiter character). For example, if I have a file with the following text:

{      
  "envConfig": {        
    "@apigee.env@": {
      ...    
  }
}

Assuming that, the system property "apigee.env" is defined and has value of "test", the new file will look like this:
{    
  "envConfig": {        
    "test": {
      ...
    }
}

Note that for this to work properly, you have to tell the Apigee config plugin which directory contains the configuration files. This is done using the "apigee.config.dir" property.

e.g.

<apigee.config.dir>${basedir}/target/config/edge</apigee.config.dir>

Here is the actual XML config for the maven resources plugin. Once again, in this example I am copying both the contents of the "apiproxy" directory, and the "config" directory.

It's likely that in your setup you are already calling the same plugin to copy the contents of the "apiproxy" directory. You can remove that and use just this plugin config ... or combine this example with your existing plugin config.

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <overwrite>true</overwrite>
                <encoding>utf8</encoding>
                <outputDirectory>${basedir}/target</outputDirectory>
                <useDefaultDelimiters>false</useDefaultDelimiters>
                <delimiters>
                    <delimiter>@</delimiter>
                </delimiters>
                <resources>
                    <resource>
                        <directory>${project.basedir}</directory>
                        <includes>
                            <include>apiproxy/**</include>
                            <include>config/**</include>
                        </includes>
                        <filtering>true</filtering>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>


I hope this helps!