diff --git a/CHANGELOG.md b/CHANGELOG.md index ae463ca..9666112 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added - Added nullable/required field modes. +- Added support for Google's ADC. ### Changed - Fix company name typo. diff --git a/README.md b/README.md index bd01481..f0bcfc8 100644 --- a/README.md +++ b/README.md @@ -10,34 +10,17 @@ Via Composer $ composer require prologuetech/big ``` -## Configuration - -By default we use the following global config options with BigQuery. - -```php -$this->options = [ - 'useLegacySql' => false, - 'useQueryCache' => false, -]; -``` - ## Setup - Publish our config file into your application: ``` bash php artisan vendor:publish --provider="Prologuetech\Big\BigServiceProvider" ``` -Set our required environment variables ```BIG_AUTH_FILE``` and ```BIG_PROJECT_ID```: - -```.env:``` -``` php -BIG_PROJECT_ID=my-project-0000000 -BIG_AUTH_FILE=/home/vagrant/app/storage/my-auth-0000.json -``` +You should have a `config/prologue-big.php` file to configure defaults. -Add our big service provider to your application providers: +### Laravel 5.4.x +Older versions of Laravel require you to add our big service provider to your application providers array in `config/app.php`: ``` php Prologuetech\Big\BigServiceProvider::class, @@ -45,8 +28,24 @@ Prologuetech\Big\BigServiceProvider::class, You now have access to a familiar laravel experience, enjoy! +## Google Authentication +The Google SDK supports Application Default Credentials (ADC) and thus this package does as well. You may leave your `auth_file` field inside of your config file `null` to use ADC. + +For more information see the [adc docs](https://cloud.google.com/docs/authentication/production#auth-cloud-implicit-php). + ## How to use +### Configuration + +By default we use the following global config options with BigQuery. + +```php +$this->options = [ + 'useLegacySql' => false, + 'useQueryCache' => false, +]; +``` + ### Tables When creating tables in BQ we automatically flip a Eloquent model schema for you. Let's cover an example of archiving data diff --git a/config/prologue-big.php b/config/prologue-big.php index 06204c2..189f51f 100644 --- a/config/prologue-big.php +++ b/config/prologue-big.php @@ -2,7 +2,7 @@ return [ 'big' => [ - 'auth_file' => env('BIG_AUTH_FILE'), + 'auth_file' => env('BIG_AUTH_FILE', null), 'project_id' => env('BIG_PROJECT_ID'), 'default_dataset' => env('BIG_DEFAULT_DATASET'), ], diff --git a/src/Big.php b/src/Big.php index e0bb337..a2c1af0 100644 --- a/src/Big.php +++ b/src/Big.php @@ -39,11 +39,18 @@ public function __construct() 'useQueryCache' => false, ]; - // Setup google service with credentials - $googleService = new ServiceBuilder([ - 'keyFilePath' => config('prologue-big.big.auth_file'), + // Build our Google config options + $config = [ 'projectId' => config('prologue-big.big.project_id'), - ]); + ]; + + // Allow Google's default application credentials if developer chooses + if (!is_null(config('prologue-big.big.auth_file'))) { + $config['keyFilePath'] = config('prologue-big.big.auth_file'); + } + + // Setup google service with credentials + $googleService = new ServiceBuilder($config); // Set a default dataset $this->defaultDataset = config('prologue-big.big.default_dataset');