protected function run1($stage) { $envProps = EnvironmentProperty::find([['name' => Entity\CloudCredentialsProperty::AWS_ACCOUNT_ID]]); foreach ($envProps as $prop) { /* @var $prop EnvironmentProperty */ if (!is_numeric($prop->value)) { $prop->value = \Scalr::getContainer()->crypto->decrypt($prop->value); $prop->save(); } } }
/** * {@inheritdoc} * @see \Scalr\Modules\PlatformModuleInterface::getLocations() */ public function getLocations(\Scalr_Environment $environment = null) { if ($environment === null) { return array(); } $locations = Entity\Account\EnvironmentProperty::find([['envId' => $environment->id], ['name' => Entity\Account\EnvironmentProperty::RACKSPACE_LOCATIONS]]); $retval = []; /* @var $location Entity\Account\EnvironmentProperty */ foreach ($locations as $location) { $retval[$location->group] = "Rackspace / {$location->group}"; } return $retval; }
protected function run1($stage) { if (\Scalr::getContainer()->analytics->enabled) { $properties = EnvironmentProperty::find([['name' => Entity\CloudCredentialsProperty::AWS_DETAILED_BILLING_BUCKET]]); foreach ($properties as $property) { /* @var $property EnvironmentProperty */ $environment = \Scalr_Environment::init()->loadById($property->envId); $accountType = $environment->getPlatformConfigValue(Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE); if ($accountType == Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE_REGULAR) { $region = Aws::REGION_US_EAST_1; } else { $platformModule = PlatformFactory::NewPlatform(\SERVER_PLATFORMS::EC2); /* @var $platformModule Ec2PlatformModule */ $locations = array_keys($platformModule->getLocationsByAccountType($accountType)); $region = reset($locations); } $environment->setPlatformConfig([Entity\CloudCredentialsProperty::AWS_DETAILED_BILLING_REGION => $region]); } } }
/** * Constructor * * @param int $envId The identifier of the Client's environment * @param string $platform The name of the cloud platform * @param string $group optional The client environment property group */ public function __construct($envId, $platform, $group = null) { $this->envId = $envId; $this->platform = $platform; $this->group = $group ?: ''; $this->cloud = null; $this->firstErrorOccurredProp = $platform . '.' . static::NAME_FIRST_ERROR_OCCURRED; $this->lastErrorMessageProp = $platform . '.' . static::NAME_LAST_ERROR_MESSAGE; $this->suspendedProp = $platform . '.' . static::NAME_SUSPENDED; $properties = EnvironmentProperty::find([['envId' => $this->envId], ['group' => $this->group], ['$or' => [["name" => $this->firstErrorOccurredProp], ["name" => $this->lastErrorMessageProp], ["name" => $this->suspendedProp]]]]); foreach ($properties as $property) { if ($property->name == $this->firstErrorOccurredProp) { $this->firstErrorOccurred = $property; } elseif ($property->name == $this->lastErrorMessageProp) { $this->lastErrorMessage = $property; } else { $this->suspended = $property; } } }
private function getCloudParams($platform) { $params = []; if (in_array($platform, $this->env->getEnabledPlatforms()) || $platform == SERVER_PLATFORMS::AZURE) { $cloudCredentials = $this->env->cloudCredentials($platform); $ccProps = $cloudCredentials->properties; switch ($platform) { case SERVER_PLATFORMS::EC2: $params[SERVER_PLATFORMS::EC2 . '.is_enabled'] = true; $params[Entity\CloudCredentialsProperty::AWS_ACCOUNT_ID] = $ccProps[Entity\CloudCredentialsProperty::AWS_ACCOUNT_ID]; $params[Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE] = $ccProps[Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE]; $params[Entity\CloudCredentialsProperty::AWS_ACCESS_KEY] = $ccProps[Entity\CloudCredentialsProperty::AWS_ACCESS_KEY]; $params[Entity\CloudCredentialsProperty::AWS_SECRET_KEY] = $ccProps[Entity\CloudCredentialsProperty::AWS_SECRET_KEY] != '' ? '******' : ''; $params[Entity\CloudCredentialsProperty::AWS_PRIVATE_KEY] = $ccProps[Entity\CloudCredentialsProperty::AWS_PRIVATE_KEY] != '' ? 'Uploaded' : ''; $params[Entity\CloudCredentialsProperty::AWS_CERTIFICATE] = $ccProps[Entity\CloudCredentialsProperty::AWS_CERTIFICATE] != '' ? 'Uploaded' : ''; $params[Entity\CloudCredentialsProperty::AWS_DETAILED_BILLING_BUCKET] = $ccProps[Entity\CloudCredentialsProperty::AWS_DETAILED_BILLING_BUCKET]; $params[Entity\CloudCredentialsProperty::AWS_DETAILED_BILLING_ENABLED] = $ccProps[Entity\CloudCredentialsProperty::AWS_DETAILED_BILLING_ENABLED]; $params[Entity\CloudCredentialsProperty::AWS_DETAILED_BILLING_PAYER_ACCOUNT] = $ccProps[Entity\CloudCredentialsProperty::AWS_DETAILED_BILLING_PAYER_ACCOUNT]; $params[Entity\CloudCredentialsProperty::AWS_DETAILED_BILLING_REGION] = $ccProps[Entity\CloudCredentialsProperty::AWS_DETAILED_BILLING_REGION]; try { if ($params[Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE] == Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE_CN_CLOUD) { $params['arn'] = $this->env->aws('cn-north-1')->getUserArn(); } elseif ($params[Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE] == Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE_GOV_CLOUD) { $params['arn'] = $this->env->aws('us-gov-west-1')->getUserArn(); } else { $params['arn'] = $this->env->aws('us-east-1')->getUserArn(); } //$params['username'] = $this->env->aws('us-east-1')->getUsername(); } catch (Exception $e) { } break; case SERVER_PLATFORMS::GCE: $params[SERVER_PLATFORMS::GCE . '.is_enabled'] = true; $params[Entity\CloudCredentialsProperty::GCE_PROJECT_ID] = $ccProps[Entity\CloudCredentialsProperty::GCE_PROJECT_ID]; $jsonKey = $ccProps[Entity\CloudCredentialsProperty::GCE_JSON_KEY]; if (!empty($jsonKey)) { $params[Entity\CloudCredentialsProperty::GCE_JSON_KEY] = 'Uploaded'; } else { $params[Entity\CloudCredentialsProperty::GCE_CLIENT_ID] = $ccProps[Entity\CloudCredentialsProperty::GCE_CLIENT_ID]; $params[Entity\CloudCredentialsProperty::GCE_SERVICE_ACCOUNT_NAME] = $ccProps[Entity\CloudCredentialsProperty::GCE_SERVICE_ACCOUNT_NAME]; $params[Entity\CloudCredentialsProperty::GCE_KEY] = $ccProps[Entity\CloudCredentialsProperty::GCE_KEY] != '' ? 'Uploaded' : ''; } break; case SERVER_PLATFORMS::CLOUDSTACK: case SERVER_PLATFORMS::IDCF: $params = $this->getCloudStackDetails($platform); break; case SERVER_PLATFORMS::OPENSTACK: case SERVER_PLATFORMS::RACKSPACENG_UK: case SERVER_PLATFORMS::RACKSPACENG_US: case SERVER_PLATFORMS::OCS: case SERVER_PLATFORMS::NEBULA: case SERVER_PLATFORMS::MIRANTIS: case SERVER_PLATFORMS::VIO: case SERVER_PLATFORMS::VERIZON: case SERVER_PLATFORMS::CISCO: case SERVER_PLATFORMS::HPCLOUD: $params = $this->getOpenStackDetails($platform); break; case SERVER_PLATFORMS::RACKSPACE: $params[SERVER_PLATFORMS::RACKSPACE . '.is_enabled'] = true; /* @var $locations Entity\Account\EnvironmentProperty[] */ $locations = Entity\Account\EnvironmentProperty::find([['envId' => $this->env->id], ['name' => Entity\Account\EnvironmentProperty::RACKSPACE_LOCATIONS]]); foreach ($locations as $location) { $ccProps = $this->env->cloudCredentials("{$location->group}.{$platform}")->properties; $params[$location->group] = [Entity\CloudCredentialsProperty::RACKSPACE_USERNAME => $ccProps[Entity\CloudCredentialsProperty::RACKSPACE_USERNAME], Entity\CloudCredentialsProperty::RACKSPACE_API_KEY => $ccProps[Entity\CloudCredentialsProperty::RACKSPACE_API_KEY], Entity\CloudCredentialsProperty::RACKSPACE_IS_MANAGED => $ccProps[Entity\CloudCredentialsProperty::RACKSPACE_IS_MANAGED]]; } break; case SERVER_PLATFORMS::AZURE: $params[SERVER_PLATFORMS::AZURE . '.is_enabled'] = $cloudCredentials->isEnabled(); $params[Entity\CloudCredentialsProperty::AZURE_TENANT_NAME] = $ccProps[Entity\CloudCredentialsProperty::AZURE_TENANT_NAME]; $params[Entity\CloudCredentialsProperty::AZURE_AUTH_STEP] = $ccProps[Entity\CloudCredentialsProperty::AZURE_AUTH_STEP] ?: 0; $params[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID] = $ccProps[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID]; $params['subscriptions'] = []; if ($params[Entity\CloudCredentialsProperty::AZURE_AUTH_STEP] > 1) { $subscriptionList = []; try { $subscriptions = $this->env->azure()->getSubscriptionsList(); foreach ($subscriptions as $subscription) { if ($subscription->state == 'Enabled') { $subscriptionList[] = ['displayName' => $subscription->displayName, 'subscriptionId' => $subscription->subscriptionId]; } } } catch (Exception $e) { if (strpos($e->getMessage(), 'Error validating credentials') !== false || strpos($e->getMessage(), 'Refresh token is expired or not exists') !== false) { $cloudCredentials->delete(); $cloudCredentials->release($this->env->getContainer()); $params[Entity\CloudCredentialsProperty::AZURE_AUTH_STEP] = 0; $params[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID] = null; } $params['errorMessage'] = $e->getMessage(); break; } if (empty($subscriptionList)) { $params['errorMessage'] = sprintf("There are no active subscriptions available for the '%s' tenant", $params[AzurePlatformModule::TENANT_NAME]); } $params['subscriptions'] = $subscriptionList; } break; } } if ($platform == SERVER_PLATFORMS::EC2) { $platformModule = PlatformFactory::NewPlatform($platform); /* @var $platformModule Ec2PlatformModule */ $params['cloudLocations'] = [Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE_REGULAR => array_keys($platformModule->getLocationsByAccountType(Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE_REGULAR)), Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE_GOV_CLOUD => array_keys($platformModule->getLocationsByAccountType(Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE_GOV_CLOUD)), Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE_CN_CLOUD => array_keys($platformModule->getLocationsByAccountType(Entity\CloudCredentialsProperty::AWS_ACCOUNT_TYPE_CN_CLOUD))]; } return $params; }