Last active
September 16, 2021 19:35
-
-
Save onefoursix/eaa2f45e742ab5dc25b891ea8aece971 to your computer and use it in GitHub Desktop.
StreamSets REST API Example of creating an SDC Deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This script creates an SDC Deployment based on the manifest file pointed to | |
# by the DEPLOYMENT_MANIFEST_FILE environment variable set below. | |
# The deployment manifest file should use '\n' (without the quotes) rather than new line characters | |
# and all quote characters should be escaped. | |
# Here is an example deployment.yaml file that can be used: | |
# https://gist.githubusercontent.com/onefoursix/f5a1084079f5b80c97c3418c9c267dca/raw/ac2dce6f69beb74d4ee6951d4cc83ec5e39c141e/deployment.yaml | |
## User variables ################################################ | |
# Control Hub User in the form <user>@<org> | |
SCH_USER= | |
# Control Hub Password | |
SCH_PASSWORD= | |
# Control Hub Base URL | |
SCH_BASE_URL=https://cloud.streamsets.com | |
# Name for the SDC Deployment | |
DEPLOYMENT_NAME='CURL_DEPLOYMENT' | |
# Description for the SDC Deployment | |
DEPLOYMENT_DESCRIPTION='CURL_DEPLOYMENT_DESCRIPTION' | |
# Number of instances for the SDC Deployment | |
NUM_INSTANCES=1 | |
# Deployment manifest file (see comments above) | |
DEPLOYMENT_MANIFEST_FILE='deployment.yaml' | |
# Control Agent ID. Get this value from Control Hub > Administration > Provisioning Agents | |
CONTROL_AGENT_ID='' | |
## End of User variables ################################################ | |
## Get a Control Hub Auth Token ################################## | |
curl -X POST $SCH_BASE_URL/security/public-rest/v1/authentication/login \ | |
--header "Content-Type:application/json" --header "X-Requested-By:SDC" \ | |
-d "{\"userName\":\"$SCH_USER\", \"password\": \"$SCH_PASSWORD\"}" \ | |
-c cookie.txt | |
# Extract the auth token from the response | |
AUTH_TOKEN=$(cat cookie.txt | grep SSO | rev | grep -o '^\S*' | rev) | |
# Delete cookie | |
rm -f cookie.txt | |
echo '' | |
echo 'Creating SDC Deployment...' | |
curl -s -X PUT "${SCH_BASE_URL}/provisioning/rest/v1/deployments" --header "Content-Type:application/json" --header "X-Requested-By:SDC" --header "X-SS-REST-CALL:true" --header "X-SS-User-Auth-Token:${AUTH_TOKEN}" -d "{\"name\":\"${DEPLOYMENT_NAME}\",\"description\":\"${DEPLOYMENT_DESCRIPTION}\",\"labels\":[\"label_1\",\"label_2\"],\"numInstances\":1,\"agentId\":\"${CONTROL_AGENT_ID}\",\"spec\": \"$(cat ${DEPLOYMENT_MANIFEST_FILE})\"}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment