1
0
Fork 0
mirror of synced 2024-05-19 04:02:34 +12:00

feat: use DSN for phone provider

This commit is contained in:
Torsten Dittmann 2022-06-20 14:22:35 +02:00
parent 3c3261b7f1
commit 400f5c4b48
5 changed files with 12 additions and 30 deletions

4
.env
View file

@ -56,9 +56,7 @@ _APP_SMTP_PORT=1025
_APP_SMTP_SECURE=
_APP_SMTP_USERNAME=
_APP_SMTP_PASSWORD=
_APP_PHONE_PROVIDER=mock
_APP_PHONE_USER=
_APP_PHONE_SECRET=
_APP_PHONE_PROVIDER=phone://mock
_APP_PHONE_FROM=
_APP_STORAGE_LIMIT=30000000
_APP_STORAGE_PREVIEW_LIMIT=20000000

View file

@ -41,6 +41,7 @@ jobs:
- name: Teardown
if: always()
run: |
docker compose down -v
docker ps -aq | xargs docker rm --force
docker volume prune --force
docker network prune --force

View file

@ -402,24 +402,6 @@ return [
'question' => '',
'filter' => ''
],
[
'name' => '_APP_PHONE_USER',
'description' => '',
'introduction' => '',
'default' => '',
'required' => false,
'question' => '',
'filter' => ''
],
[
'name' => '_APP_PHONE_SECRET',
'description' => '',
'introduction' => '',
'default' => '',
'required' => false,
'question' => '',
'filter' => ''
],
[
'name' => '_APP_PHONE_FROM',
'description' => '',

View file

@ -27,6 +27,7 @@ use Appwrite\Auth\Phone\Mock;
use Appwrite\Auth\Phone\Telesign;
use Appwrite\Auth\Phone\TextMagic;
use Appwrite\Auth\Phone\Twilio;
use Appwrite\DSN\DSN;
use Appwrite\Event\Audit;
use Appwrite\Event\Database as EventDatabase;
use Appwrite\Event\Delete;
@ -969,11 +970,11 @@ App::setResource('geodb', function ($register) {
}, ['register']);
App::setResource('phone', function () {
$provider = App::getEnv('_APP_PHONE_PROVIDER');
$user = App::getEnv('_APP_PHONE_USER');
$secret = App::getEnv('_APP_PHONE_SECRET');
$dsn = new DSN(App::getEnv('_APP_PHONE_PROVIDER'));
$user = $dsn->getUser();
$secret = $dsn->getPassword();
return match ($provider) {
return match ($dsn->getHost()) {
'mock' => new Mock('', ''), // used for tests
'twilio' => new Twilio($user, $secret),
'text-magic' => new TextMagic($user, $secret),

View file

@ -5,6 +5,7 @@ use Appwrite\Auth\Phone\Mock;
use Appwrite\Auth\Phone\Telesign;
use Appwrite\Auth\Phone\TextMagic;
use Appwrite\Auth\Phone\Twilio;
use Appwrite\DSN\DSN;
use Appwrite\Resque\Worker;
use Utopia\App;
use Utopia\CLI\Console;
@ -26,12 +27,11 @@ class MessagingV1 extends Worker
public function init(): void
{
$provider = App::getEnv('_APP_PHONE_PROVIDER');
$user = App::getEnv('_APP_PHONE_USER');
$secret = App::getEnv('_APP_PHONE_SECRET');
$dsn = new DSN(App::getEnv('_APP_PHONE_PROVIDER'));
$user = $dsn->getUser();
$secret = $dsn->getPassword();
$this->from = App::getEnv('_APP_PHONE_FROM');
$this->phone = match ($provider) {
$this->phone = match ($dsn->getHost()) {
'mock' => new Mock('', ''), // used for tests
'twilio' => new Twilio($user, $secret),
'text-magic' => new TextMagic($user, $secret),