Brightspot REST CMA Command Line Interface
This tool provides a command line interface to Brightspot's REST CMA API.
This requires the optional dependency com.psddev:cms-api, which is available as of Brightspot version 4.2.20.
Installation
Download the brightspot-cma script and rest-api-cli.jar and place them together in your $PATH.
1$ cd ~/bin/ # (or somewhere on your $PATH)2$ curl -o rest-api-cli.jar https://artifactory.psdops.com/public/com/psddev/component-lib/rest-api-cli/%5BRELEASE%5D/rest-api-cli-%5BRELEASE%5D.jar3$ unzip rest-api-cli.jar brightspot-cma
Dependencies
At least Java 8 and java on your $PATH.
Command Overview
Step 1: Initialize project and environment
1$ brightspot-cma init -p <project-name> -e <environment-name> -u <endpoint-url> -c <client-id> -s <client-secret> [-n <basic-auth-username> -w <basic-auth-password>]
This command create a Local DB using the normalized <project-name>, initialized or reinitializes an environment named <environment-name> with the specified <endpoint-url>, <client-id>, and <client-secret>.
Example:
1$ brightspot-cma init -p "Example Site" -e "Production" -u https://example.com/api/rest/cma -c 00000000000000000000000000000000 -s xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -n debug -w 12345123451234512345123451234512
Tip: You can see which projects and environments have been created by using the
list-projectsandlist-environmentscommands.
Step 2: Test a Query
1$ brightspot-cma test-query -p <project-name> -e <environment-name> -t <content-type> [-w <where>] [-f <comma,separated,fields>] [-l <limit>] [-o <offset>] [-i]
This command simply executes a query and displays the results. Check the documentation for details on how to write a Brightspot query.
Example:
1$ brightspot-cma test-query -p "Example Site" -e Production -t com.psddev.cms.db.Site -f urls,simplestAuth.simplestAuthConfiguration -i
Tip: Use the commands
refresh-types,list-types, andshow-typeto find the content type(s) you need.
Step 3: Create a Query
1$ brightspot-cma create-query -p <project-name> -t <content-type> -q <query-name> [-f <comma,separated,fields>]
This command saves the given Query in the Local DB.
Example:
1$ brightspot-cma create-query -p "Example Site" -t com.psddev.cms.db.Site -f urls,simplestAuth.simplestAuthConfiguration -q "Site Settings"
Tip: Use the command
list-queriesto list existing queries.
Step 4: Download Query Data from an Environment
1$ brightspot-cma download -p <project-name> -e <environment-name> -q <query-name>
This command downloads all data matching the given query and saves it to your Local DB. It also prints the Download ID, which you'll use later to upload the downloaded data.
Example:
1$ brightspot-cma download -p "Example Site" -e Production -q "Site Settings"270f5b9fb-8bf0-4e8e-999d-b7d5052f64e6
Tip: Use the command
list-downloads -vto list all downloads and their IDs.
Step 5: Upload Downloaded Query Data to an Environment
1$ brightspot-cma upload -p <project-name> -e <environment-name> -i <download-id>
This command uploads all data downloaded in Step 4 to the given environment.
Example:
1$ brightspot-cma upload -p "Example Site" -e Production -i 70f5b9fb-8bf0-4e8e-999d-b7d5052f64e62Uploading [0000017e-5916-d0fd-a7fe-fb9f88170000] [1/1]
Tip: By specifying a subset of
fieldsin the Query, you can limit which fields will be updated on the target environment.
Command Reference
1init Initialize Project or Environment with given credentials2Usage: init [options]3Options:4* --project, -p5Project6* --environment, -e7Environment8* --endpoint-url, -u9Endpoint URL10* --client-id, -c11Client ID12* --client-secret, -s13Client Secret1415list-projects List all Projects16Usage: list-projects1718list-environments List all Environments for a given Project19Usage: list-environments [options]20Options:21* --project, -p22Project2324refresh-types Refresh Local DB copy of all Content Types25Usage: refresh-types [options]26Options:27* --project, -p28Project29* --environment, -e30Environment3132list-types List all Content Types33Usage: list-types [options]34Options:35* --project, -p36Project37* --environment, -e38Environment3940show-type Show details for a single Content Type41Usage: show-type [options]42Options:43* --project, -p44Project45* --environment, -e46Environment47* --type, -t48Type4950test-query Test Query Without Saving51Usage: test-query [options]52Options:53* --project, -p54Project55* --environment, -e56Environment57* --type, -t58Content Type59--where, -w60Where Clause61--fields, -f62Field Names, comma separated (field1,field2,field3)63--limit, -l64Limit65--offset, -o66Offset67--indent, -i68Indent?69Default: false7071create-query Create a query that can be used to download backups72Usage: create-query [options]73Options:74* --project, -p75Project76* --query, -q77Query Name78* --type, -t79Content Type80--where, -w81Where Clause82--fields, -f83Field Names, comma separated (field1,field2,field3)8485list-queries List All Queries86Usage: list-queries [options]87Options:88--verbose, -v89List Verbose Details90Default: false91* --project, -p92Project9394download Copy data from a Project/Environment to the Local DB95Usage: download [options]96Options:97* --project, -p98Project99* --environment, -e100Environment101* --query, -q102Query Name103--limit, -l104Limit105106list-downloads List All Downloads107Usage: list-downloads [options]108Options:109* --project, -p110Project111--environment, -e112Environment113--query, -q114Query Name115--latest-only, -l116Only display latest download117Default: false118--verbose, -v119Display verbose details120Default: false121--json, -j122Display in JSON format123Default: false124125upload Upload data to a project environment126Usage: upload [options]127Options:128* --project, -p129Project130* --environment, -e131Environment132* --download-id, -i133Download ID
Definitions
Project
A Project represents a logical Brightspot application belonging to a single customer and consisting of one or more Environments. Data can be copied between Environments on a single Project, but not from one Project to another Project.
All configuration and locally cached data for a given Project is stored in a single Local DB file.
Environment
An Environment is a single instance of Brightspot in a Project. QA, UAT, and Production are all Environments. Each environment will have a single Endpoint URL, Client ID, and Client Secret.
Endpoint URL, Client ID, and Client Secret
These settings can be found on the REST API configuration in Brightspot.
Local DB
This tool uses a collection of SQLite databases in $HOME/.brightspot_api_data; one per project. These can be queried and modified using any compatible SQLite utilities.