DataPower Commander v0.3 - more useful than ever
Tags: dpcmder, datapower, croz, go
Published: 2020-01-10 09:12:14

DataPower Commander (<strong>dpcmder</strong>) is a command line tool I created for easier maintenance of files on <strong>DataPower</strong> appliances and easier development of DataPower appliance solutions. <span style="background-color: #ddf">You can use dpcmder too – it is an open source project available on <a href="https://github.com/croz-ltd/dpcmder" target="_blank" rel="noopener">GitHub (croz-ltd/dpcmder)</a>.</span>

It is developed using go (golang) which makes cross-platform releases much easier and cross-compilation is built in as a go tool feature :)

Since last time I wrote about <a href="https://croz.net/news/datapower-commander/" target="_blank" rel="noopener">dpcmder</a> so many new features were added that I felt compelled to write a new blog and describe how can dpcmder make your day nicer and your work with DataPower easier. Let's be honest, it will make your whole life easier :)

Most interesting new features are:
<ul>
 	<li>DataPower appliance configuration list</li>
 	<li>domain export</li>
 	<li>object maintenance mode
<ul>
 	 	<li>view object configuration</li>
 	 	<li>edit object configuration</li>
 	 	<li>delete object configuration</li>
 	 	<li>view non-saved changes in object configuration</li>
	 	<li>save current domain changes</li>
</ul>
</li>
 	<li>nicer input/progress dialogs</li>
 	<li>status messages history</li>
</ul>

A bit more comprehensive list of new features will be given below but let's help you to start using dpcmder before we come to that.

## Getting started with dpcmder

DataPower Commander works under Linux, macOS and Windows (normal Windows cmd prompt) but since there are no default file viewer/editor/diff externals command-line programs available under Windows it is a bit "harder" to do the initial setup for Windows environment. I would suggest you to use WSL or cmder environment to make all features of dpcmder easier to use.

The Best way to start using dpcmder is to run it with "-h" flag and see all flags available and then just call with appropriate flags to connect to your DataPower appliance, for example:
<code>dpcmder -s https://127.0.0.1:5550 -u admin -p admin -c LocalDp</code>

This command will connect to your local DataPower instance which exposes its SOMA interface at port 5550 using the default username and password combination and will save this configuration under given configuration name "LocalDp". Don't worry if you forgot to add "-c" flag - DataPower configuration just opened is saved as "_PreviousAppliance_" in the DataPower appliance list where you can easily clone it to whatever configuration name you need using F9/9 key.

You can even start without using any command line parameters when starting dpcmder for the first time and create a new DataPower configuration using the F8/8 key (when the [empty] list of appliances is shown). However, this option is not recommended if you plan to save your password to dpcmder configuration file (<em>~/.dpcmder/config.json</em>) - passwords are saved in the configuration file as base32 encoded text so you would have to properly encode password value before saving it.

If you need more information you can pass flag "-help" to dpcmder and it will write full dpcmder help to console so you can get more information about its features and their use.

<strong>Note on appliances configuration password safety</strong>

If passwords are saved in a dpcmder configuration file (if they are passed to dpcmder using "-p" flag) they will be base32 encoded so anyone with access to your dpcmder configuration file would be able to decode it easily. If you cannot guarantee the safety of this file, please avoid using "-p" flag and enter a password when you connect to each appliance - this password will not be saved into the dpcmder configuration file.

## DataPower appliance list

When you open DataPower commander without any parameters a list of saved DataPower appliance configuration is shown (which can be empty if no appliances were added through command-line flags or by using F8/8 key).

You can connect to DataPower using a given configuration (Enter key), view current configuration (F3/3 key), edit the current configuration (F4/4 key), clone current configuration (F9/9), create a new empty configuration (F8/8 key) or delete current configuration (Del/x key).

If the configuration for DataPower appliance you want to access doesn't contain password information, the first time you want to connect to that appliance (in running dpcmder program) a dialog for password input will be shown.

If you run dpcmder using proper SOMA or REST connection parameters on command line DataPower appliance list will not be shown - list of domains on DataPower you wanted to connect to (using command line parameters) will be shown instead. You can easily go back to the DataPower appliance list by going to the parent view (selecting ".." item).

