Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Jul 2017 14:31:38 +0000 (UTC)
From:      Glen Barber <gjb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r320599 - head/release/scripts
Message-ID:  <201707031431.v63EVcUN040660@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gjb
Date: Mon Jul  3 14:31:38 2017
New Revision: 320599
URL: https://svnweb.freebsd.org/changeset/base/320599

Log:
  Fix Vagrant image upload after recent API changes.
  
  - Update ATLAS_UPLOAD_URL to avoid various regular expressions
    from failing to match due to redirections.
  - Use ATLAS_UPLOAD_URL throughout the script.
  - Adjust several regular expression patterns.
  
  MFC after:	3 days
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/release/scripts/atlas-upload.sh

Modified: head/release/scripts/atlas-upload.sh
==============================================================================
--- head/release/scripts/atlas-upload.sh	Mon Jul  3 13:46:58 2017	(r320598)
+++ head/release/scripts/atlas-upload.sh	Mon Jul  3 14:31:38 2017	(r320599)
@@ -27,7 +27,7 @@
 #
 
 ATLAS_API_URL=''
-ATLAS_UPLOAD_URL='https://binstore.hashicorp.com'
+ATLAS_UPLOAD_URL='https://app.vagrantup.com'
 DESCRIPTION="FreeBSD Snapshot Build"
 
 usage() {
@@ -76,7 +76,7 @@ main () {
 	fi
 
 	# Check to see if the box exists or create it
-	BOXRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}?access_token=${KEY}")
+	BOXRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}?access_token=${KEY}")
 	if [ $? != 0 ]; then
 		echo "Failed to connect to the API"
 		exit 2;
@@ -84,26 +84,26 @@ main () {
 	echo $BOXRESULT | grep "\"name\":\"${BOX}\"" > /dev/null
 	if [ $? != 0 ]; then
 		echo "Creating box: ${BOX}"
-		/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/boxes -X POST -d "box[name]=${BOX}" -d "access_token=${KEY}" > /dev/null
-		/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[is_private]=false" -d "access_token=${KEY}" > /dev/null
-		/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[description]='${DESCRIPTION}'" -d "access_token=${KEY}" > /dev/null
+		/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/boxes -X POST -d "box[name]=${BOX}" -d "access_token=${KEY}" > /dev/null
+		/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[is_private]=false" -d "access_token=${KEY}" > /dev/null
+		/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX} -X PUT -d "box[description]='${DESCRIPTION}'" -d "access_token=${KEY}" > /dev/null
 	else
 		echo "Box already exists"
 	fi
 
 	# Check to see if the version exists or create it
-	VERSIONRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}")
+	VERSIONRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}")
 	if [ $? != 0 ]; then
 		echo "Failed to connect to the API"
 		exit 2;
 	fi
-	echo $VERSIONRESULT | grep "\"version\":\"${VERSION}\"" > /dev/null
+	echo $VERSIONRESULT | grep "version/${VERSION}" > /dev/null
 	if [ $? != 0 ]; then
 		echo "Creating version: ${VERSION}"
-		/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/versions -X POST -d "version[version]=${VERSION}" -d "access_token=${KEY}" > /dev/null
-		/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION} -X PUT -d "version[description]=${DESCRIPTION}" -d "access_token=${KEY}" > /dev/null
-		VERSIONRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}")
-		echo $VERSIONRESULT | grep "\"version\":\"${VERSION}\"" > /dev/null
+		/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/versions -X POST -d "version[version]=${VERSION}" -d "access_token=${KEY}" > /dev/null
+		/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION} -X PUT -d "version[description]=${DESCRIPTION}" -d "access_token=${KEY}" > /dev/null
+		VERSIONRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}?access_token=${KEY}")
+		echo $VERSIONRESULT | grep "version/${VERSION}" > /dev/null
 		if [ $? != 0 ]; then
 			echo "Failed to create version"
 			exit 2
@@ -113,37 +113,37 @@ main () {
 	fi
 
 	# Check to see if the provider exists or create it
-	PROVIDERRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}")
+	PROVIDERRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}")
 	if [ $? != 0 ]; then
 		echo "Failed to connect to the API"
 		exit 2;
 	fi
-	echo $PROVIDERRESULT | grep "\"name\":\"${PROVIDER}\"" > /dev/null
+	echo $PROVIDERRESULT | grep "provider/${PROVIDER}" > /dev/null
 	if [ $? != 0 ]; then
 		echo "Creating provider: ${PROVIDER}"
-		/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/providers -X POST -d "provider[name]=${PROVIDER}" -d "access_token=${KEY}" > /dev/null
+		/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/providers -X POST -d "provider[name]=${PROVIDER}" -d "access_token=${KEY}" > /dev/null
 	else
 		echo "Provider already exists"
 	fi
 
 	# Request an upload token
-	TOKENRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}/upload?access_token=${KEY}")
+	TOKENRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}/upload?access_token=${KEY}")
 	if [ $? != 0 ]; then
 		echo "Failed to get the token from the API"
 		exit 2;
 	fi
-	echo ${TOKENRESULT} | grep -E "\"(token|upload_path)\":" > /dev/null
+	echo ${TOKENRESULT} | grep -E "upload_path" > /dev/null
 	if [ $? != 0 ]; then
 		echo "No token found from the API"
 		exit 2
 	else
 		TOKEN=$(echo $TOKENRESULT | sed -e 's/.*token":"//' -e 's/.*upload_path":"//' -e 's/}$//g' -e 's/"//g')
 		echo "Uploading to Atlas"
-		UPLOADRESULT=$(/usr/local/bin/curl -s -X PUT --upload-file ${FILE} ${TOKEN})
+		UPLOADRESULT=$(/usr/local/bin/curl -s -X PUT --upload-file ${FILE} "${TOKEN}")
 
 		# Validate the Upload
 		echo "Validating"
-		VALIDRESULT=$(/usr/local/bin/curl -s "https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}")
+		VALIDRESULT=$(/usr/local/bin/curl -s "${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/provider/${PROVIDER}?access_token=${KEY}")
 		HOSTED_TOKEN=$(echo $VALIDRESULT | sed -e 's/.*"hosted"://' -e 's/,.*$//')
 		if [ ! -z ${TOKEN} -a "${HOSTED_TOKEN}" != "true" ]; then
 			echo "Upload failed, try again."
@@ -152,7 +152,7 @@ main () {
 
 		# Release the version
 		echo "Releasing ${VERSION} of ${BOX} in Atlas"
-		/usr/local/bin/curl -s https://atlas.hashicorp.com/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/release -X PUT -d "access_token=${KEY}" > /dev/null
+		/usr/local/bin/curl -s ${ATLAS_UPLOAD_URL}/api/v1/box/${USERNAME}/${BOX}/version/${VERSION}/release -X PUT -d "access_token=${KEY}" > /dev/null
 	fi
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707031431.v63EVcUN040660>