Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

API Keys read from environment variables #1075

Merged
merged 12 commits into from Nov 25, 2017
2 changes: 1 addition & 1 deletion Classes/Image Upload/ImgurClient.swift
Expand Up @@ -26,7 +26,7 @@ final class ImgurClient {
}

private static let hostpath = "https://api.imgur.com/3/"
private static let headers: HTTPHeaders = ["Authorization": "Client-ID \(Secrets.imgurClientID())"]
private static let headers: HTTPHeaders = ["Authorization": "Client-ID \(Secrets.Imgur.clientId)"]

func request(_ path: String,
method: HTTPMethod = .get,
Expand Down
4 changes: 2 additions & 2 deletions Classes/Login/GithubClient+AccessToken.swift
Expand Up @@ -21,8 +21,8 @@ extension GithubClient {
) {
let parameters = [
"code": code,
"client_id": Secrets.githubClientID(),
"client_secret": Secrets.githubClientSecret()
"client_id": Secrets.GitHub.clientId,
"client_secret": Secrets.GitHub.clientSecret
]
let headers = [
"Accept": "application/json"
Expand Down
2 changes: 1 addition & 1 deletion Classes/Login/LoginSplashViewController.swift
Expand Up @@ -9,7 +9,7 @@
import UIKit
import SafariServices

private let loginURL = URL(string: "http://github.com/login/oauth/authorize?client_id=\(Secrets.githubClientID())&scope=user+repo+notifications")!
private let loginURL = URL(string: "http://github.com/login/oauth/authorize?client_id=\(Secrets.GitHub.clientId)&scope=user+repo+notifications")!
private let callbackURLScheme = "freetime://"

final class LoginSplashViewController: UIViewController, GithubSessionListener {
Expand Down
2 changes: 1 addition & 1 deletion Classes/Settings/SettingsViewController.swift
Expand Up @@ -90,7 +90,7 @@ NewIssueTableViewControllerDelegate {
// MARK: Private API

func onReviewAccess() {
guard let url = URL(string: "https://github.com/settings/connections/applications/\(Secrets.githubClientID())")
guard let url = URL(string: "https://github.com/settings/connections/applications/\(Secrets.GitHub.clientId)")
else { fatalError("Should always create GitHub issue URL") }
// iOS 11 login uses SFAuthenticationSession which shares credentials with Safari.app
if #available(iOS 11.0, *) {
Expand Down
21 changes: 0 additions & 21 deletions Classes/Systems/Secrets.h

This file was deleted.

25 changes: 0 additions & 25 deletions Classes/Systems/Secrets.m

This file was deleted.

35 changes: 35 additions & 0 deletions Classes/Systems/Secrets.swift
@@ -0,0 +1,35 @@
//
// Secrets.swift
// Freetime
//
// Created by Sherlock, James on 23/11/2017.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//

import Foundation

enum Secrets {

enum GitHub {
static let clientId = Secrets.environmentVariable(named: "GITHUB_CLIENT_ID")
static let clientSecret = Secrets.environmentVariable(named: "GITHUB_CLIENT_SECRET")
}

enum Imgur {
static let clientId = Secrets.environmentVariable(named: "IMGUR_CLIENT_ID")
}

fileprivate static func environmentVariable(named: String) -> String {

let processInfo = ProcessInfo.processInfo

guard let value = processInfo.environment[named] else {
print("‼️ Missing Environment Variable: '\(named)'")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do #if DEBUG then fatalError() if we wanted to be super obvious when doing things locally?

return ""
}

return value

}

}
65 changes: 22 additions & 43 deletions Freetime.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Podfile.lock
Expand Up @@ -110,4 +110,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 42663ce5abae69b05b234e40c92d7f02b29efe06

COCOAPODS: 1.3.1
COCOAPODS: 1.2.1
2 changes: 1 addition & 1 deletion Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2,891 changes: 1,535 additions & 1,356 deletions Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

127 changes: 57 additions & 70 deletions Pods/Target Support Files/Pods-Freetime/Pods-Freetime-frameworks.sh

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.