![List of DataPower appliances](https://thepracticaldev.s3.amazonaws.com/i/1b1iwcd72ojhuuw9n2hh.png)

## DataPower domain export

One of the new features for which I felt to fit most naturally into dpcmder is exporting of the DataPower domains. Just as it is possible to copy files and/or directories from DataPower to the local filesystem it feels natural to copy the whole domain to a local filesystem. Actually, the same key is used for that purpose (F5/5 key) and the result of that operation is the DataPower export zip archive created on a local filesystem.

The exported archive contains all objects and files from the selected DataPower domain.

I am considering to add function to import domain (and even delete domain) but since these operations are quite powerful there is a bigger chance to make some "damage" to your appliance using those. However, these options are something that would nicely round out features of working with DataPower domains so these will probably be added in some future version of the dpcmder.

![Exporting DataPower domain](https://thepracticaldev.s3.amazonaws.com/i/pp65ly1kgnm8vrymbm97.gif)

## DataPower object maintenance mode

Object maintenance mode is very useful for making small changes to existing DataPower object configuration or viewing configuration changes (SOMA only). For example, changing the port number used for XML Firewall Service. Or maybe you don't want to change anything but just want to quickly check the current value of some configuration option.

In the new release of the dpcmder, 0 key is used to switch between (default) "file" mode and "object" mode. To use object mode we have to connect to the DataPower appliance and select one of the domains available.

When we switch to object mode a list of all "class" of objects for which at least one object in the selected DataPower domain exists is shown. Instead of file size count of available objects is shown. In case we used the SOMA management interface to access DataPower classes we mark all modified classes with "*" (if at least one object is new, modified or deleted for that class).

The same key (Enter key) used for the operation of "entering" domain/filestore/directory is used to show all available objects of the selected object class. In case we used the SOMA management interface we show if an object is new, deleted or modified (and can even view changes for a modified object using "d" key). That operation shows us names of all objects of the selected class and enables us to do more advanced operations on each of those objects:
<ul>
  	<li>view object (JSON/XML)</li>
	<li>edit object (JSON/XML)</li>
	<li>delete object</li>
	<li>view unsaved object changes (XML)</li>
</ul>

<!--more-->

In case we used the REST management interface to connect to the DataPower appliance object will be accessible using JSON, in case we used SOMA management interface XML will be used. The best feature we get "for free" is that if our editor (or viewer) supports syntax highlighting for JSON/XML we will have nicely highlighted code making our viewing and/or editing of DataPower configuration easier.

![DataPower list of object classes used](https://thepracticaldev.s3.amazonaws.com/i/0sm3oev8z25u8ry721ec.png)
![DataPower list of objects of selected class](https://thepracticaldev.s3.amazonaws.com/i/pksv2x3wrs31o6vmgwi7.png)
![Edit of DataPower object (REST / JSON example) using vim editor](https://thepracticaldev.s3.amazonaws.com/i/y7iiem9mxosbw7nvda5i.png)
![View DataPower object unsaved changes (SOMA-only) using external diff command](https://thepracticaldev.s3.amazonaws.com/i/hw8re4esggvb5ugxlhjw.png)

## List of interesing changes since last blog

For a more comprehensive list of changes you can check <a href="https://github.com/croz-ltd/dpcmder/releases">releases history</a> but here is a summary of changes:
<ul>
  <li>fixes</li>
  <li>DataPower appliance configuration saving and loading</li>
  <li>diff command (comparing files / directories)</li>
  <li>better error handling in calls to external programs (+ hints how to fix those)</li>
  <li>better in program help</li>
  <li>shows program help in console ("-help" flag)</li>
  <li>creation of new (empty) file</li>
  <li>view status history ("m" key)</li>
  <li>replaced library for terminal interaction (termbox-go -&gt; tcell) for better cross platform support</li>
  <li>added nicer terminal dialog and error messages</li>
  <li>blinking status when sync mode is on</li>
  <li>added object mode (edit and delete operations available)</li>
  <li>editing DataPower files can use syntax highlighting available in external editor</li>
  <li>workaround enabling to use diff command (normal, non-blocking) - custom blocking command is still recommended</li>
</ul>

## Features of dpcmder

<ul>
  <li>appliance configurations
  <ul>
    <li>saves and loads DataPower appliance configuration to enable fast connections to appliances</li>
    <li>edit/clone/create/delete DataPower appliance configuration</li>
  </ul></li>
  <li>file maintenance
  <ul>
    <li>view, edit, copy and delete file hierarchies (DataPower and local file system)</li>
    <li>filter and search files in current directory</li>
    <li>comparing files / directories (DataPower vs. local file system)</li>
  </ul></li>
  <li>objects maintenance
  <ul>
    <li>switching between filestore mode and object mode (0 key)</li>
    <li>existing objects can be quickly edited (as JSON (REST mgmt) or XML (SOMA mgmt) using current editor)</li>
    <li>existing objects can be quickly deleted</li>
  </ul></li>
  <li>domain export
  <ul>
    <li>when applying copy operation to DataPower domain it is automatically exported as zip files (exporting all local files)</li>
  </ul></li>
  <li>sync mode
  <ul>
    <li>turn on to automatically upload new and changed files from local filesystem to DataPower</li>
    <li>useful for development to automatically propagate your changes from any IDE/editor you are using to DataPower</li>
  </ul></li>
</ul>

## REST management vs. SOMA management

Some of the later features added were available only if we use the SOMA management interface to connect to the DataPower appliance. While the <strong>REST management interface</strong> seems a bit nicer some features are not available and/or documented. For example, Diff operation seems to be available through REST but I wasn't able to find any documentation about that action or find a way to use it. From <strong>154 actions available</strong> through /mgmt/actionqueue/{domain} (IDG.2018.4.1.3) only 3 are documented in IBM's Knowledge Center:
<ul>
 	<li>LoadConfiguration</li>
 	<li>Export</li>
 	<li>Import</li>
</ul>

Some functions of DataPower object mode work a bit differently in REST vs. SOMA mode - for example in the latest version available on the Git master branch, if the object's admin state is down we can't make changes to it using a REST management interface (REST call returns the HTTP error 409 Conflict).

Issues mentioned above are reasons why I would suggest you to use the SOMA management interface for your DataPower management - REST is nice but it still doesn't offer everything SOMA does.

## So Long, and Thanks for All the Fish

There are still many <strong>new features we consider adding</strong> to dpcmder so its development will continue further. For example - currently, dpcmder has a feature to edit or delete DataPower objects but doesn't have a feature to create a new object (it would be a bit hard to use). The next version (already on Git master) will be able to clone the existing one or even copy the object configuration to a local file or create/update the DataPower object from the local configuration file. Currently, dpcmder can create a new domain but can't delete the existing one, it can export the DataPower domain but can't import it - these are some of the areas we consider for dpcmder further development.

The last version seems to be much nicer and contains a lot more functions compared to the first release but this doesn't mean DataPower Commander is complete so stay tuned, there will be new features for dpcmder in 2020. :-)