public function createAction()
{
$this->checkScopedPermissions('CLOUD_CREDENTIALS');
$object = $this->request->getJsonBody();
if (!is_object($object)) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Invalid body");
}
/* @var $adapter CloudCredentialsAdapter */
$adapter = $this->adapter($object, null, null, array_flip(static::$inheritanceMap));
//Pre validates the request object
$adapter->validateObject($object, Request::METHOD_POST);
$cloudCredentials = $adapter->toEntity($object);
$user = $this->getUser();
$cloudCredentials->id = null;
switch ($this->getScope()) {
case ScopeInterface::SCOPE_ENVIRONMENT:
$cloudCredentials->accountId = $user->accountId;
$cloudCredentials->envId = $this->getEnvironment()->id;
break;
case ScopeInterface::SCOPE_ACCOUNT:
$cloudCredentials->accountId = $user->accountId;
$cloudCredentials->envId = null;
break;
case ScopeInterface::SCOPE_SCALR:
$cloudCredentials->accountId = null;
$cloudCredentials->envId = null;
break;
}
$cloudCredentials->status = Entity\CloudCredentials::STATUS_DISABLED;
$adapter->validateEntity($cloudCredentials);
//Saves entity
$cloudCredentials->save();
//Responds with 201 Created status
$this->response->setStatus(201);
return $this->result($adapter->toData($cloudCredentials));
}