-
Notifications
You must be signed in to change notification settings - Fork 2
Feat: DB proxy #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 2 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
353a2e7
Implement DB proxy
Meldiron 2a8fb48
linter fix
Meldiron 1fb9ad2
Remove leftover
Meldiron 767361d
Add tests, address PR comments
Meldiron 496ff76
Rename endpoints, add pool
Meldiron 9a64f76
Remove memory limit
Meldiron bd8c0c2
Improve tests
Meldiron 3146380
More auth roles tests
Meldiron 02a45e6
PR review changes
Meldiron eeedcfc
PR review changes
Meldiron 2b56bf9
Remove unnessessary endpoints
Meldiron 2f54840
getDocument queries as string
fogelito c0cd587
Merge remote-tracking branch 'origin/dev' into dev
fogelito 6fa0086
json_encode queries
fogelito 0caa0a1
json_encode queries
fogelito 6fb801b
json_encode queries
fogelito 9a28cf2
Count endpoints.php
fogelito adcd7d3
Error exceptions
fogelito df736a6
No reference
fogelito 43cc75c
Build command
fogelito 9f76dee
composer.lock
fogelito 0477586
PR review changes
Meldiron 9755039
Fix failinig tests
Meldiron a8ae3a3
Changes after HTTP and Auth refactor
Meldiron c8adf31
Rename to data API
Meldiron b12bc38
Update readme
Meldiron 4ea8dc1
Rework to have 1 endpoint only
Meldiron 6aa2492
Fix CI/CD tests
Meldiron c42c4ae
Fix document convertion
Meldiron b44c0e9
Add support for Query
Meldiron a369456
WIP: Update to raw queries
Meldiron 44a8f0b
Fix timeouts and serialize params
Meldiron 8b194dc
Fix code quality
Meldiron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| UTOPIA_DATABASE_PROXY_SECRET=proxy-secret-key | ||
| UTOPIA_DATABASE_PROXY_SECRET_CONNECTIONS=default=mariadb://root:password@mariadb:3306/appwrite |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| name: "CodeQL" | ||
|
|
||
| on: [pull_request] | ||
| jobs: | ||
| lint: | ||
| name: CodeQL | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Check out the repo | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Run CodeQL | ||
| run: | | ||
| docker run --rm -v $PWD:/app composer sh -c \ | ||
| "composer install --profile --ignore-platform-reqs && composer check" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| name: "Linter" | ||
|
|
||
| on: [pull_request] | ||
| jobs: | ||
| lint: | ||
| name: Linter | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Check out the repo | ||
| uses: actions/checkout@v2 | ||
|
|
||
| - name: Run Linter | ||
| run: | | ||
| docker run --rm -v $PWD:/app composer sh -c \ | ||
| "composer install --profile --ignore-platform-reqs && composer lint" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| /vendor/ | ||
| /.idea/ | ||
| .phpunit.result.cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| tasks: | ||
| - name: open-runtimes/proxy | ||
| init: | | ||
| docker compose pull | ||
| docker compose build | ||
| composer install --ignore-platform-reqs | ||
| vscode: | ||
| extensions: | ||
| - ms-azuretools.vscode-docker | ||
| - zobo.php-intellisense |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # Install PHP libraries | ||
| FROM composer:2.0 as composer | ||
|
|
||
| WORKDIR /usr/local/src/ | ||
|
|
||
| COPY composer.lock /usr/local/src/ | ||
| COPY composer.json /usr/local/src/ | ||
|
|
||
| RUN composer install --ignore-platform-reqs --optimize-autoloader \ | ||
| --no-plugins --no-scripts --prefer-dist | ||
|
|
||
| # Prepare generic compiler | ||
| FROM php:8.0.18-cli-alpine3.15 as compile | ||
|
|
||
| ENV PHP_SWOOLE_VERSION=v4.8.10 | ||
|
Meldiron marked this conversation as resolved.
Outdated
|
||
|
|
||
| RUN \ | ||
| apk add --no-cache --virtual .deps \ | ||
| make \ | ||
| automake \ | ||
| autoconf \ | ||
| gcc \ | ||
| g++ \ | ||
| git \ | ||
| openssl-dev | ||
|
|
||
| RUN docker-php-ext-install sockets | ||
|
|
||
| # Compile Swoole | ||
| FROM compile AS swoole | ||
|
|
||
| RUN \ | ||
| git clone --depth 1 --branch $PHP_SWOOLE_VERSION https://github.com/swoole/swoole-src.git && \ | ||
| cd swoole-src && \ | ||
| phpize && \ | ||
| ./configure --enable-sockets --enable-http2 --enable-openssl && \ | ||
| make && make install && \ | ||
| cd .. | ||
|
|
||
| # Proxy | ||
| FROM php:8.0.18-cli-alpine3.15 as final | ||
|
|
||
| ARG UTOPIA_DATABASE_PROXY_VERSION | ||
| ENV UTOPIA_DATABASE_PROXY_VERSION=$UTOPIA_DATABASE_PROXY_VERSION | ||
|
|
||
| LABEL maintainer="team@appwrite.io" | ||
|
|
||
| RUN \ | ||
| apk update \ | ||
| && apk add --no-cache --virtual .deps \ | ||
| make \ | ||
| automake \ | ||
| autoconf \ | ||
| gcc \ | ||
| g++ \ | ||
| curl-dev \ | ||
| && apk add --no-cache \ | ||
| libstdc++ \ | ||
| && docker-php-ext-install sockets pdo_mysql \ | ||
|
Meldiron marked this conversation as resolved.
Outdated
|
||
| && apk del .deps \ | ||
| && rm -rf /var/cache/apk/* | ||
|
|
||
| WORKDIR /usr/local/ | ||
|
|
||
| # Source code | ||
| COPY ./app /usr/local/app | ||
|
|
||
| # Extensions and libraries | ||
| COPY --from=composer /usr/local/src/vendor /usr/local/vendor | ||
| COPY --from=swoole /usr/local/lib/php/extensions/no-debug-non-zts-20200930/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ | ||
|
|
||
| COPY ./vendor/utopia-php/database/src/Database/Adapter/MariaDB.php /usr/local/vendor/utopia-php/database/src/Database/Adapter/MariaDB.php | ||
|
|
||
| RUN echo extension=swoole.so >> /usr/local/etc/php/conf.d/swoole.ini | ||
|
|
||
| EXPOSE 80 | ||
|
|
||
| CMD [ "php", "app/http.php" ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- TODO: Convert this to real release process | ||
| docker build -t utopia-php/database-proxy:0.1.0 . | ||
|
Meldiron marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\DatabaseProxy\Validator; | ||
|
|
||
| use Utopia\Http\Validator\Assoc as FrameworkAssoc; | ||
|
|
||
| /** | ||
| * Extention of Assoc validator that allows greater length | ||
| * TODO: Add length param to original validator instead | ||
|
Meldiron marked this conversation as resolved.
Outdated
|
||
| */ | ||
| class Assoc extends FrameworkAssoc | ||
| { | ||
| /** | ||
| * Is valid | ||
| * | ||
| * Validation will pass when $value is valid assoc array. | ||
| * | ||
| * @param mixed $value | ||
| * @return bool | ||
| */ | ||
| public function isValid($value): bool | ||
| { | ||
| if (! \is_array($value)) { | ||
| return false; | ||
| } | ||
|
|
||
| $jsonString = \json_encode($value); | ||
| $jsonStringSize = \strlen($jsonString ? $jsonString : ''); | ||
|
|
||
| if ($jsonStringSize > MAX_STRING_SIZE) { | ||
| return false; | ||
| } | ||
|
|
||
| return \array_keys($value) !== \range(0, \count($value) - 1); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.