Google Cloud setup

This commit is contained in:
R. Eric Wheeler 2017-04-22 20:58:42 -07:00
parent 10bf90bd93
commit d84ab9412f
10 changed files with 94 additions and 23 deletions

View File

@ -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(),
];

View File

@ -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: ~

View File

@ -9,7 +9,7 @@ framework:
web_profiler:
toolbar: true
intercept_redirects: false
intercept_redirects: true
monolog:
handlers:

View File

@ -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

View File

@ -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 }
- { 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%']

View File

@ -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",

View File

@ -43,7 +43,6 @@ class DefaultController extends Controller
if (null !== $this->getUser()) {
$parameters['hide_social'] = true;
}
return $this->render('default/index.html.twig', $parameters);
}
}

View File

@ -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', [
]);
}

View File

@ -0,0 +1,51 @@
<?php
namespace Sikofitt\DoughnutWeddingBundle\Factory;
use Gaufrette\Exception\FileNotFound;
use Google\Auth\Credentials\ServiceAccountCredentials;
use Google_Service_Storage;
class GoogleCloudStorageServiceFactory {
/**
* @param string $credentialFile
* @param string $clientId
* @param string $applicationName
*
* @return \Google_Service_Storage
* @throws \ErrorException
* @throws \InvalidArgumentException
*/
public static function createGoogleCloudService(string $credentialFile, string $clientId, string $applicationName) : \Google_Service_Storage
{
if(false === file_exists($credentialFile)) {
throw new \ErrorException(sprintf('File %s does not exist.', $credentialFile));
}
if(false === is_readable($credentialFile)) {
throw new \ErrorException(sprintf('File %s is not readable. Check permissions.', $credentialFile));
}
$jsonStr = file_get_contents($credentialFile);
if( null === $credentials = json_decode($jsonStr, true)) {
throw new \ErrorException('Could not decode google json credentials');
}
$client = new \Google_Client();
$client->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);
}
}

View File

@ -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';