Skip to content

Commit 227a3d2

Browse files
initial commit
1 parent 0bfb4da commit 227a3d2

21 files changed

+218
-305
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github: :vendor_name
1+
github: spatie

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
blank_issues_enabled: false
22
contact_links:
33
- name: Ask a question
4-
url: https://github.com/vendor_slug/package_slug/discussions/new?category=q-a
4+
url: https://github.com/spatie/laravel-google-cloud-storage/discussions/new?category=q-a
55
about: Ask the community for help
66
- name: Request a feature
7-
url: https://github.com/vendor_slug/package_slug/discussions/new?category=ideas
7+
url: https://github.com/spatie/laravel-google-cloud-storage/discussions/new?category=ideas
88
about: Share ideas for new features
99
- name: Report a bug
10-
url: https://github.com/vendor_slug/package_slug/issues/new
10+
url: https://github.com/spatie/laravel-google-cloud-storage/issues/new
1111
about: Report a reproducable bug

.github/SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Security Policy
22

3-
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
3+
If you discover any security related issues, please email [email protected] instead of using the issue tracker.

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
All notable changes to `:package_name` will be documented in this file.
3+
All notable changes to `laravel-google-cloud-storage` will be documented in this file.
44

55
## 1.0.0 - 202X-XX-XX
66

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) :vendor_name <[email protected]>
3+
Copyright (c) spatie <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 100 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
# :package_description
1+
# Google Cloud Storage filesystem driver for Laravel
22

3-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/vendor_slug/package_slug.svg?style=flat-square)](https://packagist.org/packages/vendor_slug/package_slug)
4-
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/vendor_slug/package_slug/run-tests?label=tests)](https://github.com/vendor_slug/package_slug/actions?query=workflow%3Arun-tests+branch%3Amain)
5-
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/vendor_slug/package_slug/Check%20&%20fix%20styling?label=code%20style)](https://github.com/vendor_slug/package_slug/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
6-
[![Total Downloads](https://img.shields.io/packagist/dt/vendor_slug/package_slug.svg?style=flat-square)](https://packagist.org/packages/vendor_slug/package_slug)
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-google-cloud-storage.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-google-cloud-storage)
4+
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/spatie/laravel-google-cloud-storage/Tests/main?label=tests)](https://github.com/spatie/laravel-google-cloud-storage/actions?query=workflow%3Arun-tests+branch%3Amain)
5+
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/spatie/laravel-google-cloud-storage/Check%20&%20fix%20styling/main?label=code%20style)](https://github.com/spatie/laravel-google-cloud-storage/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-google-cloud-storage.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-google-cloud-storage)
77

88
---
9-
This repo can be used to scaffold a Laravel package. Follow these steps to get started:
109

11-
1. Press the "Use template" button at the top of this repo to create a new repo with the contents of this skeleton
12-
2. Run "./configure-skeleton.sh" to run a script that will replace all placeholders throughout all the files
13-
3. Remove this block of text.
14-
4. Have fun creating your package.
15-
5. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course.
16-
---
17-
18-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
10+
Google Cloud Storage filesystem driver for Laravel
1911

2012
## Support us
2113

22-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/:package_name.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/:package_name)
14+
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-google-cloud-storage.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-google-cloud-storage)
2315

2416
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
2517

@@ -30,35 +22,113 @@ We highly appreciate you sending us a postcard from your hometown, mentioning wh
3022
You can install the package via composer:
3123

3224
```bash
33-
composer require vendor_slug/package_slug
25+
composer require spatie/laravel-google-cloud-storage
3426
```
3527

36-
You can publish and run the migrations with:
28+
Next, add a new disk to your `filesystems.php` config:
3729

