Skip to content

Commit

Permalink
Implement convenient .envServiceAccountKeyFields
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaelIsaev committed May 23, 2020
1 parent 7ace424 commit 8200019
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Sources/FCM/FCMConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ public struct FCMConfiguration {
return .init(pathToServiceAccountKey: path)
}

/// It will try to read
/// - FCM_EMAIL - client_email
/// - FCM_PROJECT_ID - project_id
/// - FCM_PRIVATE_KEY - private_key
/// credentials from environment variables
public static var envServiceAccountKeyFields: FCMConfiguration {
guard
let email = Environment.get("FCM_EMAIL"),
let projectId = Environment.get("FCM_PROJECT_ID"),
let rawPrivateKey = Environment.get("FCM_PRIVATE_KEY")
else {
fatalError("FCM envCredentials not set")
}
return .init(email: email, projectId: projectId, key: rawPrivateKey.replacingOccurrences(of: "\\n", with: "\n"))
}

// MARK: Helpers

private static func readKey(from path: String) -> String {
Expand Down

0 comments on commit 8200019

Please sign in to comment.