A python REPL for accessing the ICS via REST API

What it is

This is a small set of python, wrapped into a REPL for easy interaction with ICS in bulk. It has the ability to be fed simple scripts that can perform various tasks, as well as interactive capability.

It is the culmination of much playing around with the ICS REST API over the past year or so and trying to accomplish various simple, yet challenging through the UI, tasks.

Files:

Disclaimer:

These scripts are provided “AS IS” and without any official support from Oracle. Their use needs to be performed using details from the comments section and/or readme file (if one is included). Any bugs encountered, feedback, and/or enhancement requests are welcome.
No liability for the contents of these scripts can be accepted. Use the concepts, examples, and information at your own risk. However, great care has been taken to ensure that all technical information is accurate and as useful as possible.
This is an evolving set of python scripts, it is not a good example of “pythonic” code. It is expected that anyone using this would customize and extend to their needs.

Running

To run the interactive shell, one needs to have python 3.5 (or higher) installed, as well as the requests and tabulate libraries. I recommend using pycharm (an excellent python integrated development environment) to handle this, if you’re not comfortable using pip to install them.

Readline

The command implementation uses readline, or an alternative equivalent. Install gnureadline on Mac, and pyreadline on windows for tab completion.

The server password file

Execution requires a special file – the “server password” file. This file has a specific format: semi-colon separated fields, containing four values:

<URL>;<alias>;<username>;<password>

URL is the URL of the ICS server. https://mypodname-myiddomain.integration.us2.oraclecloud.com for example. This is the “root” of your usual ICS URL: https://mypodname-myiddomain.integration.us2.oraclecloud.com/ics/faces/global (look when you are logged in to an ICS console).

Alias is a short, unique, nickname for the server, that will be used by the REPL to refer to it. See the “connect” command below.

Username and Password are valid administrative credentials for authentication to the ICS instance.

Here’s an example line that connects to a local VM:

https://10.2.0.95:7002;mine;weblogic;welcome1


There can be as many lines in this file as you wish – each should have a unique alias, otherwise there are no other constraints.

Invoking the python

python3.5 repl.py --servers <passwordfile> will start the repl in interactive mode.
Here you can interact with the commands by typing them in. help is available through the help command, and completion is available if the readline library is available. It should be very familiar to anyone who’s used the python interactive console, for example.

python3.5 repl.py --servers <passwordfile> -f <scriptfile> will start the repl in script execution mode – in this mode, it will attempt to execute the commands in the <scriptfile> one line at a time, and then exit.

There are additional optional parameters – the system captures a comprehensive log file (defaulting to output.log) and you can configure the log level as well. Run python3.5 repl.py -h for more information.

Using the REPL

The selection list

The REPL has a special concept – the “selected integration list”. Several commands interact with the selected integration list, allowing bulk interaction with integrations in ICS.

The connected server

The REPL has a concept of a “connected server” – most operations will target that server, either for query, import or activation. This can be changed by using a new connect command.

Commands

help

Shows help about the system. help <command> shows simple help for the <command>

list_available_servers

List the servers available in the supplied “server” file.

connect <alias>

Verify connectivity to the specified alias and select it as the current server for further operations. The prompt will change to indicate the server is connected, if successful. Tab completion is available for the server alias.

list_integrations [<file> [<filter>]]

List the integrations on the current connected server. Optionally, (not yet implemented) outputs to a <file> (use – for output to console). The filter is passed to the REST API as a query filter: {{name like \'{<filter>}\’}} if present. Use * (default) to not apply a name filter.

dump_integration_json <file>

Outputs the entire integration json retrieved from the REST API to <file>, with pretty printed json. Useful for inspecting which elements are available in the JSON for other activities.

list_connections [<file>]

List the connections on the current connected server. Optionally (not yet implemented) outputs to a <file>.

dump_connection_json <connectioncode> <file>

Dump the entire JSON associated with the Connection with code <connectioncode> to <file>. Useful for inspecting which elements are available for a particular connection.

export_integrations <dir>

Export all integrations from the current connected server to the directory <dir>. Dir should not exist prior to running this command, and the command will error if it does.

select_integrations <expression>

Select integrations which match <expression>. <expression> is a python expression, with the following elements in it’s namespace:

iar: the integration itself. All attributes from the JSON are accessible here. Dates will be converted (for the most part) into python datetime objects. This uses a SimpleNamespace, so fields in the JSON are fields in the object.

dt: the datetime module. This allows access to the datetime related operations so one can do relative date comparisons.

tz: the pytz module. This allows the datetime module to handle UTC and other timezone aware elements of datetime.

Example expression:

select_integrations iar.lastUpdated > dt.datetime.now(tz.utc) - dt.timedelta(days=50) and iar.status != "ACTIVATED" and iar.createdBy == "christian.weeks"


This will select integrations where lastUpdated is more recent than the last 50 days (dt.datetime.now(tz.utc) - dt.timedelta(days=50)), and the integration is not active (iar.status!="ACTIVATED") and was authored by christian.weeks (iar.createdBy=="christian.weeks")

Integrations matched by the selection filter will be placed into the active selection list.

clear_selection

This clears any active selection

list_selection

Lists the active selection.

export_selection <dir>

Export the current active selection to the directory <dir>. Dir should not exist prior to running this command, and the command will error if it does.

import_directory <dir>

Import the IARs from the directory <dir> into the current server, and set the active selection to the set of imported integrations.

activate_selection

Attempts to activate the currently selected list of integrations.

update_connection <connectioncode> <propertypairs>

Updates the connection <connectioncode> with the list of key=value property pairs. This creates blocks of “propertyName”:<key>, “propertyValue”:<value> objects in the connectionproperties section of the connection.

Example:

update_connection CW_EP2 targetWSDLURL=http://my.dummy.url/is/a.wsdl


This will update the connection CW_EP2 with a new targetWSDLURL property of value http://my.dummy.url/is/a.wsdl.

update_connection_security <connectioncode> <securitytype> <propertypairs>

Updates the security associated with <connectioncode> with the new <securitytype> policy, and optionally, additional property pairs for the securityproperties section of the connection. If the securitytype is NONE, no propertypairs are expected, otherwise they are.

Example script

connect ateam
list_integrations
select_integrations iar.lastUpdated > dt.datetime.now(tz.utc) - dt.timedelta(days=50) and iar.status != "ACTIVATED" and iar.createdBy == "christian.weeks"
list_selection
export_selection letsmove
connect mine
import_directory letsmove
update_connection CW_EP2 targetWSDLURL=http://my.dummy.url/is/a.wsdl
update_connection_security CW_EP2 USERNAME_PASSWORD_TOKEN username=cw password=gofish
activate_selection


This will perform a “migration” of any integration last updated within the last 50 days, that’s not active, but was authored by christian.weeks from the “ateam” alias to the “mine” alias. The directory “letsmove” will contain any IARs that were exported and subsequently imported.

As part of the move, the connection CW_EP2 will have it’s targetWSDLURL updated and USERNAME_PASSWORD_TOKEN security of the specified type applied. At the end, all imported integrations will be activated.

Disclaimer:

Add Your Comment