summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorblsaws <bryan.sullivan@att.com>2016-06-14 14:29:41 -0700
committerblsaws <bryan.sullivan@att.com>2016-06-14 14:29:41 -0700
commit2c2706a89767de9f3df4cbeda9e8e1dad5e1fa33 (patch)
tree5751dfab6c97edddcca700bec1895fa182ca9df8
parent79b6ffd37b153558a8ef9172137842041439cb9f (diff)
Add API authentication
JIRA: COPPER-4 Change-Id: I9f54133037bd74f53640282f63e6294ccacab3aa Signed-off-by: blsaws <bryan.sullivan@att.com>
-rwxr-xr-xcomponents/congress/test-webapp/setup/clean_congress_testserver.sh1
-rw-r--r--components/congress/test-webapp/setup/install_congress_testserver.sh4
-rw-r--r--components/congress/test-webapp/www/proxy/index.php20
3 files changed, 24 insertions, 1 deletions
diff --git a/components/congress/test-webapp/setup/clean_congress_testserver.sh b/components/congress/test-webapp/setup/clean_congress_testserver.sh
index 1d06811..e23bcbd 100755
--- a/components/congress/test-webapp/setup/clean_congress_testserver.sh
+++ b/components/congress/test-webapp/setup/clean_congress_testserver.sh
@@ -29,5 +29,6 @@ echo "Stop copper-webapp container"
sudo docker stop $CID
echo "Remove copper-webapp container"
sudo docker rm $CID
+# Use this if the server is not running
# docker rm `docker ps -aq`
set +x
diff --git a/components/congress/test-webapp/setup/install_congress_testserver.sh b/components/congress/test-webapp/setup/install_congress_testserver.sh
index 9f2aaa9..9145c98 100644
--- a/components/congress/test-webapp/setup/install_congress_testserver.sh
+++ b/components/congress/test-webapp/setup/install_congress_testserver.sh
@@ -88,8 +88,12 @@ if [ ! -d /tmp/copper/log ]; then
chmod 777 /tmp/copper/log
fi
source /tmp/copper/env.sh
+
echo "Point proxy.php to the Congress server"
sed -i -- "s/CONGRESS_HOST/$CONGRESS_HOST/g" /tmp/copper/copper/components/congress/test-webapp/www/proxy/index.php
+echo "Add parameters for API authentication"
+sed -i -- "s/OS_USERNAME/$OS_USERNAME/g" /tmp/copper/copper/components/congress/test-webapp/www/proxy/index.php
+sed -i -- "s/OS_PASSWORD/$OS_PASSWORD/g" /tmp/copper/copper/components/congress/test-webapp/www/proxy/index.php
echo "Start webapp container"
sudo docker build -t copper-webapp /tmp/copper/copper/components/congress/test-webapp/
diff --git a/components/congress/test-webapp/www/proxy/index.php b/components/congress/test-webapp/www/proxy/index.php
index 5beece5..ed0b6e7 100644
--- a/components/congress/test-webapp/www/proxy/index.php
+++ b/components/congress/test-webapp/www/proxy/index.php
@@ -23,11 +23,29 @@ if ($method == 'OPTIONS') {
exit();
}
+$token = file_get_contents("/tmp/os_token");
+if ($result === false) {
+ $url = "http://KEYSTONE_HOST:5000/v2.0/tokens";
+ $curlop = curl_init();
+ curl_setopt($curlop, CURLOPT_URL, $url);
+ curl_setopt($curlop, CURLOPT_CUSTOMREQUEST, "POST");
+ curl_setopt($curlop, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($curlop, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($curlop, CURLINFO_HEADER_OUT, true);
+ curl_setopt($curlop, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
+ $body = '{"auth": {"passwordCredentials": {"username": "OS_USERNAME", "password": "OS_PASSWORD"}}}';
+ curl_setopt($curlop, CURLOPT_POSTFIELDS, $body);
+ $response = curl_exec($curlop);
+ $response = json_decode($response);
+ $token = $response->access->token->id;
+ file_put_contents("/tmp/os_token",$token);
+}
+
$url = "http://CONGRESS_HOST:1789".$_GET['~url'];
$curlop = curl_init();
curl_setopt($curlop, CURLOPT_URL, $url);
curl_setopt($curlop, CURLOPT_CUSTOMREQUEST, $method);
-//curl_setopt($curlop, CURLOPT_HEADER, 0);
+curl_setopt($curlop, CURLOPT_HEADER, array('X-Auth-Token: '.$token.''));
//curl_setopt($curlop, CURLINFO_HEADER_OUT, 0);
curl_setopt($curlop, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlop, CURLOPT_SSL_VERIFYPEER, false);