Exemplo n.º 1
0
 /**
  * @param   Entity\CloudCredentials    $entity
  * @param   Entity\CloudCredentials    $prevConfig
  *
  * @throws  ApiErrorException
  */
 public function validateEntity($entity, $prevConfig = null)
 {
     if (empty($entity->name)) {
         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Cloud credentials name cannot be empty");
     }
     $criteria = $this->controller->getScopeCriteria();
     $criteria[] = ['name' => $entity->name];
     $criteria[] = ['id' => ['$ne' => $entity->id]];
     /* @var $exists Entity\CloudCredentials */
     if ($exists = Entity\CloudCredentials::findOne($criteria)) {
         throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, "Cloud credentials named '{$entity->name}' already exists in {$exists->getScope()}");
     }
 }
Exemplo n.º 2
0
Arquivo: di.php Projeto: mheydt/scalr
 if (empty($cloud)) {
     throw new BadFunctionCallException('Cloud value must be provided!');
 }
 $envId = array_shift($arguments) ?: ($cont->environment ? $cont->environment->id : null);
 if (empty($envId)) {
     throw new BadFunctionCallException('Environment value must be provided!');
 }
 $cloudCredentials = null;
 $envCloudCredId = "env_cloud_creds.{$envId}.{$cloud}";
 /* @var $cloudCredentials Entity\CloudCredentials */
 if (!$cont->initialized($envCloudCredId)) {
     $cont->setShared($envCloudCredId, function ($cont) use($envId, $cloud, &$cloudCredentials) {
         $cloudCredentials = new Entity\CloudCredentials();
         $envCloudCredentials = new Entity\EnvironmentCloudCredentials();
         /* @var $cloudCredentials Entity\CloudCredentials */
         $cloudCredentials = Entity\CloudCredentials::findOne([\Scalr\Model\AbstractEntity::STMT_FROM => "{$cloudCredentials->table()} JOIN {$envCloudCredentials->table('cecc')} ON {$cloudCredentials->columnId()} = {$envCloudCredentials->columnCloudCredentialsId('cecc')} AND {$cloudCredentials->columnCloud()} = {$envCloudCredentials->columnCloud('cecc')}", \Scalr\Model\AbstractEntity::STMT_WHERE => "{$envCloudCredentials->columnEnvId('cecc')} = {$envCloudCredentials->qstr('envId', $envId)} AND {$envCloudCredentials->columnCloud('cecc')} = {$envCloudCredentials->qstr('cloud', $cloud)}"]);
         if (!empty($cloudCredentials)) {
             $cloudCredId = $cloudCredentials->id;
             $cloudCredentials->bindEnvironment($envId);
             return $cloudCredId;
         }
         return null;
     });
 }
 $cloudCredId = $cont->get($envCloudCredId);
 $contCloudCredId = "cloud_creds.{$cloudCredId}";
 if (!$cont->initialized($contCloudCredId)) {
     $cont->setShared($contCloudCredId, function ($cont) use($envId, $cloud, $cloudCredId, &$cloudCredentials) {
         if (!(isset($cloudCredentials) || empty($cloudCredentials = Entity\CloudCredentials::findPk($cloudCredId)))) {
             $cloudCredentials->bindEnvironment($envId);
         }