From d84ab9412f53123e9bca51d55f2e3c61b0bed325 Mon Sep 17 00:00:00 2001 From: "R. Eric Wheeler" Date: Sat, 22 Apr 2017 20:58:42 -0700 Subject: [PATCH] Google Cloud setup --- app/AppKernel.php | 2 + app/config/config.yml | 30 +++++++---- app/config/config_dev.yml | 2 +- app/config/parameters.yml.dist | 1 + app/config/services.yml | 7 ++- composer.json | 3 +- .../Controller/DefaultController.php | 1 - .../Controller/ImageController.php | 6 ++- .../GoogleCloudStorageServiceFactory.php | 51 +++++++++++++++++++ web/config.php | 14 ++--- 10 files changed, 94 insertions(+), 23 deletions(-) create mode 100644 src/Sikofitt/DoughnutWeddingBundle/Factory/GoogleCloudStorageServiceFactory.php diff --git a/app/AppKernel.php b/app/AppKernel.php index b6eb9b6..cdf59b6 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -37,6 +37,8 @@ class AppKernel extends Kernel new \Snc\RedisBundle\SncRedisBundle(), new \HWI\Bundle\OAuthBundle\HWIOAuthBundle(), new \FOS\UserBundle\FOSUserBundle(), + new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(), + new Vich\UploaderBundle\VichUploaderBundle(), new Sikofitt\DoughnutWeddingBundle\SikofittDoughnutWeddingBundle(), ]; diff --git a/app/config/config.yml b/app/config/config.yml index 185d203..8ae4edd 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -10,7 +10,9 @@ imports: # http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration parameters: locale: en - + google.credentials_file: '%kernel.root_dir%/config/google-storage-key.json' + google.client_id: '100826355104373784827' + google.application_name: 'doughnut-wedding' framework: cache: app: cache.adapter.redis @@ -118,9 +120,12 @@ doctrine_cache: swiftmailer: transport: '%mailer_transport%' host: '%mailer_host%' + port: '%mailer_port%' username: '%mailer_user%' password: '%mailer_password%' spool: { type: memory } + delivery_addresses: ['eric@rewiv.com'] + sender_address: 'noreply@doughnutwedding.com' hwi_oauth: firewall_names: [secured_area] @@ -183,15 +188,20 @@ fos_user: registration: form: type: Sikofitt\DoughnutWeddingBundle\Form\RegistrationType -swiftmailer: - #disable_delivery: true - transport: null #'%mailer_transport%' - host: '%mailer_host%' - username: '%mailer_user%' - password: '%mailer_password%' - spool: { type: memory } - delivery_addresses: ['info@doughnutwedding.com'] - sender_address: 'noreply@doughnutwedding.com' +knp_gaufrette: + adapters: + gallery: + google_cloud_storage: + service_id: 'doughnutwedding.google_cloud_storage.service' + bucket_name: 'zgluzzkwodfky2m0ytbhmjhmmzqzntq2ngy3ndjmntyxmzg4' + options: + acl: 'public' + filesystems: + cloud: + adapter: gallery + alias: google_cloud +vich_uploader: + db_driver: orm sikofitt_doughnut_wedding: max_rsvps: ~ \ No newline at end of file diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml index 7f0c1a2..07b3b9b 100644 --- a/app/config/config_dev.yml +++ b/app/config/config_dev.yml @@ -9,7 +9,7 @@ framework: web_profiler: toolbar: true - intercept_redirects: false + intercept_redirects: true monolog: handlers: diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index 8b63629..f3e116d 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -14,6 +14,7 @@ parameters: mailer_host: 127.0.0.1 mailer_user: ~ mailer_password: ~ + mailer_port: ~ # A secret key that's used to generate certain security-related tokens secret: ThisTokenIsNotSoSecretChangeIt diff --git a/app/config/services.yml b/app/config/services.yml index 12ba0d1..d222c46 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -23,4 +23,9 @@ services: arguments: ['@router'] tags: - { name: kernel.event_listener, event: fos_user.registration.confirmed } - - { name: kernel.event_listener, event: fos_user.registration.completed } \ No newline at end of file + - { name: kernel.event_listener, event: fos_user.registration.completed } + doughnutwedding.google_cloud_storage.service: + class: \Google_Service_Storage + factory: ['Sikofitt\DoughnutWeddingBundle\Factory\GoogleCloudStorageServiceFactory', createGoogleCloudService] + arguments: ['%google.credentials_file%', '%google.client_id%', '%google.application_name%'] + diff --git a/composer.json b/composer.json index 8584295..c34aa4c 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,8 @@ "tedivm/stash": "^0.14.1", "tedivm/stash-bundle": "^0.6.2", "twig/extensions": "^1.4", - "twig/twig": "^1.0||^2.0" + "twig/twig": "^1.0||^2.0", + "vich/uploader-bundle": "^1.5" }, "require-dev": { "doctrine/doctrine-fixtures-bundle": "^2.3", diff --git a/src/Sikofitt/DoughnutWeddingBundle/Controller/DefaultController.php b/src/Sikofitt/DoughnutWeddingBundle/Controller/DefaultController.php index 13c84be..e533abb 100644 --- a/src/Sikofitt/DoughnutWeddingBundle/Controller/DefaultController.php +++ b/src/Sikofitt/DoughnutWeddingBundle/Controller/DefaultController.php @@ -43,7 +43,6 @@ class DefaultController extends Controller if (null !== $this->getUser()) { $parameters['hide_social'] = true; } - return $this->render('default/index.html.twig', $parameters); } } diff --git a/src/Sikofitt/DoughnutWeddingBundle/Controller/ImageController.php b/src/Sikofitt/DoughnutWeddingBundle/Controller/ImageController.php index fdca419..2a83dcd 100644 --- a/src/Sikofitt/DoughnutWeddingBundle/Controller/ImageController.php +++ b/src/Sikofitt/DoughnutWeddingBundle/Controller/ImageController.php @@ -35,8 +35,10 @@ class ImageController extends Controller */ public function indexAction() { - return $this->render('SikofittDoughnutWeddingBundle:Image:index.html.twig', [ - // ... + /** @var \Gaufrette\Filesystem $fileSystem */ + $fileSystem = $this->get('knp_gaufrette.filesystem_map')->get('cloud'); + dump($fileSystem->listKeys()); + return $this->render('SikofittDoughnutWeddingBundle:Image:index.html.twig', [ ]); } diff --git a/src/Sikofitt/DoughnutWeddingBundle/Factory/GoogleCloudStorageServiceFactory.php b/src/Sikofitt/DoughnutWeddingBundle/Factory/GoogleCloudStorageServiceFactory.php new file mode 100644 index 0000000..220a44a --- /dev/null +++ b/src/Sikofitt/DoughnutWeddingBundle/Factory/GoogleCloudStorageServiceFactory.php @@ -0,0 +1,51 @@ +setClientId($clientId); + $client->setApplicationName($applicationName); + + + $cred = ServiceAccountCredentials::makeCredentials( + Google_Service_Storage::DEVSTORAGE_FULL_CONTROL, + $credentials + ); + $token = $cred->fetchAuthToken(); + $client->setAccessToken($token); + + + + + return new \Google_Service_Storage($client); + } + +} \ No newline at end of file diff --git a/web/config.php b/web/config.php index b96786b..69df43c 100644 --- a/web/config.php +++ b/web/config.php @@ -14,13 +14,13 @@ if (!isset($_SERVER['HTTP_HOST'])) { exit('This script cannot be run from the CLI. Run it from a browser.'); } -//if (!in_array(@$_SERVER['REMOTE_ADDR'], array( -// '127.0.0.1', -// '::1', -//))) { -// header('HTTP/1.0 403 Forbidden'); -// exit('This script is only accessible from localhost.'); -//} +if (!in_array(@$_SERVER['REMOTE_ADDR'], array( + '127.0.0.1', + '::1', +))) { + header('HTTP/1.0 403 Forbidden'); + exit('This script is only accessible from localhost.'); +} require_once dirname(__FILE__).'/../var/SymfonyRequirements.php';