mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Preserve legacy build specification limits
This commit is contained in:
1 parent
dc50f940bf
commit
bcb0cb014f
5 files changed
+40
-4
No files matched your search
@@ -49,6 +49,7 @@ class Base extends Action
|
||||
$planKey
|
||||
);
|
||||
$allowedSpecifications = $specificationValidator->getAllowedSpecifications();
|
||||
$planKey = $specificationValidator->getPlanKey();
|
||||
|
||||
if (empty($allowedSpecifications)) {
|
||||
return $fallback;
|
||||
|
||||
@@ -25,6 +25,15 @@ class Specification extends Validator
|
||||
$this->planKey = $planKey;
|
||||
}
|
||||
|
||||
public function getPlanKey(): string
|
||||
{
|
||||
if ($this->planKey === 'buildSpecifications' && !array_key_exists('buildSpecifications', $this->plan) && array_key_exists('runtimeSpecifications', $this->plan)) {
|
||||
return 'runtimeSpecifications';
|
||||
}
|
||||
|
||||
return $this->planKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Allowed Specifications.
|
||||
*
|
||||
@@ -35,11 +44,12 @@ class Specification extends Validator
|
||||
public function getAllowedSpecifications(): array
|
||||
{
|
||||
$allowedSpecifications = [];
|
||||
$planKey = $this->getPlanKey();
|
||||
|
||||
foreach ($this->specifications as $size => $values) {
|
||||
if ((empty($this->maxCpus) || $values['cpus'] <= $this->maxCpus) && (empty($this->maxMemory) || $values['memory'] <= $this->maxMemory)) {
|
||||
if (!empty($this->plan) && array_key_exists($this->planKey, $this->plan)) {
|
||||
if (!\in_array($size, $this->plan[$this->planKey])) {
|
||||
if (!empty($this->plan) && array_key_exists($planKey, $this->plan)) {
|
||||
if (!\in_array($size, $this->plan[$planKey])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Appwrite\Platform\Modules\Functions\Http\Specifications;
|
||||
|
||||
use Appwrite\Platform\Modules\Compute\Base;
|
||||
use Appwrite\Platform\Modules\Compute\Validator\Specification;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\Method;
|
||||
use Appwrite\SDK\Response as SDKResponse;
|
||||
@@ -56,7 +57,7 @@ class XList extends Base
|
||||
public function action(string $type, Response $response, array $plan)
|
||||
{
|
||||
$allSpecs = Config::getParam('specifications', []);
|
||||
$planKey = $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications';
|
||||
$planKey = (new Specification($plan, [], 0, 0, $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'))->getPlanKey();
|
||||
|
||||
$specs = [];
|
||||
foreach ($allSpecs as $spec) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Appwrite\Platform\Modules\Sites\Http\Specifications;
|
||||
|
||||
use Appwrite\Platform\Modules\Compute\Base;
|
||||
use Appwrite\Platform\Modules\Compute\Validator\Specification;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\Method;
|
||||
use Appwrite\SDK\Response as SDKResponse;
|
||||
@@ -56,7 +57,7 @@ class XList extends Base
|
||||
public function action(string $type, Response $response, array $plan)
|
||||
{
|
||||
$allSpecs = Config::getParam('specifications', []);
|
||||
$planKey = $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications';
|
||||
$planKey = (new Specification($plan, [], 0, 0, $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'))->getPlanKey();
|
||||
|
||||
$specs = [];
|
||||
foreach ($allSpecs as $spec) {
|
||||
|
||||
@@ -96,4 +96,27 @@ final class SpecificationTest extends TestCase
|
||||
$this->assertContains(SpecificationConstants::S_1VCPU_1GB, $allowed);
|
||||
$this->assertContains(SpecificationConstants::S_2VCPU_2GB, $allowed);
|
||||
}
|
||||
|
||||
public function testGetAllowedSpecificationsWithLegacyBuildPlanLimits(): void
|
||||
{
|
||||
$plan = [
|
||||
'runtimeSpecifications' => [
|
||||
SpecificationConstants::S_05VCPU_512MB,
|
||||
SpecificationConstants::S_1VCPU_512MB,
|
||||
]
|
||||
];
|
||||
$validator = new Specification(
|
||||
plan: $plan,
|
||||
specifications: $this->specifications,
|
||||
maxCpus: 0,
|
||||
maxMemory: 0,
|
||||
planKey: 'buildSpecifications'
|
||||
);
|
||||
|
||||
$allowed = $validator->getAllowedSpecifications();
|
||||
$this->assertEquals('runtimeSpecifications', $validator->getPlanKey());
|
||||
$this->assertCount(2, $allowed);
|
||||
$this->assertContains(SpecificationConstants::S_05VCPU_512MB, $allowed);
|
||||
$this->assertContains(SpecificationConstants::S_1VCPU_512MB, $allowed);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user