Пример #1
0
 /**
  * @param   string      $scope
  * @return  array
  * @throws Scalr_Exception_Core
  */
 private function getList($scope = '')
 {
     $criteria = [];
     switch ($this->request->getScope()) {
         case WebhookConfig::SCOPE_ENVIRONMENT:
             $criteria[] = ['$or' => [['$and' => [['accountId' => $this->user->getAccountId()], ['envId' => $this->getEnvironmentId()], ['level' => WebhookConfig::LEVEL_ENVIRONMENT]]], ['$and' => [['accountId' => $this->user->getAccountId()], ['envId' => null], ['level' => WebhookConfig::LEVEL_ACCOUNT]]], ['$and' => [['accountId' => null], ['envId' => null], ['level' => WebhookConfig::LEVEL_SCALR]]]]];
             break;
         case WebhookConfig::SCOPE_ACCOUNT:
             $criteria[] = ['$or' => [['$and' => [['accountId' => $this->user->getAccountId()], ['envId' => null], ['level' => WebhookConfig::LEVEL_ACCOUNT]]], ['$and' => [['accountId' => null], ['envId' => null], ['level' => WebhookConfig::LEVEL_SCALR]]]]];
             break;
         case WebhookConfig::SCOPE_SCALR:
             $criteria[] = ['level' => WebhookConfig::LEVEL_SCALR];
             $criteria[] = ['envId' => null];
             $criteria[] = ['accountId' => null];
             break;
     }
     $scopeLinking = [ScopeInterface::SCOPE_SCALR => WebhookConfig::LEVEL_SCALR, ScopeInterface::SCOPE_ACCOUNT => WebhookConfig::LEVEL_ACCOUNT, ScopeInterface::SCOPE_ENVIRONMENT => WebhookConfig::LEVEL_ENVIRONMENT];
     if ($scope && array_key_exists($scope, $scopeLinking)) {
         $criteria[] = ['level' => $scopeLinking[$scope]];
     }
     foreach (WebhookConfig::find($criteria) as $entity) {
         $webhook = ['webhookId' => $entity->webhookId, 'name' => $entity->name, 'scope' => $entity->getScope()];
         $endpoints = [];
         foreach ($entity->getEndpoints() as $endpoint) {
             $endpoints[] = $endpoint->endpointId;
         }
         $events = [];
         foreach ($entity->getEvents() as $event) {
             $events[] = $event->eventType;
         }
         $farms = array();
         foreach ($entity->getFarms() as $farm) {
             if ($farm->farmId) {
                 $farms[] = $farm->farmId;
             }
         }
         $webhook['postData'] = $this->request->getScope() == $entity->getScope() ? $entity->postData : '';
         $webhook['timeout'] = $entity->timeout;
         $webhook['attempts'] = $entity->attempts;
         $webhook['skipPrivateGv'] = $entity->skipPrivateGv;
         $webhook['endpoints'] = $endpoints;
         $webhook['events'] = $events;
         $webhook['farms'] = $farms;
         $list[] = $webhook;
     }
     return $list;
 }
Пример #2
0
 public function xGroupActionHandlerAction()
 {
     $this->request->defineParams(array('webhookIds' => array('type' => 'json'), 'action'));
     $processed = array();
     $errors = array();
     $webhooks = WebhookConfig::find(array(array('accountId' => $this->getEnvironment()->clientId), array('envId' => $this->getEnvironmentId()), array('webhookId' => array('$in' => $this->getParam('webhookIds')))));
     foreach ($webhooks as $webhook) {
         $processed[] = $webhook->webhookId;
         $webhook->delete();
     }
     $num = count($this->getParam('webhookIds'));
     if (count($processed) == $num) {
         $this->response->success('Webhooks successfully processed');
     } else {
         array_walk($errors, function (&$item) {
             $item = '- ' . $item;
         });
         $this->response->warning(sprintf("Successfully processed only %d from %d webhooks. \nFollowing errors occurred:\n%s", count($processed), $num, join($errors, '')));
     }
     $this->response->data(array('processed' => $processed));
 }