-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated for Vapor 4 and GoogleCloudKit.
- Loading branch information
1 parent
b4cfdd4
commit 49a0049
Showing
41 changed files
with
73 additions
and
2,945 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,58 @@ | ||
# GoogleCloudProvider | ||
|
||
![Swift](http://img.shields.io/badge/swift-4.1-brightgreen.svg) | ||
![Vapor](http://img.shields.io/badge/vapor-3.0-brightgreen.svg) | ||
![Swift](http://img.shields.io/badge/swift-5.1-brightgreen.svg) | ||
![Vapor](http://img.shields.io/badge/vapor-4.0-brightgreen.svg) | ||
|
||
## This project aims to bring over as many [Google Cloud Platform APIs](https://cloud.google.com/products/) as possible to Vapor projects. | ||
### GoogleCloudProvider is a Vapor wrapper around [GoogleCloudKit](https://github.com/vapor-community/GoogleCloudKit) | ||
|
||
### Because the products and API's are so vast this will start slowly and over time add more API's as time goes on. | ||
|
||
## Quickstart | ||
|
||
### Before you begin note that this package only supports using Service accounts to authenticate to the various Google Cloud Platform APIs using OAuth2. | ||
|
||
1. Select or create a Cloud Platform project. | ||
|
||
[Go to the projects page][projects] | ||
|
||
2. Enable billing for your project. | ||
|
||
[Enable billing][billing] | ||
|
||
3. Enable the Google Cloud Storage API. | ||
|
||
[Enable the API][enable_api] | ||
|
||
4. [Set up authentication with a service account][auth] so you can access the | ||
API from your local workstation. | ||
|
||
[projects]: https://console.cloud.google.com/project | ||
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing | ||
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=storage-api.googleapis.com | ||
[auth]: https://cloud.google.com/docs/authentication/getting-started | ||
|
||
### To begin using GogleCloudProvider in your project you'll need to setup the initial configuration | ||
## Installation | ||
|
||
In your `Package.swift` file, add the following | ||
|
||
```swift | ||
.package(url: "https://github.com/vapor-community/google-cloud-provider.git", from: "0.1.0") | ||
.package(url: "https://github.com/vapor-community/google-cloud-provider.git", from: "1.0.0-alpha.1") | ||
``` | ||
|
||
And In `Configure.swift` or wherever you setup your configuration in Vapor | ||
Register the credentials configuration (required) and the provider in `Configure.swift` | ||
|
||
```swift | ||
import GoogleCloud | ||
|
||
let cloudConfig = GoogleCloudProviderConfig(project: "myprojectid-12345", credentialFile: "path to your service account json") | ||
services.register(cloudConfig) | ||
try services.register(GoogleCloudProvider()) | ||
// register the credentials configuration which is used by all APIs | ||
s.register(GoogleCloudCredentialsConfiguration.self) { _ in | ||
return GoogleCloudCredentialsConfiguration(project: "myprojectid-12345", | ||
credentialsFile: "~/path/to/service-account.json") | ||
} | ||
|
||
// Register an API specific configuration. CloudStorage in this example. | ||
s.register(GoogleCloudStorageConfiguration.self) { _ in | ||
return GoogleCloudStorageConfiguration.defult() | ||
} | ||
|
||
s.provider(GoogleCloudProvider()) | ||
``` | ||
|
||
Optionally, you can register an empty `GoogleCloudProviderConfig()` and configure the following environment variables: | ||
Example usage | ||
```swift | ||
|
||
```shell | ||
export PROJECT_ID=myprojectid-12345 | ||
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/service-account.json | ||
struct UploadRequest: Content { | ||
var data: Data | ||
var filename: String | ||
} | ||
|
||
func uploadImage(_ req: Request) throws { | ||
let upload = try req.content.decode(UploadRequest.self) | ||
|
||
let storageClient = try container.make(GoogleCloudStorageClient.self) | ||
storageClient.object.createSimpleUpload(bucket: "vapor-cloud-storage-demo", | ||
data: upload.data, | ||
name: upload.filename, | ||
contentType: "image/jpeg").flatMap { uploadedObject in | ||
print(uploadedObject.mediaLink) // prints the download link for the image. | ||
} | ||
} | ||
``` | ||
|
||
Additionally, you can copy and paste the contents of your Service Account JSON file as the value for the `GOOGLE_APPLICATION_CREDENTIALS` environment variable: | ||
|
||
```shell | ||
export GOOGLE_APPLICATION_CREDENTIALS=[Valid Pasted JSON] | ||
``` | ||
### A More detailed guide can be found [here](https://github.com/vapor-community/GoogleCloudKit). | ||
|
||
### Currently the following API's are implemented and you can follow the setup guides for each specific API to integrate with your Vapor project. | ||
* [x] Cloud Storage [Setup guide](https://github.com/Andrewangeta/GoogleCloudProvider/tree/master/Sources/GoogleCloud/Storage/README.md) |
32 changes: 0 additions & 32 deletions
32
Sources/GoogleCloud/Common/Credentials/ApplicationDefault.swift
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
53 changes: 0 additions & 53 deletions
53
Sources/GoogleCloud/Common/Credentials/ServiceAccount.swift
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
Sources/GoogleCloud/Common/OAuth/OAuthApplicationDefault.swift
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.