Skip to content

Commit

Permalink
Merge pull request #27 from owainhunt/master
Browse files Browse the repository at this point in the history
Make Datastore base URL configurable
  • Loading branch information
Andrewangeta authored Apr 17, 2020
2 parents 9944d84 + 8ee97fb commit bc4d436
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Sources/CloudDatastore/GoogleCloudDatastoreAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ extension Application.GoogleCloudPlatform {
typealias Value = HTTPClient
}

private struct CloudDatastoreBaseKey: StorageKey {
typealias Value = String
}

public var datastore: GoogleCloudDatastoreAPI {
get {
if let existing = self.application.storage[CloudDatastoreAPIKey.self] {
Expand All @@ -46,7 +50,8 @@ extension Application.GoogleCloudPlatform {
let new = try GoogleCloudDatastoreClient(credentials: self.application.googleCloud.credentials,
config: self.configuration,
httpClient: self.http,
eventLoop: self.eventLoop)
eventLoop: self.eventLoop,
base: self.base)
return new
} catch {
fatalError("\(error.localizedDescription)")
Expand All @@ -71,6 +76,24 @@ extension Application.GoogleCloudPlatform {
}
}

public var base: String {
get {
if let base = application.storage[CloudDatastoreBaseKey.self] {
return base
} else {
return "https://datastore.googleapis.com"
}
}

set {
if application.storage[CloudDatastoreBaseKey.self] == nil {
application.storage[CloudDatastoreBaseKey.self] = newValue
} else {
fatalError("Attempting to override configuration after being set is not allowed.")
}
}
}

/// Custom `HTTPClient` that ignores unclean SSL shutdown.
public var http: HTTPClient {
if let existing = application.storage[CloudDatastoreHTTPClientKey.self] {
Expand Down

0 comments on commit bc4d436

Please sign in to comment.