Working with CDA Entities as Code
As an Application Developer, you can use the existing REST API features and JSON schemas to create, update and transfer CDA entities between multiple clients. To do so, you update the serialized content of CDA in a code editor and stage and version the changes with a version control system (for example: GIT).
The Automation as Code functionality allows you to:
- Work with the following entities in JSON format:
- Applications, including all related entities (components, profiles, etc.)
- Deployment Workflows
- Query data from CDA using the integrated REST Client
- Use JSON code snippets to create applications, components, and other entities.
- Use GIT to version JSON files.
- Validate code using a JSON schema.
This page includes the following:
Video
Watch the video about how to work with CDA and CA CDD entities as code:
Working with CDA Entities as Code
Note: The Automation as Code functionality requires a code editor to modify the entities. In this section, VisualStudio Code is used to perform the necessary steps. You can work with the code editor of your preference (for example, Notepad ++, Eclipse, Postman and so on).
- Install a text editor on your computer (for example: VisualStudio Code).
- Integrate the REST client to directly export and import CDA Applications and its related entities. The REST Response can be saved within the GIT repository, where you can create new versions and manage your Applications in JSON format.
To integrate the REST client in VS Code, search for "REST" in the Extension marketplace and download the VS Code REST-Client extension. Install it to directly interact with the Automic REST API within the VS Code editor.
- Integrate GIT with your code editor to version and stage your changes.
Tip: Create a folder to store all your requests and template files. If you are using GIT, you can also add this folder to your GIT repository.
To do so, enter the following commands in VisualStudio Code:
mkdir cda_automation_as_code
cd cda_automation_as_code
git init
A new cda_automation_as_code folder is created. In this folder we will save the CDA JSON Application file we want to edit.
-
Open the folder and create a readme file (Readme.md).
- Check out an Application using the Rest Client. To do so, create a new rest file (for example: cda.rest).
- Add the following content to the file:
GET http://localhost/api/data/v1/applications
Authorization: Basic 100/AUTOMIC/AUTOMIC AUTOMIC
VS Code recognizes this as a REST API request and displays a Send Request button. You can now export and import CDA entities within the VS Code without having to switch to another tool. The REST Response can be saved within the GIT repository, where you can create new versions and manage your Applications as .json.
- To add more than one request within a file, write three hashes '###' above each command. Example:
### Retrieve all workflows
GET http://localhost/cda/api/data/v1/workflows HTTP/1.1
Authorization: Basic 100/AUTOMIC/AUTOMIC automic
Now you can export and import CDA entities within your code editor.
Important! In addition to the calls, you can also specify variables to define the credentials and frequently used parameters at the top of the project.
# Connection parameters
@endpoint = localhost:80/cda
@token = Basic 100/AUTOMIC/AUTOMIC AUTOMIC
@owner = "100/AUTOMIC/AUTOMIC"
Examples
The following examples of API calls are used to retrieve all applications from the repository, and export and import a specific Application:
# Retrieve all applications
GET http://{{endpoint}}/cda/api/data/v1/applications
Authorization: Basic 100/AUTOMIC/AUTOMIC automic
### Duplicate existing application including components
POST http://{{endpoint}}/api/data/v1/applications/573/duplicate HTTP/1.1
Content-Type: application/json
Authorization: {{token}}
{
"target_application": "DemoApp_v4",
"target_owner": {{owner}}
}
# Export Application
GET http://{{endpoint}}/cda/api/data/v1/applications/DemoApp
Authorization: Basic 100/AUTOMIC/AUTOMIC automic
# Import Application (json file below needs to be adapted)
POST http://{{endpoint}}/cda/api/data/v1/applications HTTP/1.1
Content-Type: application/json
Authorization: Basic 100/AUTOMIC/AUTOMIC automic
< jpetstore.json
The following examples of API calls are used retrieve all workflows and a single one:
### Retrieve all workflows
GET http://{{endpoint}}/cda/api/data/v1/workflows HTTP/1.1
Authorization: Basic 100/AUTOMIC/AUTOMIC automic
### Retrieve single workflow
GET http://{{endpoint}}/cda/api/data/v1/workflows/13562 HTTP/1.1
Authorization: Basic 100/AUTOMIC/AUTOMIC automic
Notes:
- Duplicating an Application does not duplicate Deployment Packages.
- CA CDD and CDA templates can be found at: https://marketplace.automic.com/details/automation-as-code-with-visual-studio-code