Package: unify-cli
Element Unify CLIThe Unify CLI is a command line interface to Element Unify. It aims to supports all major APIs in Element Unify,
and all common OSes (Mac, Windows, Linux).It uses the command line tool library Click.https://click.palletsprojects.com/en/7.x/InstallationThe Unify CLI needs Python as a prerequisite. Therefore the installation instructions are divided in two main sections:Python InstallationCLI InstallationPython InstallationThe best way to get a Python environment up is using a Python virtual environment:brew install pyenvbrew install pyenv-virtualenvInitialize virtual environment, this can be accomplish in two ways:Option 1: Edit your Terminal profile (persistent)3.1.1 If you're using bash, append the following to the end of~/.bashrceval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"3.1.2 If you're using ZSH, append the following to the end of~/.zshrceval "$(pyenv init -)"Option 2: Initialize virtualenv for your current session (temporary)3.2 Or, run this command to initialize the virtualenvpyenv initsource ~/.bashrcpyenv install 3.8.0pyenv virtualenv 3.8.0 unify-cliUnify CLI Installationactivate the virtualenvpyenv activate unify-clipip install unify-cliRun a test command to ensure things are working!unify cluster add --helpConfigurationTo get started with Unify CLI, first add your instance of Unify. Note that a cluster represents a deployment of Element Unify.unify cluster addRemote is the URL of Unify. For example,https://app001-aws.elementanalytics.com/.Username is your Unify username (email).Password is your Unify password.Name is a name for this instance. For subsequent examples,unifyis usedYou will be prompted to save your credentials to keyring.Next log in to this instanceunify cluster login --remote=unifyYou may be prompted to access your credentials from keyring.Basic CommandsAn Unify CLI command has the following structureunify <command group> <command> [options and parameters]For example, to list all orgs in Unify:unify org list --remote=unifyMain Command GroupsEach of these has a set of commands that goes with it.ClusterGetListDeleteSet defaults (org, cluster, user)OrgGetUpcertListDeleteGrantUserGetUpcertListDeleteTemplateGetUpcertListDeleteDatasetGetUpcertListDeleteDatastreamSimulatePipeline (include map-attributes)GetUpcertListDeleteRunEvergreen (turn on and off, Maybe part of the upcert?)AccessDatabasesExecuteConfigure CLIFollow the steps below to set up the Unify CLI:Add a new clusterHelpunify cluster add --helpClient will prompt for parametersunify cluster addAll parameters inlineunify cluster add --remote "https://app001-aws.elementanalytics.com/" --username "yourusername" --password "yourpassword" --name "unify"Set cluster as defaultHelpunify cluster default --helpClient will prompt for parametersunify cluster defaultAll commands inlineunify cluster default --remote unifyLog in to clusterHelpunify cluster login --helpClient will prompt for parametersWorkflow activitiesWorkflows commands perform bulk operations to help facilitate common operations such as copying pipelines or templates from one organization to another.Element Unify Instance ManagementDelete existing clusterHelpunify cluster disconnect --helpAll parameters inlineunify cluster disconnect --remote unifyClient will prompt for parametersunify cluster disconnectList all Unify instancesHelpunify cluster list --helpunify cluster listOrganization ManagementCreate OrganizationAll Parameters inline to default clusterunify org add --name "New Organization Name"All Parameters inline to different clusterunify org add --name "New Organization Name" --remote "cluster_name"Client will prompt for parameters ot default clusterunify org addClient will prompt to different clusterunify org add --remote "cluster_name"List all org available for current in userList from default clusterunify org listList from different clusterunify org list --remote "cluster name"Delete org from clusterDelete org from default clusterunify org delete --orgid ######Delete org from different clusterunify org delete --orgid ###### --remote cluster_nameCreate UsersAdd Admin user to an existing org in default clusterunify user add --orgid ###### --email "user_email@email.com" --name "User Name" --role Admin --remote unifyAdd Contributor user to an existing org in default clusterunify user add --orgid ###### --email "user_email@email.com" --name "User Name" --role Contributor --remote unifyAdd user to an existing org to different clusterunify user add --orgid ###### --email "user_email@email.com" --name "User Name" --role Admin --remote cluster_nameAdd Contributor user to an existing org in default clusterunify user add --orgid ###### --email "user_email@email.com" --name "User Name" --role Contributor --remote cluster_nameData WorkflowThis group gives the user the ability to export and import various types of data from templates, sources and pipelinesTemplatesExport: This gives the functionality to export all templates from a given ORG, the output will be in standard output.unify wf export-template --org ##### --remote cluster_nameExport output into fileunify wf export-template --org ##### --remote cluster_nameImport: This will import templates contents into a given org of a clusterunify wf import-template --org ##### --remote cluster_name templates.csvCombine import and export into a single lineunify wf export-template --org ##### --remote origin_cluster_name | unify wf import-template --org ##### --remote destination_cluster_namePipelinesExport: this gives the functionality of exporting all necessary data (except sources) to export a pipelien structure. This command will even include map templates and map attributesunify wf export-pipeline --remote origin_cluster_name --org ##### --pipeline ####Export could also accept multiple pipelines:unify wf export-pipeline --remote origin_cluster_name --org ##### --pipeline #### --pipeline ####Import: This will import pipeline(s) into a given organization of the cluster. This will need a big file as input that can be generated withunify wf export-pipelineunify wf import-pipeline --remote destination_cluster_name --org #####Import and Export combined using command line pipeunify wf export-pipeline --remote origin_cluster_name --org org_origin_id --pipeline pipeline_id_to_be_copied |  unify wf import-pipeline --remote destination_cluster_name --org destination_org_idGraphsList: this gives you the list of all graphs on a given orgunify graph list --remote origin_cluster_name --org #####Query: This will give you the ability to create cypher queries to a given graphunify graph query --org ### --remote origin_cluster_name --graph "GRAPH ID" "Cypher Query" -junify graph query --org #### --remote platad --graph ##### "MATCH (n)-[r]->(g) RETURN *" -jExample: Migrate an organizationThe simplest way to fully migrate an org is to chain together several commands in a single bash script, the following .sh script can do the job.#!/bin/sh

