From ee0d054ee1ccd85f9e8597e9e7c67b214a23a36a Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Tue, 1 Apr 2025 16:14:05 +0100 Subject: [PATCH] Make the secrets optional. (#3966) --- .gitignore | 4 --- .swiftlint.yml | 1 + .../Sources/Application/AppSettings.swift | 11 +++++--- .../CallScreen/CallScreenViewModel.swift | 2 +- Secrets/Secrets.pkl | 18 ++++++++----- Secrets/Secrets.swift | 25 ++++++------------- ci_scripts/ci_common.sh | 4 +-- fastlane/Fastfile | 3 +-- 8 files changed, 32 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 3996cea11..b3b7e51cd 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,3 @@ build ## macOS Files .DS_Store ._* - -# This is a temporary file that is used to generate Secrets.swift -# That file doesn't need to be ignored, as it we assumed-unchanged it post-checkout. -Secrets/secrets.yml diff --git a/.swiftlint.yml b/.swiftlint.yml index c6574dc88..c2bdbd27e 100755 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -17,6 +17,7 @@ included: excluded: - "*/Sources/Generated/*" - Tools/Sources # Our command-line tools use a lot of print commands. + - Secrets line_length: warning: 250 diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index 778e13319..0e1e71dbe 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -223,8 +223,8 @@ final class AppSettings { // MARK: - Bug report - let bugReportServiceBaseURL: URL? = URL(string: Secrets.rageshakeServerURL)! // swiftlint:disable:this force_unwrapping - let bugReportSentryURL: URL? = URL(string: Secrets.sentryDSN)! // swiftlint:disable:this force_unwrapping + let bugReportServiceBaseURL: URL? = Secrets.rageshakeServerURL.map { URL(string: $0)! } // swiftlint:disable:this force_unwrapping + let bugReportSentryURL: URL? = Secrets.sentryDSN.map { URL(string: $0)! } // swiftlint:disable:this force_unwrapping /// The name allocated by the bug report server let bugReportApplicationID = "element-x-ios" /// The maximum size of the upload request. Default value is just below CloudFlare's max request size. @@ -233,12 +233,17 @@ final class AppSettings { // MARK: - Analytics /// The configuration to use for analytics. Set to `nil` to disable analytics. - let analyticsConfiguration: AnalyticsConfiguration? = AnalyticsConfiguration(host: Secrets.postHogHost, apiKey: Secrets.postHogAPIKey) + let analyticsConfiguration: AnalyticsConfiguration? = AppSettings.makeAnalyticsConfiguration() /// The URL to open with more information about analytics terms. When this is `nil` the "Learn more" link will be hidden. private(set) var analyticsTermsURL: URL? = "https://element.io/cookie-policy" /// Whether or not there the app is able ask for user consent to enable analytics or sentry reporting. var canPromptForAnalytics: Bool { analyticsConfiguration != nil || bugReportSentryURL != nil } + private static func makeAnalyticsConfiguration() -> AnalyticsConfiguration? { + guard let host = Secrets.postHogHost, let apiKey = Secrets.postHogAPIKey else { return nil } + return AnalyticsConfiguration(host: host, apiKey: apiKey) + } + /// Whether the user has opted in to send analytics. @UserPreference(key: UserDefaultsKeys.analyticsConsentState, defaultValue: AnalyticsConsentState.unknown, storageType: .userDefaults(store)) var analyticsConsentState diff --git a/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift b/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift index 2b1f82f4a..14c8af2b6 100644 --- a/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift +++ b/ElementX/Sources/Screens/CallScreen/CallScreenViewModel.swift @@ -159,7 +159,7 @@ class CallScreenViewModel: CallScreenViewModelType, CallScreenViewModelProtocol switch await widgetDriver.start(baseURL: baseURL, clientID: clientID, colorScheme: colorScheme, - rageshakeURL: Secrets.rageshakeServerURL, + rageshakeURL: appSettings.bugReportServiceBaseURL?.absoluteString, analyticsConfiguration: analyticsConfiguration) { case .success(let url): state.url = url diff --git a/Secrets/Secrets.pkl b/Secrets/Secrets.pkl index 76ed68d74..f314d01c0 100644 --- a/Secrets/Secrets.pkl +++ b/Secrets/Secrets.pkl @@ -7,11 +7,17 @@ // Analytics and Diagnostics -sentryDSN = read("env:SENTRY_DSN") -postHogHost = read("env:POSTHOG_HOST") -postHogAPIKey = read("env:POSTHOG_API_KEY") -rageshakeServerURL = read("env:RAGESHAKE_SERVER_URL") +import "package://pkg.pkl-lang.org/github.com/element-hq/pkl-tools/staticcode@1.0.0#/StaticCode.pkl" -// Maps +sentryDSN: String? = read?("env:SENTRY_DSN") +postHogHost: String? = read?("env:POSTHOG_HOST") +postHogAPIKey: String? = read?("env:POSTHOG_API_KEY") +rageshakeServerURL: String? = read?("env:RAGESHAKE_SERVER_URL") +mapLibreAPIKey: String? = read?("env:MAPLIBRE_API_KEY") -mapLibreAPIKey = read("env:MAPLIBRE_API_KEY") +output { + renderer = new StaticCode.Renderer { + language = "Swift" + objectName = "Secrets" + } +} diff --git a/Secrets/Secrets.swift b/Secrets/Secrets.swift index c414670c0..f1d802762 100644 --- a/Secrets/Secrets.swift +++ b/Secrets/Secrets.swift @@ -1,19 +1,8 @@ -// swiftlint:disable all -// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen +enum Secrets { + static let sentryDSN: String? = "https://sentry.localhost" + static let postHogHost: String? = "https://posthog.localhost" + static let postHogAPIKey: String? = "your_key" + static let rageshakeServerURL: String? = "https://rageshake.localhost" + static let mapLibreAPIKey: String? = "your_key" -import Foundation - -// swiftlint:disable superfluous_disable_command -// swiftlint:disable file_length - -// MARK: - YAML Files - -// swiftlint:disable identifier_name line_length number_separator type_body_length -internal enum Secrets { - internal static let mapLibreAPIKey: String = "your_key" - internal static let postHogAPIKey: String = "your_key" - internal static let postHogHost: String = "https://posthog.localhost" - internal static let rageshakeServerURL: String = "https://rageshake.localhost" - internal static let sentryDSN: String = "https://sentry.localhost" -} -// swiftlint:enable identifier_name line_length number_separator type_body_length +} \ No newline at end of file diff --git a/ci_scripts/ci_common.sh b/ci_scripts/ci_common.sh index 4762ab294..aa25691b3 100755 --- a/ci_scripts/ci_common.sh +++ b/ci_scripts/ci_common.sh @@ -30,14 +30,14 @@ setup_xcode_cloud_environment () { } install_xcode_cloud_brew_dependencies () { - brew update && brew install xcodegen swiftgen pkl + brew update && brew install xcodegen pkl } setup_github_actions_environment() { unset HOMEBREW_NO_INSTALL_FROM_API export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 - brew update && brew install xcodegen swiftlint swiftformat swiftgen git-lfs pkl a7ex/homebrew-formulae/xcresultparser + brew update && brew install xcodegen swiftlint swiftformat git-lfs pkl a7ex/homebrew-formulae/xcresultparser bundle config path vendor/bundle bundle install --jobs 4 --retry 3 diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 8c9f48181..1ddd7d70d 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -429,7 +429,6 @@ end lane :config_secrets do Dir.chdir "../Secrets" do - sh("pkl eval -f yaml -o secrets.yml Secrets.pkl") - sh("swiftgen run yaml -n inline-swift5 --param enumName=Secrets -o Secrets.swift secrets.yml") + sh("pkl eval -o Secrets.swift Secrets.pkl") end end