Skip to content

Commit

Permalink
Updated for Vapor 4 and GoogleCloudKit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewangeta committed Aug 15, 2019
1 parent b4cfdd4 commit 49a0049
Show file tree
Hide file tree
Showing 41 changed files with 73 additions and 2,945 deletions.
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:4.0
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -13,15 +13,15 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/vapor/vapor.git", from: "3.0.0"),
.package(url: "https://github.com/vapor/jwt.git", from: "3.0.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-alpha"),
.package(url: "https://github.com/vapor-community/GoogleCloudKit.git", from: "1.0.0-alpha.1")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "GoogleCloud",
dependencies: ["Vapor","JWT"]),
dependencies: ["Vapor", "GoogleCloudKit"]),
.testTarget(
name: "GoogleCloudTests",
dependencies: ["GoogleCloud"]),
Expand Down
82 changes: 37 additions & 45 deletions README.md
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 Sources/GoogleCloud/Common/Credentials/ApplicationDefault.swift

This file was deleted.

85 changes: 0 additions & 85 deletions Sources/GoogleCloud/Common/Credentials/Loaders.swift

This file was deleted.

53 changes: 0 additions & 53 deletions Sources/GoogleCloud/Common/Credentials/ServiceAccount.swift

This file was deleted.

14 changes: 0 additions & 14 deletions Sources/GoogleCloud/Common/GoogleCloudAPIConfig.swift

This file was deleted.

10 changes: 0 additions & 10 deletions Sources/GoogleCloud/Common/GoogleCloudError.swift

This file was deleted.

20 changes: 0 additions & 20 deletions Sources/GoogleCloud/Common/OAuth/OAuthAccessToken.swift

This file was deleted.

43 changes: 0 additions & 43 deletions Sources/GoogleCloud/Common/OAuth/OAuthApplicationDefault.swift

This file was deleted.

Loading

0 comments on commit 49a0049

Please sign in to comment.