You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/08/15 20:56:13 UTC

[GitHub] dangogh closed pull request #2658: Cache script improvements

dangogh closed pull request #2658: Cache script improvements
URL: https://github.com/apache/trafficcontrol/pull/2658
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/infrastructure/cdn-in-a-box/README.md b/infrastructure/cdn-in-a-box/README.md
index c4caf9524..6b3ac0d47 100644
--- a/infrastructure/cdn-in-a-box/README.md
+++ b/infrastructure/cdn-in-a-box/README.md
@@ -1,44 +1,139 @@
 <!--
-    Licensed to the Apache Software Foundation (ASF) under one
-    or more contributor license agreements.  See the NOTICE file
-    distributed with this work for additional information
-    regarding copyright ownership.  The ASF licenses this file
-    to you under the Apache License, Version 2.0 (the
-    "License"); you may not use this file except in compliance
-    with the License.  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing,
-    software distributed under the License is distributed on an
-    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-    KIND, either express or implied.  See the License for the
-    specific language governing permissions and limitations
-    under the License.
--->
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements.  See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership.  The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License.  You may obtain a copy of the License at
+
+	  http://www.apache.org/licenses/LICENSE-2.0
 
-CDN In a Box (containerized)
-============================
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied.  See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
 
-This is intended to simplify the process of creating a "CDN in a box",  easing
+# CDN In a Box (containerized)
+This is intended to simplify the process of creating a "CDN in a box", easing
 the barrier to entry for newcomers as well as providing a way to spin up a
 minimal CDN for full system testing.
 
