feat: console service
This commit is contained in:
parent
ca186543ca
commit
3860602697
10 changed files with 212 additions and 0 deletions
|
@ -186,4 +186,17 @@ return [
|
||||||
'optional' => true,
|
'optional' => true,
|
||||||
'icon' => '/images/services/graphql.png',
|
'icon' => '/images/services/graphql.png',
|
||||||
],
|
],
|
||||||
|
'console' => [
|
||||||
|
'key' => 'console',
|
||||||
|
'name' => 'Conosle',
|
||||||
|
'subtitle' => 'The Console service allows you to interact with Console relevant informations.',
|
||||||
|
'description' => '',
|
||||||
|
'controller' => 'api/console.php',
|
||||||
|
'sdk' => true,
|
||||||
|
'docs' => true,
|
||||||
|
'docsUrl' => '',
|
||||||
|
'tests' => false,
|
||||||
|
'optional' => false,
|
||||||
|
'icon' => '',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
40
app/controllers/api/console.php
Normal file
40
app/controllers/api/console.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Appwrite\Extend\Exception;
|
||||||
|
use Appwrite\Utopia\Response;
|
||||||
|
use Utopia\App;
|
||||||
|
use Utopia\Database\Document;
|
||||||
|
|
||||||
|
App::init()
|
||||||
|
->groups(['console'])
|
||||||
|
->inject('console')
|
||||||
|
->action(function (Document $project) {
|
||||||
|
if ($project->getId() !== 'console') {
|
||||||
|
throw new Exception(Exception::GENERAL_ACCESS_FORBIDDEN);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
App::get('/v1/console/variables')
|
||||||
|
->desc('Get Variables')
|
||||||
|
->groups(['api', 'projects'])
|
||||||
|
->label('scope', 'projects.read')
|
||||||
|
->label('sdk.auth', [APP_AUTH_TYPE_KEY])
|
||||||
|
->label('sdk.namespace', 'console')
|
||||||
|
->label('sdk.method', 'variables')
|
||||||
|
->label('sdk.description', '/docs/references/console/variables.md')
|
||||||
|
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||||
|
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||||
|
->label('sdk.response.model', Response::MODEL_CONSOLE_VARIABLES)
|
||||||
|
->inject('response')
|
||||||
|
->action(function (Response $response) {
|
||||||
|
|
||||||
|
$variables = new Document([
|
||||||
|
'_APP_DOMAIN_TARGET' => App::getEnv('_APP_DOMAIN_TARGET'),
|
||||||
|
'_APP_STORAGE_LIMIT' => +App::getEnv('_APP_STORAGE_LIMIT'),
|
||||||
|
'_APP_FUNCTIONS_SIZE_LIMIT' => +App::getEnv('_APP_FUNCTIONS_SIZE_LIMIT'),
|
||||||
|
'_APP_USAGE_STATS' => App::getEnv('_APP_USAGE_STATS'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->dynamic($variables, Response::MODEL_CONSOLE_VARIABLES);
|
||||||
|
});
|
1
docs/references/console/variables.md
Normal file
1
docs/references/console/variables.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Get all Environment Variables that are relevant for the console.
|
|
@ -20,6 +20,7 @@
|
||||||
<directory>./tests/e2e/General</directory>
|
<directory>./tests/e2e/General</directory>
|
||||||
<directory>./tests/e2e/Scopes</directory>
|
<directory>./tests/e2e/Scopes</directory>
|
||||||
<directory>./tests/e2e/Services/Account</directory>
|
<directory>./tests/e2e/Services/Account</directory>
|
||||||
|
<directory>./tests/e2e/Services/Console</directory>
|
||||||
<directory>./tests/e2e/Services/Realtime</directory>
|
<directory>./tests/e2e/Services/Realtime</directory>
|
||||||
<directory>./tests/e2e/Services/Avatars</directory>
|
<directory>./tests/e2e/Services/Avatars</directory>
|
||||||
<directory>./tests/e2e/Services/Databases</directory>
|
<directory>./tests/e2e/Services/Databases</directory>
|
||||||
|
|
|
@ -44,6 +44,7 @@ use Appwrite\Utopia\Response\Model\Execution;
|
||||||
use Appwrite\Utopia\Response\Model\Build;
|
use Appwrite\Utopia\Response\Model\Build;
|
||||||
use Appwrite\Utopia\Response\Model\File;
|
use Appwrite\Utopia\Response\Model\File;
|
||||||
use Appwrite\Utopia\Response\Model\Bucket;
|
use Appwrite\Utopia\Response\Model\Bucket;
|
||||||
|
use Appwrite\Utopia\Response\Model\ConsoleVariables;
|
||||||
use Appwrite\Utopia\Response\Model\Func;
|
use Appwrite\Utopia\Response\Model\Func;
|
||||||
use Appwrite\Utopia\Response\Model\Index;
|
use Appwrite\Utopia\Response\Model\Index;
|
||||||
use Appwrite\Utopia\Response\Model\JWT;
|
use Appwrite\Utopia\Response\Model\JWT;
|
||||||
|
@ -213,6 +214,9 @@ class Response extends SwooleResponse
|
||||||
public const MODEL_HEALTH_TIME = 'healthTime';
|
public const MODEL_HEALTH_TIME = 'healthTime';
|
||||||
public const MODEL_HEALTH_ANTIVIRUS = 'healthAntivirus';
|
public const MODEL_HEALTH_ANTIVIRUS = 'healthAntivirus';
|
||||||
|
|
||||||
|
// Console
|
||||||
|
public const MODEL_CONSOLE_VARIABLES = 'consoleVariables';
|
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
public const MODEL_PERMISSIONS = 'permissions';
|
public const MODEL_PERMISSIONS = 'permissions';
|
||||||
public const MODEL_RULE = 'rule';
|
public const MODEL_RULE = 'rule';
|
||||||
|
@ -341,6 +345,7 @@ class Response extends SwooleResponse
|
||||||
->setModel(new UsageFunctions())
|
->setModel(new UsageFunctions())
|
||||||
->setModel(new UsageFunction())
|
->setModel(new UsageFunction())
|
||||||
->setModel(new UsageProject())
|
->setModel(new UsageProject())
|
||||||
|
->setModel(new ConsoleVariables())
|
||||||
// Verification
|
// Verification
|
||||||
// Recovery
|
// Recovery
|
||||||
// Tests (keep last)
|
// Tests (keep last)
|
||||||
|
|
58
src/Appwrite/Utopia/Response/Model/ConsoleVariables.php
Normal file
58
src/Appwrite/Utopia/Response/Model/ConsoleVariables.php
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Utopia\Response\Model;
|
||||||
|
|
||||||
|
use Appwrite\Utopia\Response;
|
||||||
|
use Appwrite\Utopia\Response\Model;
|
||||||
|
|
||||||
|
class ConsoleVariables extends Model
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this
|
||||||
|
->addRule('_APP_DOMAIN_TARGET', [
|
||||||
|
'type' => self::TYPE_STRING,
|
||||||
|
'description' => 'CNAME target for your Appwrite custom domains.',
|
||||||
|
'default' => '',
|
||||||
|
'example' => '1.3.0',
|
||||||
|
])
|
||||||
|
->addRule('_APP_STORAGE_LIMIT', [
|
||||||
|
'type' => self::TYPE_INTEGER,
|
||||||
|
'description' => 'Maximum file size allowed for file upload in bytes.',
|
||||||
|
'default' => '',
|
||||||
|
'example' => '1.3.0',
|
||||||
|
])
|
||||||
|
->addRule('_APP_FUNCTIONS_SIZE_LIMIT', [
|
||||||
|
'type' => self::TYPE_INTEGER,
|
||||||
|
'description' => 'Maximum file size allowed for deployment in bytes.',
|
||||||
|
'default' => '',
|
||||||
|
'example' => '1.3.0',
|
||||||
|
])
|
||||||
|
->addRule('_APP_USAGE_STATS', [
|
||||||
|
'type' => self::TYPE_STRING,
|
||||||
|
'description' => 'Defines if usage stats are enabled. This value is set to \'enabled\' by default, to disable the usage stats set the value to \'disabled\'.',
|
||||||
|
'default' => '',
|
||||||
|
'example' => '1.3.0',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return 'Console Variables';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Type
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getType(): string
|
||||||
|
{
|
||||||
|
return Response::MODEL_CONSOLE_VARIABLES;
|
||||||
|
}
|
||||||
|
}
|
7
tests/e2e/Services/Console/ConsoleBase.php
Normal file
7
tests/e2e/Services/Console/ConsoleBase.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\E2E\Services\Console;
|
||||||
|
|
||||||
|
trait ConsoleBase
|
||||||
|
{
|
||||||
|
}
|
33
tests/e2e/Services/Console/ConsoleConsoleClientTest.php
Normal file
33
tests/e2e/Services/Console/ConsoleConsoleClientTest.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\E2E\Services\Console;
|
||||||
|
|
||||||
|
use Tests\E2E\Client;
|
||||||
|
use Tests\E2E\Scopes\ProjectConsole;
|
||||||
|
use Tests\E2E\Scopes\Scope;
|
||||||
|
use Tests\E2E\Scopes\SideClient;
|
||||||
|
|
||||||
|
class ConsoleConsoleClientTest extends Scope
|
||||||
|
{
|
||||||
|
use ConsoleBase;
|
||||||
|
use ProjectConsole;
|
||||||
|
use SideClient;
|
||||||
|
|
||||||
|
public function testGetVariables(): void
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test for SUCCESS
|
||||||
|
*/
|
||||||
|
$response = $this->client->call(Client::METHOD_GET, '/console/variables', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), []);
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
|
$this->assertCount(4, $response['body']);
|
||||||
|
$this->assertIsString($response['body']['_APP_DOMAIN_TARGET']);
|
||||||
|
$this->assertIsInt($response['body']['_APP_STORAGE_LIMIT']);
|
||||||
|
$this->assertIsInt($response['body']['_APP_FUNCTIONS_SIZE_LIMIT']);
|
||||||
|
$this->assertIsString($response['body']['_APP_DOMAIN_TARGET']);
|
||||||
|
}
|
||||||
|
}
|
27
tests/e2e/Services/Console/ConsoleCustomClientTest.php
Normal file
27
tests/e2e/Services/Console/ConsoleCustomClientTest.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\E2E\Services\Console;
|
||||||
|
|
||||||
|
use Tests\E2E\Client;
|
||||||
|
use Tests\E2E\Scopes\ProjectCustom;
|
||||||
|
use Tests\E2E\Scopes\Scope;
|
||||||
|
use Tests\E2E\Scopes\SideClient;
|
||||||
|
|
||||||
|
class ConsoleCustomClientTest extends Scope
|
||||||
|
{
|
||||||
|
use ProjectCustom;
|
||||||
|
use SideClient;
|
||||||
|
|
||||||
|
public function testGetVariables(): void
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test for FAILURE
|
||||||
|
*/
|
||||||
|
$response = $this->client->call(Client::METHOD_GET, '/console/variables', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), []);
|
||||||
|
|
||||||
|
$this->assertEquals(401, $response['headers']['status-code']);
|
||||||
|
}
|
||||||
|
}
|
27
tests/e2e/Services/Console/ConsoleCustomServerTest.php
Normal file
27
tests/e2e/Services/Console/ConsoleCustomServerTest.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\E2E\Services\Console;
|
||||||
|
|
||||||
|
use Tests\E2E\Client;
|
||||||
|
use Tests\E2E\Scopes\ProjectCustom;
|
||||||
|
use Tests\E2E\Scopes\Scope;
|
||||||
|
use Tests\E2E\Scopes\SideServer;
|
||||||
|
|
||||||
|
class ConsoleCustomServerTest extends Scope
|
||||||
|
{
|
||||||
|
use ProjectCustom;
|
||||||
|
use SideServer;
|
||||||
|
|
||||||
|
public function testGetVariables(): void
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test for FAILURE
|
||||||
|
*/
|
||||||
|
$response = $this->client->call(Client::METHOD_GET, '/console/variables', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), []);
|
||||||
|
|
||||||
|
$this->assertEquals(401, $response['headers']['status-code']);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue