Connections

Overview

In Flex.io, any input or output that requires stored authentication credentials is considered a “Connection”, including cloud storage accounts, databases, SaaS apps and API calls. Authentication methods include OAuth, bearer tokens and and database authentication.

In the Flex.io Web App, the Connections tab is used to securely manage connections that can be used in your pipe definitions:

Connections List

You may create new connections at any time by adding them via the Connections area or by using connection-related Tasks within a Pipe itself. Once you have a connection set up, you can then reference its path in an execute task with its eid or alias.

Using Aliases

To reference the Connection you may use its eid or and alias. By default, every connection you create has its own unique eid string, such as g98ffn156zsj. However, an eid isn’t necessarily memorable when referencing from a script. So, in addition, you can create a human-readable alias to use in your connection definition. For example, you might call your connection to Dropbox something like my-dropbox.

Each account has its own namespace, so all you need to remember is this alias when referencing a connection.

Understanding Connection Types

Different connections may have different properties and bindings associated with them. For example, while many APIs may only require simple requests, others may have special properties that Flex.io can utilize.

At this time, Flex.io provides additional functionality for storage-type and email-type connections. Flex.io designates these special types of connections with an icon/tag next to the connection name:

Connections Types

Storage-type Connections

A storage-type connection enables you to access its file system and list files in the directory as well as read and write to it via an Execute Task.

Once you’ve created a storage-type connection, you can also view lists of the files and directories in them. Specifically, you can view directories of these types of connections from the “Storage” tab. Click on the connection to show a drill-down list of files associated with the connection.

Connections View Directory

In addition to utilizing storage-type connections via a Python or Node.js function from an Execute Task, you may also access them using the following pre-packaged Tasks: Read Task to pass a file via std out and the Write Task to receive files via std in.

Adding Connections

There are two ways to set up a connection in Flex.io. You may add connections using the Connections page itself or you can choose to add one while building a pipe using connection-related tasks like the OAuth task. The methodology for adding a connection for either option are the same, so we’ll focus on the Connections page here.

To add a connection from the web app, sign in to Flex.io and navigate to the Connections tab. Then, click the “New Connection” button at the top right of the screen to bring up a connection chooser dialog:

Connections Chooser Dialog

This dialog will help you set up pre-built connections to cloud storage, databases and Saas apps. You may also connect to any API using the Custom API connector option.

Different services have different means of authentication, therefore each connection set up will vary slightly depending on the type of service. Below we’ll walk through the most common connection authentication methods including OAuth, Basic Authentication, Bearer Tokens, Database Authentication and Custom Authentication.

OAuth

OAuth is a browser-based authentication mechanism used by many services, such as Dropbox, GitHub and Google Sheets.

Connections: OAuth

An OAuth dialog has the following options:

When finished, select the “Create Connection” button to save your connection.

Basic Authentication

Basic Authentication is used when your service requires a login and password combination, like accessing Twilio call logs:

Connections: Basic Authentication

A Basic Authentication dialog has the following options:

When finished, select the “Create Connection” button to save your connection.

Bearer Tokens

Many services provide secure access via tokens, such as Amazon Web Services:

Connections: Bearer Tokens

A Bearer Token dialog has the following options:

When finished, select the “Create Connection” button to save your connection.

Database Authentication

It’s often useful to be able to read or write to a cloud-based database, like Postgres or MySQL. To do so, you’ll need to give Flex.io access to your database through your firewall as well as provide authentication information via the database dialog:

Connections: Database Authentication

A Database Authentiation dialog has the following options:

When finished, select the “Create Connection” button to save your connection.

Custom API Authentication

For any API connection for which Flex.io does not provide a specific connector, you can create a custom connection using the services raw API calls. To do this, select “Custom API” from the Connector Chooser dialog:

Connections: Custom API Authentication

A Custom API dialog has the following options:

When finished, select the “Create Connection” button to save your connection.

Using Connections

After adding a connection, you’ll use it to pass or receive data to your function. For instance, to get access to your Oauth token, you can use the OAuth Task or OAuth execute code or to get your connection keyring, you can use the stored token code.

For storage-type Connections, you can list data using the List Task or list execute code. You can read data using the Read Task or the read execute code. You can write data using the Write Task or write execute code.

Belows are the primary Connection bindings you can use within an Execute Task to reference your Connections in your code.

Access Stored Token via Keyring

All connections, regardless of type, can be stored in the Flex.io Connections area, which enables you to utilize the connection without exposing paths or credentials in your Execute Task scripts.

Access OAuth Refresh Token

For OAuth connection types, Flex.io automatically provides access to the OAuth refresh token for you. After setting up your OAuth-type Connection, you can add an Execute task with the following code to get access to the token:

def flex_handler(flex):

connection_alias = 'YOUR_OAUTH_CONNECTION_ALIAS_HERE'
auth_token = flex.connections[connection_alias].get_access_token()

flex.res.end(auth_token)

List Files in a Directory

For storage-type connections, Flex.io provides you access to file system controls, including listing files in the directory of the Connection. After setting up your Connection, you can add an Execute task with the following code to list out the contents in its directory:

# list out contents of the contents of the base directory, where
# 'my-connection-alias' is the alias of the connection
def flex_handler(flex):
items = flex.fs.list('my-connection-alias:/')
flex.output.write(items)

Read from a File

For storage-type connections, Flex.io allows you to perform common file operations, including listing files in the directory of the Connection. After setting up your Connection, you can add an Execute task with the following code to read files from its directory.

# read a file into a variable, where 'my-connection-alias' is the
# alias of the connection and 'my-file.txt' is the path of the
# file in the connection to read from
def flex_handler(flex):
file = flex.fs.open('my-connection-alias:/my-file.txt')
buf = file.read()
flex.output.write(buf)

Write to a File

For storage-type connections, Flex.io provides you access to file system controls, including listing files in the directory of the Connection. After setting up your Connection, you can add an Execute task with the following code to write files to its directory.

To open a file and overwrite its contents:

# opening a file and overwriting the contents
def flex_handler(flex):
f = flex.fs.open('my-connection-alias:/my-file.txt', 'w+')
f.write('Hello')
f.close()

To open a file and append to its contents:

# opening a file and appending to the contents
def flex_handler(flex):
f = flex.fs.open('my-connection-alias:/my-file.txt', 'a+')
f.write('Add this line...')
f.close()

Managing Connections

Once a Connection has been added, you can update or delete it from the Flex.io Web App or via the API.

In the web app, click on the Connections tab to see the list of connections:

Connections List

The connection list shows each connection added to your Flex.io account. In the left-navigation, each connection summary shows the connection name, the alias or EID and the path, if relevant.

If a connection has been authenticated and valid, the connection summary shows a green checkmark icon. If the connection has been added, but has either not been authenticated or is no longer functional, the commection summary shows a red ‘x’ icon.

You can also get the list of all your connections via the API along with a status as follows:

See the API reference for details on connection properties such as status codes

Editing or Updating a Connection

Editing or updating a connection is similar to adding a connection.

Simply navigate to the connection you wish to edit, click on the connection summary and the connection detail will appear. Edit your connection information and, if appropriate, test or reauthenticate the connection and then click “Save Changes” to update.

Deleting a Connection

If you’d like to remove a connection from your Connections, select the connection summary you’d like to delete. Then, at the right of the connection summary, click on the down arrow to open up a dropdown menu. Select the “Delete” button. A dialog will pop up asking you to confirm your deletion. Click “Delete Connection” to remove the connection from your list or “Cancel” to return to the connection list.