OpenIG’s improved configuration files

openig-logoIn the last couple of weeks, Guillaume and Violette have introduced more slick configuration improvements into the latest nightly builds of OpenIG. To me these are the coolest features since Guillaume added routing with support for runtime configuration changes in OpenIG 3.0.0. The changes are backwards compatible, too, so you don’t have to move right away if you just want to upgrade for other reasons.

In OpenIG 3.0.0 you have to declare all your objects in the heap, and then use the “name” wherever you reference the object. Also, you have to declare the “config” on an object, even if it is empty. (You leave “config” empty when all the fields are optional, and you want default settings for everything).

{
  "heap": {
    "objects": [
      {
        "name": "Chain",
        "type": "Chain",
        "config": {
          "filters": [
            "CaptureFilter"
          ],
          "handler": "Router"
        }
      },
      {
        "name": "CaptureFilter",
        "type": "CaptureFilter",
        "config": {
          "file": "/tmp/gateway.log"
        }
      },
      {
        "name": "Router",
        "type": "Router",
        "config": {}
      },
      {
        "name": "ClientHandler",
        "type": "ClientHandler",
        "comment": "HTTP client for routes",
        "config": {}
      }
    ]
  },
  "handler": "Chain"
}

That example is small, so it is still pretty easy to see what you are doing.

If the configuration file gets any longer, it can be tough to see the relationships.

What Guillaume did is allow you to add the configuration objects inline. (In the case where the object is only used in one place in the configuration, why not just declare it right there?) Violette then made empty “config” fields optional.

Now you can write it like this:

{
  "heap": {
    "objects": [
      {
        "name": "Chain",
        "type": "Chain",
        "config": {
          "filters": [
            {
              "type": "CaptureFilter",
              "config": {
                "file": "/tmp/gateway.log"
              }
            }
          ],
          "handler": {
            "type": "Router"
          }
        }
      },
      {
        "name": "ClientHandler",
        "type": "ClientHandler",
        "comment": "HTTP client for routes",
      }
    ]
  },
  "handler": "Chain"
}

Notice how easy it is to see what’s happening in the “Chain”.

The draft, in-progress docs and examples have all been updated to use the new, inline style. Check out what this does for some of the more complicated examples.

My favorite? If the file above is your main config.json, then your default route can be succinct indeed:

{
  "heap": {
    "objects": []
  },
  "handler": "ClientHandler"
}
Advertisements

1 Comment

Filed under Access Management, Docs

One response to “OpenIG’s improved configuration files

  1. Pingback: Simplifying OpenIG configuration… | Ludo's Sketches

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s