mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Add env var value detection
This commit is contained in:
@@ -966,14 +966,14 @@ App::post('/v1/vcs/github/installations/:installationId/detections')
|
||||
}
|
||||
|
||||
$wg = new WaitGroup();
|
||||
$envNames = [];
|
||||
$envs = [];
|
||||
foreach ($files as $file) {
|
||||
if (!(\str_starts_with($file, '.env'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$wg->add();
|
||||
go(function () use ($github, $owner, $repositoryName, $providerRootDirectory, $file, $wg, &$envNames) {
|
||||
go(function () use ($github, $owner, $repositoryName, $providerRootDirectory, $file, $wg, &$envs) {
|
||||
try {
|
||||
$contentResponse = $github->getRepositoryContent($owner, $repositoryName, \rtrim($providerRootDirectory, '/') . '/' . $file);
|
||||
$envFile = $contentResponse['content'] ?? '';
|
||||
@@ -982,8 +982,9 @@ App::post('/v1/vcs/github/installations/:installationId/detections')
|
||||
foreach ($envLines as $line) {
|
||||
$parts = \explode('=', $line, 2);
|
||||
$envName = \trim($parts[0] ?? '');
|
||||
$envValue = \trim($parts[1] ?? '');
|
||||
if (!empty($envName)) {
|
||||
$envNames[] = $envName;
|
||||
$envs[$envName] = $envValue;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -993,7 +994,15 @@ App::post('/v1/vcs/github/installations/:installationId/detections')
|
||||
}
|
||||
$wg->wait();
|
||||
|
||||
$output->setAttribute('variables', \array_unique($envNames));
|
||||
$variables = [];
|
||||
foreach ($envs as $key => $value) {
|
||||
$variables[] = [
|
||||
'name' => $key,
|
||||
'value' => $value,
|
||||
];
|
||||
}
|
||||
|
||||
$output->setAttribute('variables', $variables);
|
||||
|
||||
$response->dynamic($output, $type === 'framework' ? Response::MODEL_DETECTION_FRAMEWORK : Response::MODEL_DETECTION_RUNTIME);
|
||||
});
|
||||
@@ -1171,14 +1180,14 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories')
|
||||
}
|
||||
|
||||
$wg = new WaitGroup();
|
||||
$envNames = [];
|
||||
$envs = [];
|
||||
foreach ($files as $file) {
|
||||
if (!(\str_starts_with($file, '.env'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$wg->add();
|
||||
go(function () use ($github, $repo, $file, $wg, &$envNames) {
|
||||
go(function () use ($github, $repo, $file, $wg, &$envs) {
|
||||
try {
|
||||
$contentResponse = $github->getRepositoryContent($repo['organization'], $repo['name'], $file);
|
||||
$envFile = $contentResponse['content'] ?? '';
|
||||
@@ -1187,8 +1196,9 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories')
|
||||
foreach ($envLines as $line) {
|
||||
$parts = \explode('=', $line, 2);
|
||||
$envName = \trim($parts[0] ?? '');
|
||||
$envValue = \trim($parts[1] ?? '');
|
||||
if (!empty($envName)) {
|
||||
$envNames[] = $envName;
|
||||
$envs[$envName] = $envValue;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -1198,7 +1208,13 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories')
|
||||
}
|
||||
$wg->wait();
|
||||
|
||||
$repo['variables'] = \array_unique($envNames);
|
||||
$repo['variables'] = [];
|
||||
foreach ($envs as $key => $value) {
|
||||
$repo['variables'][] = [
|
||||
'name' => $key,
|
||||
'value' => $value,
|
||||
];
|
||||
}
|
||||
|
||||
return $repo;
|
||||
};
|
||||
|
||||
@@ -59,6 +59,7 @@ use Appwrite\Utopia\Response\Model\Database;
|
||||
use Appwrite\Utopia\Response\Model\Deployment;
|
||||
use Appwrite\Utopia\Response\Model\DetectionFramework;
|
||||
use Appwrite\Utopia\Response\Model\DetectionRuntime;
|
||||
use Appwrite\Utopia\Response\Model\DetectionVariable;
|
||||
use Appwrite\Utopia\Response\Model\DevKey;
|
||||
use Appwrite\Utopia\Response\Model\Document as ModelDocument;
|
||||
use Appwrite\Utopia\Response\Model\Error;
|
||||
@@ -316,6 +317,7 @@ class Response extends SwooleResponse
|
||||
public const MODEL_BRANCH = 'branch';
|
||||
public const MODEL_BRANCH_LIST = 'branchList';
|
||||
public const MODEL_DETECTION_FRAMEWORK = 'detectionFramework';
|
||||
public const MODEL_DETECTION_VARIABLE = 'detectionVariable';
|
||||
public const MODEL_DETECTION_RUNTIME = 'detectionRuntime';
|
||||
public const MODEL_VCS_CONTENT = 'vcsContent';
|
||||
public const MODEL_VCS_CONTENT_LIST = 'vcsContentList';
|
||||
@@ -563,6 +565,7 @@ class Response extends SwooleResponse
|
||||
->setModel(new ProviderRepositoryRuntime())
|
||||
->setModel(new DetectionFramework())
|
||||
->setModel(new DetectionRuntime())
|
||||
->setModel(new DetectionVariable())
|
||||
->setModel(new VcsContent())
|
||||
->setModel(new Branch())
|
||||
->setModel(new Runtime())
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
abstract class Detection extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('variables', [
|
||||
'type' => Response::MODEL_DETECTION_VARIABLE,
|
||||
'description' => 'Environment variables found in .env files',
|
||||
'required' => false,
|
||||
'default' => [],
|
||||
'example' => new \stdClass(),
|
||||
'array' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,13 @@
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class DetectionFramework extends Model
|
||||
class DetectionFramework extends Detection
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this
|
||||
->addRule('framework', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -33,13 +34,6 @@ class DetectionFramework extends Model
|
||||
'description' => 'Site Output Directory',
|
||||
'default' => '',
|
||||
'example' => 'dist',
|
||||
])
|
||||
->addRule('variables', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Environment variables found in .env files',
|
||||
'default' => [],
|
||||
'array' => true,
|
||||
'example' => ['PORT', 'NODE_ENV'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class DetectionRuntime extends Model
|
||||
class DetectionRuntime extends Detection
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this
|
||||
->addRule('runtime', [
|
||||
'type' => self::TYPE_STRING,
|
||||
@@ -27,13 +28,6 @@ class DetectionRuntime extends Model
|
||||
'description' => 'Function install and build commands',
|
||||
'default' => '',
|
||||
'example' => 'npm install && npm run build',
|
||||
])
|
||||
->addRule('variables', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Environment variables found in .env files',
|
||||
'default' => [],
|
||||
'array' => true,
|
||||
'example' => ['PORT', 'NODE_ENV'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
|
||||
class DetectionVariable extends Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this
|
||||
->addRule('name', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Name of environment variable',
|
||||
'default' => '',
|
||||
'example' => 'NODE_ENV',
|
||||
])
|
||||
->addRule('value', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'Value of environment variable',
|
||||
'default' => '',
|
||||
'example' => 'production',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return 'DetectionVariable';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return Response::MODEL_DETECTION_VARIABLE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user