38-
```bash
39-
php artisan vendor:publish --provider="VendorName\Skeleton\SkeletonServiceProvider" --tag="package_slug-migrations"
40-
php artisan migrate
30+
```php
31+
'gcs' => [
32+
'driver' => 'gcs',
33+
'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
34+
'key_file_path' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json
35+
'key_file' => [], // optional: Array of data that substitutes the .json file (see below)
36+
'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket'),
37+
'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null), // optional: /default/path/to/apply/in/bucket
38+
'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null), // see: Public URLs below
39+
'visibility' => 'public', // optional: public|private
40+
'metadata' => ['cacheControl'=> 'public,max-age=86400'], // optional: default metadata
41+
],
4142
```
4243

43-
You can publish the config file with:
44-
```bash
45-
php artisan vendor:publish --provider="VendorName\Skeleton\SkeletonServiceProvider" --tag="package_slug-config"
44+
## Usage
45+
46+
```php
47+
$disk = Storage::disk('gcs');
48+
49+
$disk->put('avatars/1', $fileContents);
50+
$exists = $disk->exists('file.jpg');
51+
$time = $disk->lastModified('file1.jpg');
52+
$disk->copy('old/file1.jpg', 'new/file1.jpg');
53+
$disk->move('old/file1.jpg', 'new/file1.jpg');
54+
$url = $disk->url('folder/my_file.txt');
55+
$url = $disk->temporaryUrl('folder/my_file.txt', now()->addMinutes(30));
56+
$disk->setVisibility('folder/my_file.txt', 'public');
4657
```
4758

48-
This is the contents of the published config file:
59+
See https://laravel.com/docs/master/filesystem for full list of available functionality.
60+
61+
### Authentication
62+
63+
The Google Client uses a few methods to determine how it should authenticate with the Google API.
64+
65+
1. If you specify a path in the key `key_file` in disk config, that json credentials file will be used.
66+
2. If the `GOOGLE_APPLICATION_CREDENTIALS` env var is set, it will use that.
67+
```php
68+
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');
69+
```
70+
3. It will then try load the key file from a 'well known path':
71+
* windows: %APPDATA%/gcloud/application_default_credentials.json
72+
* others: $HOME/.config/gcloud/application_default_credentials.json
73+
74+
4. If running in **Google App Engine**, the built-in service account associated with the application will be used.
75+
5. If running in **Google Compute Engine**, the built-in service account associated with the virtual machine instance will be used.
76+
6. If you want to authenticate directly without using a json file, you can specify an array for `key_file` in disk config with this data:
77+
```php
78+
'key_file' => [
79+
'type' => env('GOOGLE_CLOUD_ACCOUNT_TYPE'),
80+
'private_key_id' => env('GOOGLE_CLOUD_PRIVATE_KEY_ID'),
81+
'private_key' => env('GOOGLE_CLOUD_PRIVATE_KEY'),
82+
'client_email' => env('GOOGLE_CLOUD_CLIENT_EMAIL'),
83+
'client_id' => env('GOOGLE_CLOUD_CLIENT_ID'),
84+
'auth_uri' => env('GOOGLE_CLOUD_AUTH_URI'),
85+
'token_uri' => env('GOOGLE_CLOUD_TOKEN_URI'),
86+
'auth_provider_x509_cert_url' => env('GOOGLE_CLOUD_AUTH_PROVIDER_CERT_URL'),
87+
'client_x509_cert_url' => env('GOOGLE_CLOUD_CLIENT_CERT_URL'),
88+
],
89+
```
90+
91+
### Public URLs
92+
93+
The adapter implements a `getUrl($path)` method which returns a public url to a file.
94+
>**Note:** Method available for Laravel 5.2 and higher. If used on 5.1, it will throw an exception.
4995

5096
```php
51-
return [
52-
];
97+
$disk = Storage::disk('gcs');
98+
$url = $disk->url('folder/my_file.txt');
99+
// http://storage.googleapis.com/bucket-name/folder/my_file.txt
53100
```
54101

55-
## Usage
102+
If you configure a `path_prefix` in your config:
103+
```php
104+
$disk = Storage::disk('gcs');
105+
$url = $disk->url('folder/my_file.txt');
106+
// http://storage.googleapis.com/bucket-name/path-prefix/folder/my_file.txt
107+
```
56108

109+
If you configure a custom `storage_api_uri` in your config:
57110
```php
58-
$skeleton = new VendorName\Skeleton();
59-
echo $skeleton->echoPhrase('Hello, Spatie!');
111+
$disk = Storage::disk('gcs');
112+
$url = $disk->url('folder/my_file.txt');
113+
// http://your-custom-domain.com/bucket-name/path-prefix/folder/my_file.txt
60114
```
61115

