1
0
Fork 0
mirror of synced 2024-06-13 16:24:47 +12:00

feat: console service

This commit is contained in:
Torsten Dittmann 2023-03-31 17:14:59 +02:00
parent ca186543ca
commit 3860602697
10 changed files with 212 additions and 0 deletions

View file

@ -186,4 +186,17 @@ return [
'optional' => true,
'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' => '',
],
];

View 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);
});

View file

@ -0,0 +1 @@
Get all Environment Variables that are relevant for the console.

View file

@ -20,6 +20,7 @@
<directory>./tests/e2e/General</directory>
<directory>./tests/e2e/Scopes</directory>
<directory>./tests/e2e/Services/Account</directory>
<directory>./tests/e2e/Services/Console</directory>
<directory>./tests/e2e/Services/Realtime</directory>
<directory>./tests/e2e/Services/Avatars</directory>
<directory>./tests/e2e/Services/Databases</directory>

View file

@ -44,6 +44,7 @@ use Appwrite\Utopia\Response\Model\Execution;
use Appwrite\Utopia\Response\Model\Build;
use Appwrite\Utopia\Response\Model\File;
use Appwrite\Utopia\Response\Model\Bucket;
use Appwrite\Utopia\Response\Model\ConsoleVariables;
use Appwrite\Utopia\Response\Model\Func;
use Appwrite\Utopia\Response\Model\Index;
use Appwrite\Utopia\Response\Model\JWT;
@ -213,6 +214,9 @@ class Response extends SwooleResponse
public const MODEL_HEALTH_TIME = 'healthTime';
public const MODEL_HEALTH_ANTIVIRUS = 'healthAntivirus';
// Console
public const MODEL_CONSOLE_VARIABLES = 'consoleVariables';
// Deprecated
public const MODEL_PERMISSIONS = 'permissions';
public const MODEL_RULE = 'rule';
@ -341,6 +345,7 @@ class Response extends SwooleResponse
->setModel(new UsageFunctions())
->setModel(new UsageFunction())
->setModel(new UsageProject())
->setModel(new ConsoleVariables())
// Verification
// Recovery
// Tests (keep last)

View 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;
}
}

View file

@ -0,0 +1,7 @@
<?php
namespace Tests\E2E\Services\Console;
trait ConsoleBase
{
}

View 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']);
}
}

View 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']);
}
}

View 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']);
}
}