Host provisioning API

I’ve been working on exposing the new host provisioning functions through a JSON api.  There are a number of endpoints defined.  They all work with GET requests, but if you want to specify a domain configuration when registering a domain you have to post a JSON object.  In order to use this API you need to enable the api in your ejabberd_http listener by adding the ‘ejabberd_api’ config atom.

It should look like this:

{5280, ejabberd_http, [              ejabberd_api,
             captcha,
             http_bind,
             http_poll,
             %%register,
             web_admin
            ]}

After the listener is configured you also need to define acls and access rules.  To allow access to admin@localhost I added the following rules:

{acl, api_admin_acl, {user, "admin", "localhost"}}.
{access, api_admin, [{allow, api_admin_acl}]}.

Endpoints:

/api/domain/register/<domain>
/api/domain/unregister/<domain>
/api/domain/start/<domain>
/api/domain/stop/<domain>
/api/domain/status/<domain>
/api/domain/list

Most of these can be best understood after spending a few minutes experimenting with hitting each URL path in a browser.  The key things to note are that you must register a domain then start it.  When you want to remove a domain you have to stop it before unregistering.  Each step must be done in the correct state or a descriptive error is returned.

To specify special domain configurations POST a JSON object to the domain register function.  Anything that can be put into a {host_config, Host, ConfigList} section of the config can be passed in through the JSON object with the exception of {add, modules} directives.

Here is an example JSON object post:

{"domain_config": "[{modules,[{mod_offline,[]},{mod_version,[]}]}]."}

Authentication, modules, and other details can be configured using this method.  Take note that the configuration is passed as an array instead of individual erlang terms as seen in the config file.

About Shaun Kruger

I am one of the co-founders of Chatmongers.com cloud XMPP service. Hacking on ejabberd provides interesting and fun challenges. When I'm not working on chat related projects I work as a systems engineer.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>