/** * Gets CloudCredentials entity * * @param string $cloudCredentialsId Unique identifier of the CloudCredentials * * @return Entity\CloudCredentials * * @throws ApiErrorException */ public function getCloudCredentials($cloudCredentialsId) { /* @var $cloudCredentials Entity\CloudCredentials */ $cloudCredentials = Entity\CloudCredentials::findPk($cloudCredentialsId); if (empty($cloudCredentials)) { throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Requested Cloud Credentials either does not exist or is not owned by you."); } switch ($cloudCredentials->getScope()) { case ScopeInterface::SCOPE_SCALR: break; case ScopeInterface::SCOPE_ACCOUNT: if ($cloudCredentials->accountId != $this->getUser()->getAccountId()) { throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Requested Cloud Credentials either does not exist or is not owned by you."); } break; case ScopeInterface::SCOPE_ENVIRONMENT: if (!($this->getUser()->canManageAcl() || $this->getUser()->hasAccessToEnvironment($cloudCredentials->envId))) { throw new ApiErrorException(403, ErrorMessage::ERR_PERMISSION_VIOLATION, "Insufficient permissions"); } } return $cloudCredentials; }
/** * @param string $cloudCredentialsId * @param bool $modify * * @return Entity\CloudCredentials * @throws ApiErrorException */ public function getCloudCredentials($cloudCredentialsId, $modify = false) { $cloudCredentials = Entity\CloudCredentials::findPk($cloudCredentialsId); if (empty($cloudCredentials) || !$this->hasPermissions($cloudCredentials, $modify)) { throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Requested Cloud Credentials either does not exist or is not owned by you."); } return $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); } return $cloudCredentials ?: false; }); } if (empty($cloudCredentials = $cont->get($contCloudCredId))) { $cloudCredentials = new Entity\CloudCredentials(); $cloudCredentials->accountId = empty($cont->environment) || $cont->environment->id != $envId ? \Scalr_Environment::init()->loadById($envId)->getAccountId() : $cont->environment; $cloudCredentials->envId = $envId; $cloudCredentials->cloud = $cloud; } return $cloudCredentials; }); $container->setShared('saml.config', function ($cont) { $settings = $cont->config->get('scalr.connections.saml');