116+
For a custom domain (storage api uri), you will need to configure a CNAME DNS entry pointing to `storage.googleapis.com`.
117+
118+
Please see https://cloud.google.com/storage/docs/xml-api/reference-uris#cname for further instructions.
119+
120+
### Temporary / Signed URLs
121+
122+
With the latest adapter versions, you can easily generate a signed URLs for files that are not publicly visible by default.
123+
124+
```php
125+
$disk = Storage::disk('gcs');
126+
$url = $disk->temporaryUrl('folder/my_file.txt', now()->addMinutes(30));
127+
// https://storage.googleapis.com/test-bucket/folder/my_file.txt?GoogleAccessId=test-bucket%40test-gcp.iam.gserviceaccount.com&Expires=1571151576&Signature=tvxN1OS1txkWAUF0cCR3FWK%seRZXtFu42%04%YZACYL2zFQxA%uwdGEmdO1KgsHR3vBF%I9KaEzPbl4b7ic2IWUuo8Jh3IoZFqdTQec3KypjDtt%02DGwm%OO6pWDVV421Yp4z520%o5oMqGBtV8B3XmjW2PH76P3uID2QY%AlFxn23oE9PBoM2wXr8pDXhMPwZNJ0FtckSc26O8PmfVsG7Jvln%CQTU57IFyB7JnNxz5tQpc2hPTHbCGrcxVPEISvdOamW3I%83OsXr5raaYYBPcuumDnAmrK%cyS9%Ky2fL2B2shFO2cz%KRu79DBPqtnP2Zf1mJWBTwxVUCK2jxEEYcXBXtdOszIvlI6%tp2XfVwYxLNFU
128+
```
129+
130+
Please see https://cloud.google.com/storage/docs/access-control/signed-urls and https://laravel.com/docs/6.x/filesystem for more info.
131+
62132
## Testing
63133

64134
```bash
@@ -79,7 +149,7 @@ Please review [our security policy](../../security/policy) on how to report secu
79149

80150
## Credits
81151

82-
- [:author_name](https://github.com/:author_username)
152+
- [Alex Vanderbist](https://github.com/alexvanderbist)
83153
- [All Contributors](../../contributors)
84154

85155
## License

composer.json

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
{
2-
"name": "vendor_slug/package_slug",
3-
"description": ":package_description",
2+
"name": "spatie/laravel-google-cloud-storage",
3+
"description": "Google Cloud Storage filesystem driver for Laravel",
44
"keywords": [
5-
":vendor_name",
5+
"spatie",
66
"laravel",
7-
"package_slug"
7+
"laravel-google-cloud-storage"
88
],
9-
"homepage": "https://github.com/vendor_slug/package_slug",
9+
"homepage": "https://github.com/spatie/laravel-google-cloud-storage",
1010
"license": "MIT",
1111
"authors": [
1212
{
13-
"name": ":author_name",
14-
"email": "[email protected]",
13+
"name": "Alex Vanderbist",
14+
"email": "[email protected]",
1515
"role": "Developer"
1616
}
1717
],
1818
"require": {
1919
"php": "^8.0",
20-
"spatie/laravel-package-tools": "^1.4.3",
21-
"illuminate/contracts": "^8.37"
20+
"illuminate/contracts": "^8.37",
21+
"illuminate/filesystem": "^8.0",
22+
"illuminate/support": "^8.0",
23+
"league/flysystem-cached-adapter": "^1.0",
24+
"spatie/flysystem-google-cloud-storage": "^0.0.3"
2225
},
2326
"require-dev": {
2427
"brianium/paratest": "^6.2",
@@ -30,13 +33,12 @@
3033
},
3134
"autoload": {
3235
"psr-4": {
33-
"VendorName\\Skeleton\\": "src",
34-
"VendorName\\Skeleton\\Database\\Factories\\": "database/factories"
36+
"Spatie\\GoogleCloudStorage\\": "src"
3537
}
3638
},
3739
"autoload-dev": {
3840
"psr-4": {
39-
"VendorName\\Skeleton\\Tests\\": "tests"
41+
"Spatie\\GoogleCloudStorage\\Tests\\": "tests"
4042
}
4143
},
4244
"scripts": {
@@ -50,10 +52,10 @@
5052
"extra": {
5153
"laravel": {
5254
"providers": [
53-
"VendorName\\Skeleton\\SkeletonServiceProvider"
55+
"Spatie\\GoogleCloudStorage\\GoogleCloudStorageServiceProvider"
5456
],
5557
"aliases": {
56-
"Skeleton": "VendorName\\Skeleton\\SkeletonFacade"
58+
"GoogleCloudStorage": "Spatie\\GoogleCloudStorage\\GoogleCloudStorageFacade"
5759
}
5860
}
5961
},

config/skeleton.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)