Setting Up the Extension

Prerequisites

The following products should be installed:

  • VSCode Plugin 2.0.0
  • uip-cli 2.0.0
  • Universal Controller 7.4.0.0
  • Universal Agent 7.4.0.0

All work will be done in a Python 3.7.16 virtual environment. Make sure the uip-cli is installed in the virtual environment.

Introduction

We will create an Extension that uses the requests module (pure Python) and psutil module (not pure Python as it requires C runtime).

Step 1 - Initializing the Extension

Open VSCode to an empty folder (e.g. /tmp/tutorial) and activate the virtual environment you wish to use.

Initialize the ue-task extension by clicking:

For this tutorial, all parameters are suitable so, just pressing 'Enter' to select the default for each parameter is sufficient. 

Once initialized, you should now have a file called requirements.txt in your working folder:

Open the file and add requests==2.28.2 (version is optional) as follows:

requirements.txt
#
# Specify any third-party Python modules that should be bundled with the
# extension. uip-cli will automatically download and bundle the modules
# upon running `uip build` or `uip push`. 
#
# Refer to https://pip.pypa.io/en/stable/reference/requirements-file-format/
# for the expected format.
#

requests==2.28.2

Step 2 - Using requests module

Open extension.py and modify it as follows:

extension.py
from __future__ import (print_function)
from universal_extension import UniversalExtension
from universal_extension import ExtensionResult
from universal_extension import logger
import requests


class Extension(UniversalExtension):
    """Required class that serves as the entry point for the extension
    """

    def __init__(self):
        """Initializes an instance of the 'Extension' class
        """
        # Call the base class initializer
        super(Extension, self).__init__()

    def extension_start(self, fields):
        """Required method that serves as the starting point for work performed
        for a task instance.

        Parameters
        ----------
        fields : dict
            populated with field values from the associated task instance
            launched in the Controller

        Returns
        -------
        ExtensionResult
            once the work is done, an instance of ExtensionResult must be
            returned. See the documentation for a full list of parameters that
            can be passed to the ExtensionResult class constructor
        """

        resp = requests.get(
            'https://httpbin.org/basic-auth/user/pass',
            auth=('user', 'pass')
        )
        print(resp.status_code)

        # Return the result with a payload containing a Hello message...
        return ExtensionResult(
            unv_output='Hello Extension!'
        )

On line 5, we import the requests module

On lines 36-40, we call requests.get on a sample url and print the status code

Step 3 - Pushing out Extension

We are ready to test out our extension!

Assuming this Extension has not been pushed out to the Controller, go ahead and run

You may need to configure the username, password, and url first.

Running the Push All command internally runs the Build All command followed by the Upload All command. The Build All command will download all dependencies specified in requirements.txt to a folder called 3pp and package the folder in the final package archive.

Next >