Overview
The very first thing to consider when integrating with a 3rd party tool is credentials; how to properly store and access them. It is never recommended to store credentials in plain text. CloudBolt (CB) has a solution for this that pairs perfectly with CB Plugins and CB UI Extensions (XUI). Connection Info objects can be created to store credentials and host details, all encrypted in the database. Each object can be referenced in code, never exposing the sensitive data.
This article will cover both the manual and automated procedures for creating and setting values for the Connection Info Object.
Considerations
Service Account:
It is recommend to create the equivalent of a service account for remote access to the 3rd party tool. Do NOT use an employee account, this will render the integration useless if/when the password changes or the employee leaves the company. It is also recommended not to use a frequently rotated password for this account, the currently process for updating the password is manual.
Token Auth:
Token auth is supported, simply store it in the “password” field of the Connection Info object.
Manual Create Procedure
Goto Admin > Connection Info
Click the “Add Connection Info” button
Fill in all of the required fields
The value of each field can be looked up and used programmatically
The “name” field is typically used to look up the connection info object. It is case sensitive.
Example of how to lookup and use a Connection Info.
from utilities.models import ConnectionInfo conn = ConnectionInfo.objects.get(name="Example Integration") # base url base_url = f'{conn.protocol}://{conn.ip}:{conn.port}/api/v1' # username conn.username #password conn.password
Automated Create/Lookup Procedure
Within your CB Plugin or XUI, you can programmatically look up the Connection Info object, we typically do this by its name attribute. Django queries have multiple methods for lookups, the simple one being a “get” method (shown above). Alternatively, you can use a “get_or_create” method, which is almost self explanatory. This method is more advanced where the object is created using supplied defaults if it was not found and returns the found or created object. This is a great option for seeding requirements/dependencies like Connection Info objects that are related to the integration being developed.
from utilities.models import ConnectionInfo conn, created = ConnectionInfo.objects.get_or_create( name='Example Integration', defaults={ "ip": "192.168.2.100", "protocol": "https", "port": 443, "username": "example_svc_acct", "password": "" } ) # base url base_url = f'{conn.protocol}://{conn.ip}:{conn.port}/api/v1' # username conn.username #password conn.password
Additional information
Include links to outside source articles or reference material if applicable
0 Comments