<?php

namespace Websight\GcsProvider;

use ErrorException;
use Google_Auth_AssertionCredentials;
use Google_Client;
use Google_Service_Storage;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Filesystem;
use Storage;
use Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter;

/**
 * Class CloudStorageServiceProvider
 * Configures Google Cloud Storage Access for flysystem
 *
 * @package Websight\GcsProvider
 */
class CloudStorageServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('gcs', function ($app, $config) {
            try {
                $credentials = new Google_Auth_AssertionCredentials(
                    $config['service_account'],
                    [
                        Google_Service_Storage::DEVSTORAGE_READ_WRITE
                    ],
                    file_get_contents($config['service_account_certificate']),
                    $config['service_account_certificate_password']
                );

                $client = new Google_Client();
                $client->setAssertionCredentials($credentials);

                $service = new Google_Service_Storage($client);
                $adapter = new GoogleStorageAdapter($service, $config['bucket']);

                return new Filesystem($adapter);
            } catch (ErrorException $e) {
                throw new ErrorException("GCS Flysystem adapter is not configured correctly.");
            }
        });
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        // Not needed
    }
}

<?php

namespace Websight\GcsProvider;

use ErrorException;
use Google_Auth_AssertionCredentials;
use Google_Client;
use Google_Service_Storage;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Filesystem;
use Storage;
use Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter;

/**
 * Class CloudStorageServiceProvider
 * Configures Google Cloud Storage Access for flysystem
 *
 * @package Websight\GcsProvider
 */
class CloudStorageServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('gcs', function ($app, $config) {
            try {
                $credentials = new Google_Auth_AssertionCredentials(
                    $config['service_account'],
                    [
                        Google_Service_Storage::DEVSTORAGE_FULL_CONTROL
                    ],
                    file_get_contents($config['service_account_certificate']),
                    $config['service_account_certificate_password']
                );

                $client = new Google_Client();
                $client->setAssertionCredentials($credentials);

                $service = new Google_Service_Storage($client);
                $adapter = new GoogleStorageAdapter($service, $config['bucket']);

                return new Filesystem($adapter);
            } catch (ErrorException $e) {
                throw new ErrorException("GCS Flysystem adapter is not configured correctly.");
            }
        });
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        // Not needed
    }
}

Revert "CloudStorage Adapter only needs Read-Write access scopes"
Revert "CloudStorage Adapter only needs Read-Write access scopes"

This reverts commit ea0516b5415c0ea994e127f8da74efa97f7a0beb.