ORIGIN_ORG="5024"
ORIGIN_ENV="unify"
DESTINATION_ORG="10824"
DESTINATION_ENV="unify"

# Login to the origin unify cluster
unify cluster login --remote $ORIGIN_ENV

# Login to the destination unify cluster
unify cluster login --remote $DESTINATION_ENV

# Export the templates from the origin env and imported to the destination env
unify wf export-template --remote $ORIGIN_ENV --org $ORIGIN_ORG | unify wf import-template --remote $DESTINATION_ENV --org $DESTINATION_ORG

echo "Templates were migrated"

# Retrieves the datasets lists into a json array
DATASETS=$(unify dataset list --org $ORIGIN_ORG --remote $ORIGIN_ENV)

# Iterates over the current datasets
jq -c '.[]' <<< $DATASETS | while read js; do
  code_val=$(jq -r '.id' <<< "$js")

  # Export each dataset from the origin env and imported to the destination env
  unify wf export-dataset --remote $ORIGIN_ENV --org $ORIGIN_ORG --id $code_val | unify wf import-dataset --remote $DESTINATION_ENV --org $DESTINATION_ORG
done


# Retrieves the pipeline lists into a json array
PIPELINES=$(unify pipeline list --org $ORIGIN_ORG --remote $ORIGIN_ENV)

# Iterates over the current Pipelines
jq -c '.[]' <<< $PIPELINES | while read jss; do
  code_val=$(jq -r '.id' <<< "$jss")
  # Export each pipeline from the origin env and imported to the destination env
  unify wf export-pipeline --remote $ORIGIN_ENV --org $ORIGIN_ORG --pipeline $code_val --skip datasets --skip templates |  unify wf import-pipeline --remote $DESTINATION_ENV --org $DESTINATION_ORG --skip datasets --skip templates
doneDevelopers SectionInfo for people developing against the CLIRunning the testsInitialize your virtual environment, either using virtualenv, pyenv & pyvenv-virtualenv, or however you have it set up.Install the test requirements:pip install -r tests/requirements.txtSet the environment variables with cluster credentials (note, this should be a testing cluster for tests as it may not clean up after itself). These env var names may be edited intests/local.iniif you like (don't check in the changes of course). Values for these can be found in 1password in the Engineering vault.LOCAL_API_URLLOCAL_ADMIN_NAMELOCAL_ADMIN_PASSWORDRun the tests:nosetests --tc-file tests/local.ini --nocapture -v tests/