mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Collapse envVariables/requiredEnvVariables into per-field variables
The two arrays were both keyed by the same semantic names and had to be
kept manually in sync -- adding a field to one but forgetting the other
(or a typo) would silently make getEnv() return empty and isConfigured()
silently treat the whole provider as unconfigured, with no error anywhere.
Each field is now self-contained: name => {required, envVariable}.
This commit is contained in:
1 parent
01064bace5
commit
534b695dad
3 files changed
+34
-36
No files matched your search
+14
-16
@@ -10,26 +10,24 @@ use Utopia\VCS\Adapter\Git\GitHub;
|
||||
return [
|
||||
'github' => [
|
||||
'adapter' => GitHub::class,
|
||||
'envVariables' => [
|
||||
'APP_NAME' => '_APP_VCS_GITHUB_APP_NAME',
|
||||
'PRIVATE_KEY' => '_APP_VCS_GITHUB_PRIVATE_KEY',
|
||||
'APP_ID' => '_APP_VCS_GITHUB_APP_ID',
|
||||
'CLIENT_ID' => '_APP_VCS_GITHUB_CLIENT_ID',
|
||||
'CLIENT_SECRET' => '_APP_VCS_GITHUB_CLIENT_SECRET',
|
||||
'WEBHOOK_SECRET' => '_APP_VCS_GITHUB_WEBHOOK_SECRET',
|
||||
'variables' => [
|
||||
'appName' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_APP_NAME'],
|
||||
'privateKey' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_PRIVATE_KEY'],
|
||||
'appId' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_APP_ID'],
|
||||
'clientId' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_CLIENT_ID'],
|
||||
'clientSecret' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_CLIENT_SECRET'],
|
||||
'webhookSecret' => ['required' => false, 'envVariable' => '_APP_VCS_GITHUB_WEBHOOK_SECRET'],
|
||||
],
|
||||
'requiredEnvVariables' => ['APP_NAME', 'PRIVATE_KEY', 'APP_ID', 'CLIENT_ID', 'CLIENT_SECRET'],
|
||||
],
|
||||
'gitea' => [
|
||||
'adapter' => Gitea::class,
|
||||
'envVariables' => [
|
||||
'ENDPOINT' => '_APP_VCS_GITEA_ENDPOINT',
|
||||
'CLIENT_ID' => '_APP_VCS_GITEA_CLIENT_ID',
|
||||
'CLIENT_SECRET' => '_APP_VCS_GITEA_CLIENT_SECRET',
|
||||
'WEBHOOK_SECRET' => '_APP_VCS_GITEA_WEBHOOK_SECRET',
|
||||
'variables' => [
|
||||
'endpoint' => ['required' => true, 'envVariable' => '_APP_VCS_GITEA_ENDPOINT'],
|
||||
'clientId' => ['required' => true, 'envVariable' => '_APP_VCS_GITEA_CLIENT_ID'],
|
||||
'clientSecret' => ['required' => true, 'envVariable' => '_APP_VCS_GITEA_CLIENT_SECRET'],
|
||||
// Unlike GitHub's legacy optional secret, Gitea webhooks must
|
||||
// always have a shared secret because Appwrite creates them directly.
|
||||
'webhookSecret' => ['required' => true, 'envVariable' => '_APP_VCS_GITEA_WEBHOOK_SECRET'],
|
||||
],
|
||||
// Unlike GitHub's legacy optional secret, Gitea webhooks must always
|
||||
// have a shared secret because Appwrite creates them directly.
|
||||
'requiredEnvVariables' => ['ENDPOINT', 'CLIENT_ID', 'CLIENT_SECRET', 'WEBHOOK_SECRET'],
|
||||
],
|
||||
];
|
||||
@@ -40,8 +40,8 @@ class Factory
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->registry[$key]['requiredEnvVariables'] ?? [] as $name) {
|
||||
if (empty($this->getEnv($key, $name))) {
|
||||
foreach ($this->registry[$key]['variables'] ?? [] as $name => $variable) {
|
||||
if (($variable['required'] ?? false) && empty($this->getEnv($key, $name))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class Factory
|
||||
|
||||
$adapter = new ($this->registry[$key]['adapter'])($this->cache);
|
||||
|
||||
$endpoint = $this->getEnv($key, 'ENDPOINT');
|
||||
$endpoint = $this->getEnv($key, 'endpoint');
|
||||
if (!empty($endpoint) && \method_exists($adapter, 'setEndpoint')) {
|
||||
$adapter->setEndpoint(\rtrim($endpoint, '/'));
|
||||
}
|
||||
@@ -80,8 +80,8 @@ class Factory
|
||||
|
||||
$adapter->initializeVariables(
|
||||
$installation->getAttribute('providerInstallationId', ''),
|
||||
$this->getEnv($provider, 'PRIVATE_KEY'),
|
||||
$this->getEnv($provider, 'APP_ID'),
|
||||
$this->getEnv($provider, 'privateKey'),
|
||||
$this->getEnv($provider, 'appId'),
|
||||
$installation->getAttribute('personalAccessToken', ''),
|
||||
$installation->getAttribute('personalRefreshToken', ''),
|
||||
);
|
||||
@@ -91,12 +91,12 @@ class Factory
|
||||
|
||||
public function getWebhookSecret(string $key): string
|
||||
{
|
||||
return $this->getEnv($key, 'WEBHOOK_SECRET');
|
||||
return $this->getEnv($key, 'webhookSecret');
|
||||
}
|
||||
|
||||
protected function getEnv(string $key, string $name): string
|
||||
{
|
||||
$variable = $this->registry[$key]['envVariables'][$name] ?? '';
|
||||
$variable = $this->registry[$key]['variables'][$name]['envVariable'] ?? '';
|
||||
|
||||
return empty($variable) ? '' : System::getEnv($variable, '');
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ final class FactoryTest extends TestCase
|
||||
|
||||
foreach ($registry as $key => $entry) {
|
||||
$this->assertTrue(\is_subclass_of($entry['adapter'], Git::class), "Adapter for '{$key}' must extend Git");
|
||||
$this->assertNotEmpty($entry['requiredEnvVariables'], "Required env variables missing for '{$key}'");
|
||||
foreach ($entry['requiredEnvVariables'] as $required) {
|
||||
$this->assertStringStartsWith('_APP_VCS_', $entry['envVariables'][$required] ?? '', "Env variable for required key '{$required}' missing or invalid for '{$key}'");
|
||||
$this->assertNotEmpty($entry['variables'], "Variables missing for '{$key}'");
|
||||
foreach ($entry['variables'] as $name => $variable) {
|
||||
$this->assertStringStartsWith('_APP_VCS_', $variable['envVariable'] ?? '', "Env variable for '{$name}' missing or invalid for '{$key}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,8 +74,9 @@ final class FactoryTest extends TestCase
|
||||
{
|
||||
$entry = [
|
||||
'adapter' => GitHub::class,
|
||||
'envVariables' => ['TOKEN' => '_APP_VCS_TEST_TOKEN'],
|
||||
'requiredEnvVariables' => ['TOKEN'],
|
||||
'variables' => [
|
||||
'token' => ['required' => true, 'envVariable' => '_APP_VCS_TEST_TOKEN'],
|
||||
],
|
||||
];
|
||||
$factory = new Factory($this->cache(), ['test' => $entry]);
|
||||
|
||||
@@ -111,15 +112,14 @@ final class FactoryTest extends TestCase
|
||||
{
|
||||
return [
|
||||
'adapter' => GitHub::class,
|
||||
'envVariables' => [
|
||||
'APP_NAME' => '_APP_VCS_GITHUB_APP_NAME',
|
||||
'PRIVATE_KEY' => '_APP_VCS_GITHUB_PRIVATE_KEY',
|
||||
'APP_ID' => '_APP_VCS_GITHUB_APP_ID',
|
||||
'CLIENT_ID' => '_APP_VCS_GITHUB_CLIENT_ID',
|
||||
'CLIENT_SECRET' => '_APP_VCS_GITHUB_CLIENT_SECRET',
|
||||
'WEBHOOK_SECRET' => '_APP_VCS_GITHUB_WEBHOOK_SECRET',
|
||||
'variables' => [
|
||||
'appName' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_APP_NAME'],
|
||||
'privateKey' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_PRIVATE_KEY'],
|
||||
'appId' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_APP_ID'],
|
||||
'clientId' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_CLIENT_ID'],
|
||||
'clientSecret' => ['required' => true, 'envVariable' => '_APP_VCS_GITHUB_CLIENT_SECRET'],
|
||||
'webhookSecret' => ['required' => false, 'envVariable' => '_APP_VCS_GITHUB_WEBHOOK_SECRET'],
|
||||
],
|
||||
'requiredEnvVariables' => ['APP_NAME', 'PRIVATE_KEY', 'APP_ID', 'CLIENT_ID', 'CLIENT_SECRET'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user