From bec62ec906dec4ed55c428175446ba4e5b055f53 Mon Sep 17 00:00:00 2001 From: drigato Date: Tue, 25 Nov 2014 16:04:08 -0500 Subject: [PATCH] SAAS-496: Create a provisioning controller with a terminate endpoint --- airtime_mvc/application/configs/ACL.php | 5 +- .../controllers/ProvisioningController.php | 58 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 airtime_mvc/application/controllers/ProvisioningController.php diff --git a/airtime_mvc/application/configs/ACL.php b/airtime_mvc/application/configs/ACL.php index ff65a9192..e0454d7d6 100644 --- a/airtime_mvc/application/configs/ACL.php +++ b/airtime_mvc/application/configs/ACL.php @@ -32,7 +32,9 @@ $ccAcl->add(new Zend_Acl_Resource('library')) ->add(new Zend_Acl_Resource('webstream')) ->add(new Zend_Acl_Resource('locale')) ->add(new Zend_Acl_Resource('upgrade')) - ->add(new Zend_Acl_Resource('billing')); + ->add(new Zend_Acl_Resource('billing')) + ->add(new Zend_Acl_Resource('provisioning')); + /** Creating permissions */ $ccAcl->allow('G', 'index') @@ -48,6 +50,7 @@ $ccAcl->allow('G', 'index') ->allow('G', 'webstream') ->allow('G', 'locale') ->allow('G', 'upgrade') + ->allow('G', 'provisioning') ->allow('H', 'preference', 'is-import-in-progress') ->allow('H', 'usersettings') ->allow('H', 'plupload') diff --git a/airtime_mvc/application/controllers/ProvisioningController.php b/airtime_mvc/application/controllers/ProvisioningController.php new file mode 100644 index 000000000..2323b151f --- /dev/null +++ b/airtime_mvc/application/controllers/ProvisioningController.php @@ -0,0 +1,58 @@ +view->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + if (!$this->verifyAPIKey()) { + return; + } + + $amazon_s3 = new Amazon_S3(); + $zend_s3 = $amazon_s3->getZendServiceAmazonS3(); + $bucket = $amazon_s3->getBucket(); + + // Get all files stored on Amazon S3 + $cloudFiles = CloudFilesQuery::create()->find(); + foreach ($cloudFiles as $cloudFile) { + $resource_id = $this->getResourceId(); + $amz_resource = utf8_encode("$bucket/$resource_id"); + $zend_s3->removeObject($amz_resource); + } + } + + private function verifyAPIKey() + { + // The API key is passed in via HTTP "basic authentication": + // http://en.wikipedia.org/wiki/Basic_access_authentication + + $CC_CONFIG = Config::getConfig(); + + // Decode the API key that was passed to us in the HTTP request. + $authHeader = $this->getRequest()->getHeader("Authorization"); + $encodedRequestApiKey = substr($authHeader, strlen("Basic ")); + $encodedStoredApiKey = base64_encode($CC_CONFIG["apiKey"][0] . ":"); + + if ($encodedRequestApiKey === $encodedStoredApiKey) + { + return true; + } + + $this->getResponse() + ->setHttpResponseCode(401) + ->appendBody("ERROR: Incorrect API key."); + + return false; + } +}