-For now,  only `traffic_ops` and `traffic_portal` are implemented.  Other
-components will follow as well as details on specific parts of the
-implementation.. 
+## Implemented Components
+As of the time of this writing, Traffic Ops, Traffic Monitor, Traffic Portal and a
+database server for Traffic Ops are all fully implemented. An edge-tier cache,
+mid-tier cache and simple origin are also all implemented, although with limited
+functionality (caches do not respond to update queues/routing, and origin serves
+static HTTP content - likely subject to change in favor of proper video streaming in
+the future). Other components will follow as well as details on specific parts of the
+implementation.
+
+## Setup
+The containers run on docker, and require Docker (tested v17.05.0-ce) and Docker
+Compose (tested v1.9.0) to build and run. On most 'nix systems these can be installed
+via the distribution's package manager under the names `docker-ce` and
+`docker-compose`, respectively (e.g. `sudo yum install docker-ce`).
+
+Each container (except the origin) requires an `.rpm` file to install the Traffic Control
+component for which it is responsible. You can either download these `*.rpm` files or
+create them yourself by using the [`pkg`](../../pkg) script at the root of the
+repository. Copy the `*.rpm`s without any version/architecture information to their
+respective component directories, such that their filenames are as follows:
+
+* `edge/traffic_ops_ort.rpm`
+* `mid/traffic_ops_ort.rpm`
+* `traffic_monitor/traffic_monitor.rpm`
+* `traffic_ops/traffic_ops.rpm`
+* `traffic_portal/traffic_portal.rpm`
+
+Finally, run the test CDN using the command:
+
+```bash
+docker-compose up --build
+```
+
+## Components
+> The following assumes that the default configuration provided in
+> [`variables.env`](./variables.env) is used.
+
+Once your CDN is running, you should see a cascade of output on your terminal. This is
+typically the output of the build, then setup, and finally logging infrastructure
+(assuming nothing goes wrong). You can now access the various components of the CDN on
+your local machine. For example, opening [`https://localhost`](https://localhost) should
+show you the default UI for interacting with the CDN - Traffic Portal.
+
+> Note: You will likely see a warning about an untrusted or invalid certificate for
+> components that serve over HTTPS (Traffic Ops & Traffic Portal). If you
+> are sure that you are looking at `https://localhost:N` for some integer `N`, these
+> warnings may be safely ignored via the e.g. `Add Exception` button (possibly hidden
+> behind e.g. `Advanced Options`).
+
+
+
+### Traffic Ops
+The API and legacy UI for the CDN
+* URLs:
+	* New Go endpoints: [`https://localhost:6443`](https://localhost:6443)
+	* Limited, Legacy Perl endpoints: [`https://localhost:60443`](https://localhost:60443)
+* Login Credentials:
+	* Username: Defined by `TO_ADMIN_USER` in [`variables.env`](./variables.env)
+	* Password: Defined by `TO_ADMIN_PASSWORD` in [`variables.env`](./variables.env)
+
+Login credentials will work for both sets of endpoints.
+Note that the recommended way to access the Traffic Ops API is through the new Go endpoints.
+Not all endpoints have been implemented in Go, but the Go server will proxy requests it cannot
+service back to the legacy API.
+
+### Traffic Portal
+The modern UI for the CDN
+* URL: [`https://localhost`](https://localhost)
+* Login Credentials:
+	* Username: Defined by `TO_ADMIN_USER` in [`variables.env`](./variables.env)
+	* Password: Defined by `TO_ADMIN_PASSWORD` in [`variables.env`](./variables.env)
+
+### Traffic Ops PostgreSQL Database
+This holds the configuration information for the entire CDN. It is normally accessed
+directly only by Traffic Ops.
+* URL: [`postgres://traffic_ops:twelve@localhost:5432/traffic_ops`](postgres://traffic_ops:twelve@localhost:5432/traffic_ops)
+* Login Credentials:
+	* Username: Defined by `DB_USER` in [`variables.env`](./variables.env)
+	* Password: Defined by `DB_USER_PASS` in [`variables.env`](./variables.env)
+* Port: 5432
+* Database: Defined by `DB_NAME` in [`variables.env`](./variables.env)
+
+### Traffic Vault
+A secure storage server for private keys used by Traffic Ops
+* Port: 8010
+
+### Traffic Monitor
+Traffic Monitor is responsible for monitoring and reporting the "health" of edge- and
+mid-tier caches (See [the documentation](http://traffic-control-cdn.readthedocs.io/en//latest/overview/traffic_monitor.html) for details).
+
+* URL: [`http://localhost`](http://localhost)
+
+### Edge-Tier Cache
+An edge-tier cache sits at the outermost extremity of the CDN, typically serving content
+directly to the user from either its cache, or a parent cache group. The management port
+is not exposed locally - however the main content port is.
+
+* URL: [`http://localhost:8080`](http://localhost:8080)
+
+### Mid-Tier Cache
+A mid-tier cache serves content internally - within the CDN. Typically, requests are
+made from an edge-tier cache and the mid serves content from its own cache, a parent
+mid-tier cache or directly from the origin. The management port is not exposed locally -
+however the main content port is.
+
+* URL: [`http://localhost:9080`](http://localhost:8081)
+
+### Origin Server
+An origin server simply serves HTTP(S) content. The CDN-in-a-box origin server serves up
+a very simple page sporting the Traffic Control logo.
 
-To start it, install `docker-ce` and `docker-compose`.  Create an rpm for each
-component and copy into the respective directory with no version number, e.g.
-`traffic_ops/traffic_ops.rpm`, `traffic_portal/traffic_portal.rpm`.
-    
-    cd infrastructure/cdn-in-a-box
-    docker-compose up --build
+* URL: [`http://localhost:8081`](http://localhost:9080)
 
 The process creates containers for each component with ports exposed on the host.  The
 following should be available once the system is running:
-   
-    Traffic Portal: https://localhost    
-    Traffic Ops (go): https://localhost:6443
-    Traffic Ops (perl): https://localhost:60443
-    Postgres: `psql -h localhost -p 5432 -U postgres`
diff --git a/infrastructure/cdn-in-a-box/docker-compose.yml b/infrastructure/cdn-in-a-box/docker-compose.yml
index 6428728b8..4e70aae06 100644
--- a/infrastructure/cdn-in-a-box/docker-compose.yml
+++ b/infrastructure/cdn-in-a-box/docker-compose.yml
@@ -164,7 +164,8 @@ services:
   # edge cache
   edge:
     build:
-      context: edge
+      context: .
+      dockerfile: edge/Dockerfile
     domainname: cdn.local
     env_file:
       - variables.env
@@ -177,7 +178,8 @@ services:
   # mid cache
   mid:
     build:
-      context: mid
+      context: .
+      dockerfile: mid/Dockerfile
     domainname: cdn.local
     env_file:
       - variables.env
diff --git a/infrastructure/cdn-in-a-box/edge/Dockerfile b/infrastructure/cdn-in-a-box/edge/Dockerfile
index 0f4c2cfd9..7484de457 100644
--- a/infrastructure/cdn-in-a-box/edge/Dockerfile
+++ b/infrastructure/cdn-in-a-box/edge/Dockerfile
@@ -25,13 +25,13 @@ FROM centos:7
 
 ARG RPM=https://ci.trafficserver.apache.org/RPMS/CentOS7/trafficserver-7.1.2-4.el7.centos.x86_64.rpm
 ADD $RPM /trafficserver.rpm
-ADD traffic_ops_ort.rpm /
+ADD edge/traffic_ops_ort.rpm /
 
 RUN yum install -y /trafficserver.rpm iproute net-tools nmap-ncat epel-release
 RUN yum install -y jq && yum clean all
 
 RUN mkdir -p /var/trafficserver/cache /opt/ort && chown -R ats:ats /etc/trafficserver/ /var/trafficserver/ /opt/ort
-ADD parameters.json profile.json server.json setup.sh /
+ADD edge/parameters.json edge/profile.json edge/server.json edge/setup.sh traffic_ops/to-access.sh /
 
 EXPOSE 80
 
diff --git a/infrastructure/cdn-in-a-box/edge/setup.sh b/infrastructure/cdn-in-a-box/edge/setup.sh
index 442eecc01..3d8d8ccb0 100755
--- a/infrastructure/cdn-in-a-box/edge/setup.sh
+++ b/infrastructure/cdn-in-a-box/edge/setup.sh
@@ -38,7 +38,9 @@ sed -ie "s;MY_GATEWAY;$gateway;g" /server.json
 sed -ie "s;MY_NETMASK;$netmask;g" /server.json
 sed -ie "s;MY_IP;$myIP;g" /server.json
 
-while !  curl -ks https://$TO_HOST:$TO_PORT/api/1.3/ping; do
+source /to-access.sh
+
+while ! to-ping; do
 	echo "waiting for Traffic Ops"
 	sleep 3
 done
@@ -48,42 +50,42 @@ curl -ksc cookie.jar -d "{\"u\":\"$TO_ADMIN_USER\",\"p\":\"$TO_ADMIN_PASSWORD\"}
 echo
 
 # Gets our CDN ID
-CDN=$(curl -ksb cookie.jar https://$TO_HOST:$TO_PORT/api/1.3/cdns | jq '.response|.[]|select(.name=="CDN-in-a-Box")|.id')
+CDN=$(to-get api/1.3/cdns | jq '.response|.[]|select(.name=="CDN-in-a-Box")|.id')
 while [[ -z "$CDN" ]]; do
 	echo "waiting for trafficops setup to complete..."
 	sleep 3
-	CDN=$(curl -ksb cookie.jar https://$TO_HOST:$TO_PORT/api/1.3/cdns | jq '.response|.[]|select(.name=="CDN-in-a-Box")|.id')
+	CDN=$(to-get api/1.3/cdns | jq '.response|.[]|select(.name=="CDN-in-a-Box")|.id')
 done
 
 
 # Now we upload a profile for later use
 sed -ie "s;CDN_ID;$CDN;g" /profile.json
-PROFILE=$(curl -ksb cookie.jar -d @/profile.json https://$TO_HOST:$TO_PORT/api/1.3/profiles | jq '.response')
+PROFILE=$(to-post api/1.3/profiles /profile.json | jq '.response')
 PROFILENAME=$(echo $PROFILE | jq '.name' | tr -d '"')
 PROFILEID=$(echo $PROFILE | jq '.id')
-curl -ksb cookie.jar -d @/parameters.json https://$TO_HOST:$TO_PORT/api/1.3/profiles/name/$PROFILENAME/parameters
+to-post api/1.3/profiles/name/$PROFILENAME/parameters /parameters.json
 echo
 
 # Gets the location ID
-location=$(curl -ksb cookie.jar https://$TO_HOST:$TO_PORT/api/1.3/phys_locations | jq '.response|.[]|select(.name=="CDN_in_a_Box")|.id')
+location=$(to-get api/1.3/phys_locations | jq '.response|.[]|select(.name=="CDN_in_a_Box")|.id')
 while [[ -z "$location" ]]; do
 	echo "Waiting for location setup"
 	sleep 3
-	location=$(curl -ksb cookie.jar https://$TO_HOST:$TO_PORT/api/1.3/phys_locations | jq '.response|.[]|select(.name=="CDN_in_a_Box")|.id')
+	location=$(to-get api/1.3/phys_locations | jq '.response|.[]|select(.name=="CDN_in_a_Box")|.id')
 done
 
 # Gets the id of a MID server type
-TYPE=$(curl -ksb cookie.jar https://$TO_HOST:$TO_PORT/api/1.3/types | jq '.response|.[]|select(.name=="EDGE")|.id')
+TYPE=$(to-get api/1.3/types | jq '.response|.[]|select(.name=="EDGE")|.id')
 
 # Gets the id of the 'REPORTED' status
-REPORTED=$(curl -ksb cookie.jar https://$TO_HOST:$TO_PORT/api/1.3/statuses | jq '.response|.[]|select(.name=="REPORTED")|.id')
+REPORTED=$(to-get api/1.3/statuses | jq '.response|.[]|select(.name=="REPORTED")|.id')
 
 # Gets the cachegroup ID
-CACHEGROUP=$(curl -ksb cookie.jar https://$TO_HOST:$TO_PORT/api/1.3/cachegroups | jq '.response|.[]|select(.name=="CDN_in_a_Box_Edge")|.id')
+CACHEGROUP=$(to-get api/1.3/cachegroups | jq '.response|.[]|select(.name=="CDN_in_a_Box_Edge")|.id')
 while [[ -z "$CACHEGROUP" ]]; do
 	echo "waiting for trafficops setup to complete..."
 	sleep 3
-	CACHEGROUP=$(curl -ksb cookie.jar https://$TO_HOST:$TO_PORT/api/1.3/cachegroups | jq '.response|.[]|select(.name=="CDN_in_a_Box_Edge")|.id')
+	CACHEGROUP=$(to-get api/1.3/cachegroups | jq '.response|.[]|select(.name=="CDN_in_a_Box_Edge")|.id')
 done
 
 # Now put it all together and send it up
@@ -94,18 +96,18 @@ sed -ie "s;REPORTED_ID;$REPORTED;g" /server.json
 sed -ie "s;CACHE_GROUP_ID;$CACHEGROUP;g" /server.json
 sed -ie "s;MY_PROFILE_ID;$PROFILEID;g" /server.json
 cat /server.json
-SERVER=$(curl -ksb cookie.jar -d @/server.json https://$TO_HOST:$TO_PORT/api/1.3/servers | jq '.response.id')
+SERVER=$(to-post api/1.3/servers /server.json | jq '.response.id')
 
 
 #finally, link this server to a delivery service
-DSID=$(curl -ksb cookie.jar https://$TO_HOST:$TO_PORT/api/1.3/deliveryservices | jq '.response|.[]|select(.displayName=="CDN in a Box")|.id')
+DSID=$(to-get api/1.3/deliveryservices | jq '.response|.[]|select(.displayName=="CDN in a Box")|.id')
 while [[ -z "$DSID" ]]; do
 	echo "Waiting for delivery service creation..."
 	sleep 3
-	DSID=$(curl -ksb cookie.jar https://$TO_HOST:$TO_PORT/api/1.3/deliveryservices | jq '.response|.[]|select(.displayName=="CDN in a Box")|.id')
+	DSID=$(to-get api/1.3/deliveryservices | jq '.response|.[]|select(.displayName=="CDN in a Box")|.id')
 done
 
-curl -ksb cookie.jar -d "{\"dsId\":$DSID,\"servers\":[$SERVER],\"replace\":true}" https://$TO_HOST:$TO_PORT/api/1.2/deliveryserviceserver
+to-post api/1.2/deliveryserviceserver "{\"dsId\":$DSID,\"servers\":[$SERVER],\"replace\":true}"
 echo
 
 fg
diff --git a/infrastructure/cdn-in-a-box/mid/Dockerfile b/infrastructure/cdn-in-a-box/mid/Dockerfile
index b951427bb..a1dab8125 100644
--- a/infrastructure/cdn-in-a-box/mid/Dockerfile
+++ b/infrastructure/cdn-in-a-box/mid/Dockerfile
@@ -31,7 +31,7 @@ RUN yum install -y /trafficserver.rpm iproute jq net-tools nmap-ncat && yum clea
 
 RUN mkdir -p /var/trafficserver/cache /opt/ort && chown -R ats:ats /etc/trafficserver /var/trafficserver /opt/ort
 
-ADD parameters.json profile.json server.json setup.sh /
+ADD mid/parameters.json mid/profile.json mid/server.json mid/setup.sh traffic_ops/to-access.sh /
 
 EXPOSE 80
 
diff --git a/infrastructure/cdn-in-a-box/mid/setup.sh b/infrastructure/cdn-in-a-box/mid/setup.sh
index ee8190f9f..2da88ed3f 100755
--- a/infrastructure/cdn-in-a-box/mid/setup.sh
+++ b/infrastructure/cdn-in-a-box/mid/setup.sh
@@ -38,53 +38,50 @@ sed -ie "s;MY_GATEWAY;$gateway;g" /server.json
 sed -ie "s;MY_NETMASK;$netmask;g" /server.json
 sed -ie "s;MY_IP;$myIP;g" /server.json
 
-TO_URL=https://$TO_HOST:$TO_PORT
-while ! curl -sk $TO_URL/api/1.3/ping </dev/null >/dev/null; do
+source /to-access.sh
+
+while ! to-ping >/dev/null; do
 	echo "waiting for Traffic Ops"
 	sleep 3
 done
 
-# Now network things. First need to authenticate
-curl -ksc cookie.jar -d "{\"u\":\"$TO_ADMIN_USER\",\"p\":\"$TO_ADMIN_PASSWORD\"}" $TO_URL/api/1.3/user/login
-echo
-
 # Gets our CDN ID
-CDN=$(curl -ksb cookie.jar $TO_URL/api/1.3/cdns | jq '.response|.[]|select(.name=="CDN-in-a-Box")|.id')
+CDN=$(to-get api/1.3/cdns | jq '.response|.[]|select(.name=="CDN-in-a-Box")|.id')
 while [[ -z "$CDN" ]]; do
 	echo "waiting for trafficops setup to complete..."
 	sleep 3
-	CDN=$(curl -ksb cookie.jar $TO_URL/api/1.3/cdns | jq '.response|.[]|select(.name=="CDN-in-a-Box")|.id')
+	CDN=$(to-get api/1.3/cdns | jq '.response|.[]|select(.name=="CDN-in-a-Box")|.id')
 done
 
 
 # Now we upload a profile for later use
 sed -ie "s;CDN_ID;$CDN;g" /profile.json
-PROFILE=$(curl -ksb cookie.jar -d @/profile.json $TO_URL/api/1.3/profiles | jq '.response')
+PROFILE=$(to-post api/1.3/profiles /profile.json | jq '.response')
 PROFILENAME=$(echo $PROFILE | jq '.name' | tr -d '"')
 PROFILEID=$(echo $PROFILE | jq '.id')
-curl -ksb cookie.jar -d @/parameters.json $TO_URL/api/1.3/profiles/name/$PROFILENAME/parameters
+to-post api/1.3/profiles/name/$PROFILENAME/parameters /parameters.json
 echo
 
 # Gets the location ID
-location=$(curl -ksb cookie.jar $TO_URL/api/1.3/phys_locations | jq '.response|.[]|select(.name=="CDN_in_a_Box")|.id')
+location=$(to-get api/1.3/phys_locations | jq '.response|.[]|select(.name=="CDN_in_a_Box")|.id')
 while [[ -z "$location" ]]; do
 	echo "Waiting for location setup"
 	sleep 3
-	location=$(curl -ksb cookie.jar $TO_URL/api/1.3/phys_locations | jq '.response|.[]|select(.name=="CDN_in_a_Box")|.id')
+	location=$(to-get api/1.3/phys_locations | jq '.response|.[]|select(.name=="CDN_in_a_Box")|.id')
 done
 
 # Gets the id of a MID server type
-TYPE=$(curl -ksb cookie.jar $TO_URL/api/1.3/types | jq '.response|.[]|select(.name=="MID")|.id')
+TYPE=$(to-get api/1.3/types | jq '.response|.[]|select(.name=="MID")|.id')
 
 # Gets the id of the 'REPORTED' status
-REPORTED=$(curl -ksb cookie.jar $TO_URL/api/1.3/statuses | jq '.response|.[]|select(.name=="REPORTED")|.id')
+REPORTED=$(to-get api/1.3/statuses | jq '.response|.[]|select(.name=="REPORTED")|.id')
 
 # Gets the cachegroup ID
-CACHEGROUP=$(curl -ksb cookie.jar $TO_URL/api/1.3/cachegroups | jq '.response|.[]|select(.name=="CDN_in_a_Box_Mid")|.id')
+CACHEGROUP=$(to-get api/1.3/cachegroups | jq '.response|.[]|select(.name=="CDN_in_a_Box_Mid")|.id')
 while [[ -z CACHEGROUP ]]; do
 	echo "waiting for trafficops setup to complete..."
 	sleep 3
-	CACHEGROUP=$(curl -ksb cookie.jar $TO_URL/api/1.3/cachegroups | jq '.response|.[]|select(.name=="CDN_in_a_Box_Mid")|.id')
+	CACHEGROUP=$(to-get api/1.3/cachegroups | jq '.response|.[]|select(.name=="CDN_in_a_Box_Mid")|.id')
 done
 
 # Now put it all together and send it up
@@ -95,7 +92,7 @@ sed -ie "s;REPORTED_ID;$REPORTED;g" /server.json
 sed -ie "s;CACHE_GROUP_ID;$CACHEGROUP;g" /server.json
 sed -ie "s;MY_PROFILE_ID;$PROFILEID;g" /server.json
 cat /server.json
-curl -ksb cookie.jar -d @/server.json $TO_URL/api/1.3/servers
+to-post api/1.3/servers /server.json
 echo
 
 fg
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 98917ccaa..6c2f87776 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
@@ -30,66 +30,80 @@ TO_URL=https://$TO_HOST:$TO_PORT
 login=$(mktemp -t XXXX.login)
 
 cleanup() {
-    rm -f "$COOKIEJAR" "$login"
+	rm -f "$COOKIEJAR" "$login"
 }
 
 trap cleanup EXIT
 
 cookie_current() {
-    local cookiefile=$1
-    [[ -s $cookiefile ]] || return 1
+	local cookiefile=$1
+	[[ -s $cookiefile ]] || return 1
 
-    # get expiration from cookiejar -- compare to current time
-    exp=$(awk '/mojolicious/ {print $5}' $cookiefile | tail -n 1)
-    cur=$(date +%s)
+	# get expiration from cookiejar -- compare to current time
+	exp=$(awk '/mojolicious/ {print $5}' $cookiefile | tail -n 1)
+	cur=$(date +%s)
 
-    # return value is the comparison itself
-    (( $exp > $cur ))
+	# return value is the comparison itself
+	(( $exp > $cur ))
 }
 
 to-auth() {
-    # These are required
-    if [[ -z $TO_URL || -z $TO_ADMIN_USER || -z $TO_ADMIN_PASSWORD ]]; then
-        echo TO_URL TO_ADMIN_USER TO_ADMIN_PASSWORD must all be set
-        return 1
-    fi
-
-    # if cookiejar is current, nothing to do..
-    cookie_current $COOKIEJAR && return
-
-    local url=$TO_URL/api/1.3/user/login
-    local datatype='Accept: application/json'
-    cat >"$login" <<-CREDS
+	# These are required
+	if [[ -z $TO_URL || -z $TO_ADMIN_USER || -z $TO_ADMIN_PASSWORD ]]; then
+		echo TO_URL TO_ADMIN_USER TO_ADMIN_PASSWORD must all be set
+		return 1
+	fi
+
+	# if cookiejar is current, nothing to do..
+	cookie_current $COOKIEJAR && return
+
+	local url=$TO_URL/api/1.3/user/login
+	local datatype='Accept: application/json'
+	cat >"$login" <<-CREDS
 { "u" : "$TO_ADMIN_USER", "p" : "$TO_ADMIN_PASSWORD" }
 CREDS
-    res=$(curl $CURLAUTH $CURLOPTS -H "$datatype" --cookie "$COOKIEJAR" --cookie-jar "$COOKIEJAR" -X POST --data @"$login" "$url")
-    if [[ $res != *"Successfully logged in."* ]]; then
-        echo "Login failed: $res"
-        return 1
-    fi
+	res=$(curl $CURLAUTH $CURLOPTS -H "$datatype" --cookie "$COOKIEJAR" --cookie-jar "$COOKIEJAR" -X POST --data @"$login" "$url")
+	if [[ $res != *"Successfully logged in."* ]]; then
+		echo "Login failed: $res"
+		return 1
+	fi
 }
 
 to-ping() {
-    # ping endpoint does not require authentication
-    curl $CURLAUTH $CURLOPTS -s -X GET "$TO_URL/api/1.3/ping"
+	# ping endpoint does not require authentication
+	curl $CURLAUTH $CURLOPTS -s -X GET "$TO_URL/api/1.3/ping"
 }
 
 to-get() {
-    to-auth && \
-        curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X GET "$TO_URL/$1"
+	to-auth && \
+		curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X GET "$TO_URL/$1"
 }
 
 to-post() {
-    to-auth && \
-        curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X POST --data @"$2" "$TO_URL/$1"
+	if [[ -z "$2" ]]; then
+		data=""
+	elif [[ -f "$2" ]]; then
+		data="--data @$2"
+	else
+		data="--data $2"
+	fi
+	to-auth && \
+	    curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X POST $data "$TO_URL/$1"
 }
 
 to-put() {
-    to-auth && \
-        curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X PUT --data @"$2" "$TO_URL/$1"
+	if [[ -z "$2" ]]; then
+		data=""
+	elif [[ -f "$2" ]]; then
+		data="--data @$2"
+	else
+		data="--data $2"
+	fi
+	to-auth && \
+	    curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X PUT $data "$TO_URL/$1"
 }
 
 to-delete() {
-    to-auth && \
-        curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X DELETE "$TO_URL/$1"
+	to-auth && \
+		curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X DELETE "$TO_URL/$1"
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services