public function detachCredentialsAction($envId, $cloud)
{
if (!$this->getUser()->canManageAcl()) {
$this->checkPermissions(Acl::RESOURCE_ENV_CLOUDS_ENVIRONMENT);
}
$env = $this->getEnv($envId);
$cloudCredentials = $env->keychain($cloud);
if (empty($cloudCredentials->id)) {
throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, "Cloud '{$cloud}' not configured for this environment");
}
if (in_array($cloudCredentials->cloud, [SERVER_PLATFORMS::EC2, SERVER_PLATFORMS::GCE]) && (count(Entity\Server::find([['envId' => $envId], ['platform' => $cloudCredentials->cloud]])) || count(Entity\Image::find([['envId' => $envId], ['platform' => $cloudCredentials->cloud]])))) {
throw new ApiErrorException(409, ErrorMessage::ERR_OBJECT_IN_USE, "Cloud Credentials are used");
}
$cloudCredentials->environments[$envId]->delete();
return $this->result(null);
}