trafficcontrol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dang...@apache.org
Subject [trafficcontrol] branch master updated: Let auto-snapqueue and add-sslkeys be functions (#3475)
Date Wed, 10 Jul 2019 20:30:55 GMT
This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 7162d88  Let auto-snapqueue and add-sslkeys be functions (#3475)
7162d88 is described below

commit 7162d8875876540c90ce3f84c3ff702e922365ac
Author: Shihta Kuan <Shihta@users.noreply.github.com>
AuthorDate: Thu Jul 11 04:30:49 2019 +0800

    Let auto-snapqueue and add-sslkeys be functions (#3475)
    
    auto-snapqueue and add-sslkeys are good features and worth reusing.
    This commit changes them into separate functions.
---
 infrastructure/cdn-in-a-box/traffic_ops/run-go.sh  | 90 +---------------------
 .../cdn-in-a-box/traffic_ops/to-access.sh          | 88 +++++++++++++++++++++
 2 files changed, 92 insertions(+), 86 deletions(-)

diff --git a/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh b/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
index b38a8d0..6a542c7 100755
--- a/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
@@ -87,94 +87,12 @@ while true; do
 done
 
 ### Add SSL keys for demo1 delivery service
-demo1_sslkeys_verified=false
-demo1_version=1
-while [[ "$demo1_sslkeys_verified" = false ]]; do
-   while true; do
-     sslkeys_response=$(to-get "api/1.4/deliveryservices/xmlId/$ds_name/sslkeys?decode=true")
-     echo "CDN SSLKeys=$sslkeys_response"
-     [[ -n "$sslkeys_response" ]] && break
-     sleep 2
-   done
-   demo1_crt="$(sed -n -e '/-----BEGIN CERTIFICATE-----/,$p' $X509_DEMO1_CERT_FILE | jq -s
-R '.')"
-   demo1_csr="$(sed -n -e '/-----BEGIN CERTIFICATE REQUEST-----/,$p' $X509_DEMO1_REQUEST_FILE
| jq -s -R '.')"
-   demo1_key="$(sed -n -e '/-----BEGIN PRIVATE KEY-----/,$p' $X509_DEMO1_KEY_FILE | jq -s
-R '.')"
-   demo1_json_request=$(jq -n \
-                           --arg     cdn        "$CDN_NAME" \
-                           --arg     hostname   "*.demo1.mycdn.ciab.test" \
-                           --arg     dsname     "$ds_name" \
-                           --argjson crt        "$demo1_crt" \
-                           --argjson csr        "$demo1_csr" \
-                           --argjson key        "$demo1_key" \
-                           --argjson version    $demo1_version \
-                          "{ cdn: \$cdn, 
-                             certificate: { 
-                               crt: \$crt, 
-                               csr: \$csr,
-                               key: \$key 
-                             },
-                             deliveryservice: \$dsname,
-                             hostname: \$hostname,
-                             key: \$dsname,
-                             version: $demo1_version 
-                          }")
-
-   demo1_json_response=$(to-post 'api/1.4/deliveryservices/sslkeys/add' "$demo1_json_request")
-
-   if [[ -n "$demo1_json_response" ]] ; then 
-      sleep 2
-      cdn_sslkeys_response=$(to-get "api/1.3/cdns/name/$CDN_NAME/sslkeys.json" | jq '.response[]
| length')
-      echo "cdn_sslkeys_response=$cdn_sslkeys_response"
-
-      if [ -n "$cdn_sslkeys_response" ] ; then 
-         if ((cdn_sslkeys_response==0)); then 
-           sleep 2 # Submit it again because the first time doesn't work !
-           demo1_json_response=$(to-post 'api/1.4/deliveryservices/sslkeys/add' "$demo1_json_request")
- 
-           if [[ -n "$demo1_json_response" ]] ; then 
-              demo1_sslkeys_verified=true
-           fi
-        elif ((cdn_sslkeys_response>0)); then
-           demo1_sslkeys_verified=true
-        fi
-      fi
-   fi
-
-   ((demo_version+=1)) 
-done
+to-add-sslkeys $CDN_NAME $ds_name "*.demo1.mycdn.ciab.test" $X509_DEMO1_CERT_FILE $X509_DEMO1_REQUEST_FILE
$X509_DEMO1_KEY_FILE
 
 ### Automatic Queue/Snapshot ###
-while [[ "$AUTO_SNAPQUEUE_ENABLED" = true ]] ; do
+if [[ "$AUTO_SNAPQUEUE_ENABLED" = true ]]; then
   # AUTO_SNAPQUEUE_SERVERS should be a comma delimited list of expected docker service names
to be enrolled - see varibles.env
-  expected_servers_json=$(echo "$AUTO_SNAPQUEUE_SERVERS" | tr ',' '\n' | jq -R . | jq -M
-c -e -s '.|sort')
-  expected_servers_list=$(jq -r -n --argjson expected "$expected_servers_json" '$expected|join(",")')
-  expected_servers_total=$(jq -r -n --argjson expected "$expected_servers_json" '$expected|length')
-
-  current_servers_json=$(to-get 'api/1.4/servers' 2>/dev/null | jq -c -e '[.response[]
| .xmppId] | sort')
-  [ -z "$current_servers_json" ] && current_servers_json='[]'
-  current_servers_list=$(jq -r -n --argjson current "$current_servers_json" '$current|join(",")')
-  current_servers_total=$(jq -r -n --argjson current "$current_servers_json" '$current|length')
-
-  remain_servers_json=$(jq -n --argjson expected "$expected_servers_json" --argjson current
"$current_servers_json" '$expected-$current')
-  remain_servers_list=$(jq -r -n --argjson remain "$remain_servers_json" '$remain|join(",")')
-  remain_servers_total=$(jq -r -n --argjson remain "$remain_servers_json" '$remain|length')
-
-  echo "AUTO-SNAPQUEUE - Expected Servers ($expected_servers_total): $expected_servers_list"
-  echo "AUTO-SNAPQUEUE - Current Servers ($current_servers_total): $current_servers_list"
-  echo "AUTO-SNAPQUEUE - Remain Servers ($remain_servers_total): $remain_servers_list"
-
-  if ((remain_servers_total == 0)) ; then
-     echo "AUTO-SNAPQUEUE - All expected servers enrolled."
-     sleep $AUTO_SNAPQUEUE_ACTION_WAIT
-     echo "AUTO-SNAPQUEUE - Do automatic snapshot..."
-     to-put 'api/1.3/cdns/2/snapshot'
-     sleep $AUTO_SNAPQUEUE_ACTION_WAIT
-     echo "AUTO-SNAPQUEUE - Do queue updates..."
-     to-post 'api/1.3/cdns/2/queue_update' '{"action":"queue"}'
-     break
-  fi
-
-  sleep $AUTO_SNAPQUEUE_POLL_INTERVAL
-done
+  to-auto-snapqueue $AUTO_SNAPQUEUE_SERVERS $CDN_NAME
+fi
 
 exec tail -f /dev/null
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh b/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
index 7e3b2ce..ad83504 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
@@ -269,3 +269,91 @@ function testenrolled() {
 	tmp=$(echo $tmp | jq '.response[]|select(.hostName=="'"$MY_HOSTNAME"'")')
 	echo "$tmp"
 }
+
+# Add SSL keys
+# args:
+#     cdn_name
+#     deliveryservice_name
+#     hostname
+#     crt_path
+#     csr_path
+#     key_path
+to-add-sslkeys() {
+	demo1_crt="$(sed -n -e '/-----BEGIN CERTIFICATE-----/,$p' $4 | jq -s -R '.')"
+	demo1_csr="$(sed -n -e '/-----BEGIN CERTIFICATE REQUEST-----/,$p' $5 | jq -s -R '.')"
+	demo1_key="$(sed -n -e '/-----BEGIN PRIVATE KEY-----/,$p' $6 | jq -s -R '.')"
+	json_request=$(jq -n \
+	                  --arg     cdn        "$1" \
+	                  --arg     dsname     "$2" \
+	                  --arg     hostname   "$3" \
+	                  --argjson crt        "$demo1_crt" \
+	                  --argjson csr        "$demo1_csr" \
+	                  --argjson key        "$demo1_key" \
+	                 "{ cdn: \$cdn,
+	                    certificate: {
+	                      crt: \$crt,
+	                      csr: \$csr,
+	                      key: \$key
+	                    },
+	                    deliveryservice: \$dsname,
+	                    hostname: \$hostname,
+	                    key: \$dsname,
+	                    version: 1
+	                 }")
+
+	while true; do
+		json_response=$(to-post 'api/1.4/deliveryservices/sslkeys/add' "$json_request")
+		if [[ -n "$json_response" ]] ; then
+			sleep 3
+			cdn_sslkeys_response=$(to-get "api/1.3/cdns/name/$1/sslkeys.json" | jq '.response[] |
length')
+			if ((cdn_sslkeys_response>0)); then
+				break
+			else
+				# Submit it again because the first time doesn't work !
+				sleep 3
+			fi
+		else
+			sleep 3
+		fi
+	done
+}
+
+# AUTO_SNAPQUEUE
+# args:
+#     expected_servers - should be a comma delimited list of expected docker service names
to be enrolled
+#     cdn_name
+to-auto-snapqueue() {
+	while true; do
+		# AUTO_SNAPQUEUE_SERVERS should be a comma delimited list of expected docker service names
to be enrolled - see varibles.env
+		expected_servers_json=$(echo "$1" | tr ',' '\n' | jq -R . | jq -M -c -e -s '.|sort')
+		expected_servers_list=$(jq -r -n --argjson expected "$expected_servers_json" '$expected|join(",")')
+		expected_servers_total=$(jq -r -n --argjson expected "$expected_servers_json" '$expected|length')
+
+		current_servers_json=$(to-get 'api/1.4/servers' 2>/dev/null | jq -c -e '[.response[]
| .xmppId] | sort')
+		[ -z "$current_servers_json" ] && current_servers_json='[]'
+		current_servers_list=$(jq -r -n --argjson current "$current_servers_json" '$current|join(",")')
+		current_servers_total=$(jq -r -n --argjson current "$current_servers_json" '$current|length')
+
+		remain_servers_json=$(jq -n --argjson expected "$expected_servers_json" --argjson current
"$current_servers_json" '$expected-$current')
+		remain_servers_list=$(jq -r -n --argjson remain "$remain_servers_json" '$remain|join(",")')
+		remain_servers_total=$(jq -r -n --argjson remain "$remain_servers_json" '$remain|length')
+
+		echo "AUTO-SNAPQUEUE - Expected Servers ($expected_servers_total): $expected_servers_list"
+		echo "AUTO-SNAPQUEUE - Current Servers ($current_servers_total): $current_servers_list"
+		echo "AUTO-SNAPQUEUE - Remain Servers ($remain_servers_total): $remain_servers_list"
+
+		if ((remain_servers_total == 0)) ; then
+			echo "AUTO-SNAPQUEUE - All expected servers enrolled."
+			sleep $AUTO_SNAPQUEUE_ACTION_WAIT
+			echo "AUTO-SNAPQUEUE - Do automatic snapshot..."
+			cdn_id=$(to-get "api/1.3/cdns?name=$2" |jq '.response[0].id')
+			to-put "api/1.3/cdns/$cdn_id/snapshot"
+			sleep $AUTO_SNAPQUEUE_ACTION_WAIT
+			echo "AUTO-SNAPQUEUE - Do queue updates..."
+			to-post "api/1.3/cdns/$cdn_id/queue_update" '{"action":"queue"}'
+			break
+		fi
+
+		sleep $AUTO_SNAPQUEUE_POLL_INTERVAL
+	done
+}


Mime
View raw message