From 55b52cae6ed5b213b81833f3fe0eb0e1eeaf5e5c Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Thu, 27 Jan 2022 00:42:10 +0100 Subject: [PATCH] feat: dockerize php application --- .gitignore | 3 +- README.md | 14 +- .../grafana.env.dist | 5 - config/influxdb.env.dist | 4 + config/php.env.dist | 13 + docker-compose.yml | 28 +- php/.env.dist | 22 - php/Dockerfile | 13 + php/composer.json | 14 - php/nginx/default.conf | 16 + php/sessions/.gitkeep | 0 php/{ => src}/.gitignore | 1 - php/{App => src/app}/SessionHandler.php | 8 +- php/src/composer.json | 21 + php/{ => src}/composer.lock | 463 +----------------- php/{ => src/public}/app.php | 21 +- php/{ => src/public}/callback.php | 7 +- php/{ => src/public}/index.php | 7 +- 18 files changed, 117 insertions(+), 543 deletions(-) rename configuration.env.dist => config/grafana.env.dist (51%) create mode 100644 config/influxdb.env.dist create mode 100644 config/php.env.dist delete mode 100644 php/.env.dist create mode 100644 php/Dockerfile delete mode 100644 php/composer.json create mode 100644 php/nginx/default.conf delete mode 100644 php/sessions/.gitkeep rename php/{ => src}/.gitignore (77%) rename php/{App => src/app}/SessionHandler.php (87%) create mode 100644 php/src/composer.json rename php/{ => src}/composer.lock (62%) rename php/{ => src/public}/app.php (71%) rename php/{ => src/public}/callback.php (83%) rename php/{ => src/public}/index.php (61%) diff --git a/.gitignore b/.gitignore index 441b31d..4dd479b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ .idea .DS_Store -.env -configuration.env +*.env diff --git a/README.md b/README.md index 5f989f5..30e4a58 100644 --- a/README.md +++ b/README.md @@ -8,19 +8,15 @@ It uses a PHP Script for fetching data from the Spotify API and saves it to Infl It is advised to use a PHP website serving tool of your choice, such as [Laravel Valet]. -1. Copy ``configuration.env.dist`` to ``configuration.env`` and change the credentials -1. Copy ``php/.env.dist`` to ``php/env`` and change the credentials -2. Run ``docker-compose up -d`` to provision Grafana and InfluxDB +1. Copy ``config/*.env.dist`` to ``config/*.env`` and change the credentials +2. Run ``docker-compose up -d`` to provision Grafana, InfluxDB and PHP (via Nginx) 3. Log in to the [Spotify Developer] website -4. Set up a new Spotify App, save client id and client secret on your local machine -5. Set up static website serving by using ``cd php && valet link spotisights`` -6. (optional) Make your connection secure by executing ``valet secure`` -7. Edit your Spotify App and add the callback URL ``https://spotisights.test/callback.php`` (http when not securing the connection) +4. Set up a new Spotify App, add the callback URL ``http://localhost:8080/callback.php`` and add client id and client secret to ``php.env`` ## Data Flow -1. Call https://spotisights.test/ and follow the displayed auth flow (technical reference: [Authorization Code Flow]) -2. app.php will be called which collects recent tracks fron the logged in user, saves them to InfluxDB and prompts "done" when finished +1. Call http://localhost:8080/ and follow the displayed auth flow (technical reference: [Authorization Code Flow]) +2. app.php is called and collects recent tracks fron the authorized user, saves them to InfluxDB and prompts "done" when finished 3. Open Grafana at http://localhost:3000/ and navigate to the Dashboard "spotisights" (http://localhost:3000/?orgId=1&search=open) ## Auth diff --git a/configuration.env.dist b/config/grafana.env.dist similarity index 51% rename from configuration.env.dist rename to config/grafana.env.dist index 7da5a24..8ee091d 100644 --- a/configuration.env.dist +++ b/config/grafana.env.dist @@ -2,8 +2,3 @@ GF_SECURITY_ADMIN_USER=admin GF_SECURITY_ADMIN_PASSWORD=admin GF_INSTALL_PLUGINS= - -# InfluxDB options -INFLUXDB_DB=influx -INFLUXDB_ADMIN_USER=admin -INFLUXDB_ADMIN_PASSWORD=admin diff --git a/config/influxdb.env.dist b/config/influxdb.env.dist new file mode 100644 index 0000000..9733fd5 --- /dev/null +++ b/config/influxdb.env.dist @@ -0,0 +1,4 @@ +# InfluxDB options +INFLUXDB_DB=influx +INFLUXDB_ADMIN_USER=admin +INFLUXDB_ADMIN_PASSWORD=admin diff --git a/config/php.env.dist b/config/php.env.dist new file mode 100644 index 0000000..5ad13d8 --- /dev/null +++ b/config/php.env.dist @@ -0,0 +1,13 @@ +# InfluxDB +INFLUXDB_URL=http://influxdb:8086 +INFLUXDB_TOKEN=secrettoken +INFLUXDB_BUCKET=influx +INFLUXDB_ORG=my-org + +# Spotify +SPOTIFY_CLIENT_ID=123 +SPOTIFY_CLIENT_SECRET=123 +SPOTIFY_REDIRECT_URL=http://localhost:8080/callback.php + +# MISC +USERNAME=testuser diff --git a/docker-compose.yml b/docker-compose.yml index d0e8e70..8253780 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: influxdb: image: influxdb:1.8-alpine - env_file: configuration.env + env_file: config/influxdb.env ports: - '8086:8086' volumes: @@ -13,7 +13,7 @@ services: image: grafana/grafana:latest depends_on: - influxdb - env_file: configuration.env + env_file: config/grafana.env links: - influxdb ports: @@ -23,6 +23,30 @@ services: - ./grafana/provisioning/:/etc/grafana/provisioning/ - ./grafana/dashboards/:/var/lib/grafana/dashboards/ + php: + build: + context: ./php + depends_on: + - influxdb + links: + - influxdb + env_file: config/php.env + ports: + - '8080:80' +# - '8443:443' + volumes: + - ./php/src:/app:rw,cached + environment: + - WEB_DOCUMENT_ROOT=/app/public + - PHP_DISPLAY_ERRORS=1 + - PHP_MEMORY_LIMIT=2048M +# - PHP_MAX_EXECUTION_TIME=-1 +# - XDEBUG_MODE=debug +# - XDEBUG_START_WITH_REQUEST=yes +# - XDEBUG_CLIENT_PORT=9000 +# - XDEBUG_CLIENT_HOST=docker.local +# - XDEBUG_MAX_NESTING_LEVEL=1000 + volumes: grafana_data: { } influxdb_data: { } diff --git a/php/.env.dist b/php/.env.dist deleted file mode 100644 index 811576b..0000000 --- a/php/.env.dist +++ /dev/null @@ -1,22 +0,0 @@ -# -# InfluxDB -# - -INFLUXDB_URL=http://localhost:8086 -INFLUXDB_TOKEN=XUzCLRJ3B_IHoy4QoeqclPm2nUksXjicazMlbKlhSOtVQPNTG6BeIB-YJJD7y3hWpZjfwW-TvuETHEZZ3cvVNQ== -INFLUXDB_BUCKET=influx -INFLUXDB_ORG=my-org - -# -# Spotify -# - -SPOTIFY_CLIENT_ID=d65bcebcb5f5410683cd78c230d5dab4 -SPOTIFY_CLIENT_SECRET=1c41756848194d57939a3d9da412c2a5 -SPOTIFY_REDIRECT_URL=https://spotisights.test/callback.php - -# -# MISC -# - -USERNAME=mash1t diff --git a/php/Dockerfile b/php/Dockerfile new file mode 100644 index 0000000..eed0fcb --- /dev/null +++ b/php/Dockerfile @@ -0,0 +1,13 @@ +FROM webdevops/php-nginx-dev:8.0 + +RUN mkdir /app/sessions + +COPY ./src/composer.json /app/composer.json +COPY ./src/composer.lock /app/composer.lock + +RUN composer install -d /app + +COPY ./src/app /app/app +COPY ./src/public /app/public + +WORKDIR /app diff --git a/php/composer.json b/php/composer.json deleted file mode 100644 index f0873f7..0000000 --- a/php/composer.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "require": { - "league/statsd": "^1.5", - "ext-pcntl": "*", - "influxdata/influxdb-client-php": "^2.5", - "jwilsson/spotify-web-api-php": "^5.0", - "vlucas/phpdotenv": "^5.4" - }, - "autoload" : { - "psr-4" : { - "App\\" : "App" - } - } -} diff --git a/php/nginx/default.conf b/php/nginx/default.conf new file mode 100644 index 0000000..f85c583 --- /dev/null +++ b/php/nginx/default.conf @@ -0,0 +1,16 @@ +server { + index index.php index.html; + server_name phpfpm.local; + error_log /var/log/nginx/error.log; + access_log /var/log/nginx/access.log; + root /app/public; + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass 127.0.0.1:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } +} diff --git a/php/sessions/.gitkeep b/php/sessions/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/php/.gitignore b/php/src/.gitignore similarity index 77% rename from php/.gitignore rename to php/src/.gitignore index f812b51..4aa7116 100644 --- a/php/.gitignore +++ b/php/src/.gitignore @@ -1,3 +1,2 @@ -.env vendor/ sessions diff --git a/php/App/SessionHandler.php b/php/src/app/SessionHandler.php similarity index 87% rename from php/App/SessionHandler.php rename to php/src/app/SessionHandler.php index 45bc3f2..68922f9 100644 --- a/php/App/SessionHandler.php +++ b/php/src/app/SessionHandler.php @@ -6,14 +6,14 @@ class SessionHandler { - const BASE_FILEPATH = 'sessions'; + const BASE_FILEPATH = '..' . DIRECTORY_SEPARATOR . 'sessions'; public static function getSession(): Session { return new Session( - $_ENV['SPOTIFY_CLIENT_ID'], - $_ENV['SPOTIFY_CLIENT_SECRET'], - $_ENV['SPOTIFY_REDIRECT_URL'], + getenv('SPOTIFY_CLIENT_ID'), + getenv('SPOTIFY_CLIENT_SECRET'), + getenv('SPOTIFY_REDIRECT_URL'), ); } diff --git a/php/src/composer.json b/php/src/composer.json new file mode 100644 index 0000000..984ece7 --- /dev/null +++ b/php/src/composer.json @@ -0,0 +1,21 @@ +{ + "name": "mashb1t/spotisights", + "description": "Spotify Insights", + "autoload": { + "psr-4": { + "App\\": "app" + } + }, + "authors": [ + { + "name": "Manuel Schmid", + "email": "info@mash1t.de" + } + ], + "require": { + "league/statsd": "^1.5", + "ext-pcntl": "*", + "influxdata/influxdb-client-php": "^2.5", + "jwilsson/spotify-web-api-php": "^5.0" + } +} diff --git a/php/composer.lock b/php/src/composer.lock similarity index 62% rename from php/composer.lock rename to php/src/composer.lock index 85a6037..2fca32e 100644 --- a/php/composer.lock +++ b/php/src/composer.lock @@ -4,70 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8b790d9afd73df058c1fbe250cf22803", + "content-hash": "10e9f7dbf751d3280e94c8148e389d3c", "packages": [ - { - "name": "graham-campbell/result-type", - "version": "v1.0.4", - "source": { - "type": "git", - "url": "https://github.com/GrahamCampbell/Result-Type.git", - "reference": "0690bde05318336c7221785f2a932467f98b64ca" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/0690bde05318336c7221785f2a932467f98b64ca", - "reference": "0690bde05318336c7221785f2a932467f98b64ca", - "shasum": "" - }, - "require": { - "php": "^7.0 || ^8.0", - "phpoption/phpoption": "^1.8" - }, - "require-dev": { - "phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.19 || ^9.5.8" - }, - "type": "library", - "autoload": { - "psr-4": { - "GrahamCampbell\\ResultType\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - } - ], - "description": "An Implementation Of The Result Type", - "keywords": [ - "Graham Campbell", - "GrahamCampbell", - "Result Type", - "Result-Type", - "result" - ], - "support": { - "issues": "https://github.com/GrahamCampbell/Result-Type/issues", - "source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.0.4" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type", - "type": "tidelift" - } - ], - "time": "2021-11-21T21:41:47+00:00" - }, { "name": "guzzlehttp/guzzle", "version": "7.4.1", @@ -546,77 +484,6 @@ }, "time": "2018-10-09T16:02:46+00:00" }, - { - "name": "phpoption/phpoption", - "version": "1.8.1", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/php-option.git", - "reference": "eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15", - "reference": "eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15", - "shasum": "" - }, - "require": { - "php": "^7.0 || ^8.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.4.1", - "phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.19 || ^9.5.8" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.8-dev" - } - }, - "autoload": { - "psr-4": { - "PhpOption\\": "src/PhpOption/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com", - "homepage": "https://github.com/schmittjoh" - }, - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - } - ], - "description": "Option Type for PHP", - "keywords": [ - "language", - "option", - "php", - "type" - ], - "support": { - "issues": "https://github.com/schmittjoh/php-option/issues", - "source": "https://github.com/schmittjoh/php-option/tree/1.8.1" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption", - "type": "tidelift" - } - ], - "time": "2021-12-04T23:24:31+00:00" - }, { "name": "psr/http-client", "version": "1.0.1", @@ -887,334 +754,6 @@ } ], "time": "2021-11-01T23:48:49+00:00" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.24.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "30885182c981ab175d4d034db0f6f469898070ab" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab", - "reference": "30885182c981ab175d4d034db0f6f469898070ab", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "provide": { - "ext-ctype": "*" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.24.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-10-20T20:35:02+00:00" - }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.24.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825", - "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "provide": { - "ext-mbstring": "*" - }, - "suggest": { - "ext-mbstring": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for the Mbstring extension", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.24.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-11-30T18:21:41+00:00" - }, - { - "name": "symfony/polyfill-php80", - "version": "v1.24.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "57b712b08eddb97c762a8caa32c84e037892d2e9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/57b712b08eddb97c762a8caa32c84e037892d2e9", - "reference": "57b712b08eddb97c762a8caa32c84e037892d2e9", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, - "files": [ - "bootstrap.php" - ], - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.24.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-09-13T13:58:33+00:00" - }, - { - "name": "vlucas/phpdotenv", - "version": "v5.4.1", - "source": { - "type": "git", - "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "264dce589e7ce37a7ba99cb901eed8249fbec92f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/264dce589e7ce37a7ba99cb901eed8249fbec92f", - "reference": "264dce589e7ce37a7ba99cb901eed8249fbec92f", - "shasum": "" - }, - "require": { - "ext-pcre": "*", - "graham-campbell/result-type": "^1.0.2", - "php": "^7.1.3 || ^8.0", - "phpoption/phpoption": "^1.8", - "symfony/polyfill-ctype": "^1.23", - "symfony/polyfill-mbstring": "^1.23.1", - "symfony/polyfill-php80": "^1.23.1" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.4.1", - "ext-filter": "*", - "phpunit/phpunit": "^7.5.20 || ^8.5.21 || ^9.5.10" - }, - "suggest": { - "ext-filter": "Required to use the boolean validator." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.4-dev" - } - }, - "autoload": { - "psr-4": { - "Dotenv\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Vance Lucas", - "email": "vance@vancelucas.com", - "homepage": "https://github.com/vlucas" - } - ], - "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", - "keywords": [ - "dotenv", - "env", - "environment" - ], - "support": { - "issues": "https://github.com/vlucas/phpdotenv/issues", - "source": "https://github.com/vlucas/phpdotenv/tree/v5.4.1" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv", - "type": "tidelift" - } - ], - "time": "2021-12-12T23:22:04+00:00" } ], "packages-dev": [], diff --git a/php/app.php b/php/src/public/app.php similarity index 71% rename from php/app.php rename to php/src/public/app.php index fc47541..7858920 100644 --- a/php/app.php +++ b/php/src/public/app.php @@ -1,24 +1,21 @@ load(); - -$username = $_ENV['USERNAME']; +$username = getenv('USERNAME'); $client = new InfluxDB2\Client([ - 'url' => $_ENV['INFLUXDB_URL'], - 'token' => $_ENV['INFLUXDB_TOKEN'], - 'bucket' => $_ENV['INFLUXDB_BUCKET'], - 'org' => $_ENV['INFLUXDB_ORG'], + 'url' => getenv('INFLUXDB_URL'), + 'token' => getenv('INFLUXDB_TOKEN'), + 'bucket' => getenv('INFLUXDB_BUCKET'), + 'org' => getenv('INFLUXDB_ORG'), 'precision' => InfluxDB2\Model\WritePrecision::NS, ]); $writeApi = $client->createWriteApi(); -$session = SessionHandlerAlias::loadSession($username); +$session = SessionHandler::loadSession($username); $options = [ 'auto_refresh' => true, @@ -56,6 +53,6 @@ $writeApi->close(); -SessionHandlerAlias::saveSession($session, $username); +SessionHandler::saveSession($session, $username); echo 'done'; diff --git a/php/callback.php b/php/src/public/callback.php similarity index 83% rename from php/callback.php rename to php/src/public/callback.php index e6fef90..0979b08 100644 --- a/php/callback.php +++ b/php/src/public/callback.php @@ -1,15 +1,12 @@ load(); +require '../vendor/autoload.php'; $state = $_GET['state']; // Fetch the stored state value from somewhere. A session for example -$username = $_ENV['USERNAME']; +$username = getenv('USERNAME'); $session = \App\SessionHandler::loadSession($username); //$storedState = \App\SessionHandler::getStateFromSession($username); diff --git a/php/index.php b/php/src/public/index.php similarity index 61% rename from php/index.php rename to php/src/public/index.php index 758d9e7..ce1f6d7 100644 --- a/php/index.php +++ b/php/src/public/index.php @@ -1,9 +1,6 @@ load(); +require '../vendor/autoload.php'; $session = \App\SessionHandler::getSession(); @@ -15,7 +12,7 @@ 'state' => $state, ]; -\App\SessionHandler::saveSession($session, $_ENV['USERNAME']); +\App\SessionHandler::saveSession($session, getenv('USERNAME')); header('Location: ' . $session->getAuthorizeUrl($options)); die();