diff --git a/Modules/Sources/NetworkingCore/Settings/WooConstants.swift b/Modules/Sources/NetworkingCore/Settings/WooConstants.swift index 19023b56745..73b06c11428 100644 --- a/Modules/Sources/NetworkingCore/Settings/WooConstants.swift +++ b/Modules/Sources/NetworkingCore/Settings/WooConstants.swift @@ -15,4 +15,7 @@ public enum WooConstants { /// Slug of the free trial WooExpress plan public static let freeTrialPlanSlug = "ecommerce-trial-bundle-monthly" + + /// Keychain Access's Key for merchant AI provider API key + public static let merchantAIProviderKey = "merchantAIProviderKey" } diff --git a/Modules/Sources/Yosemite/Extensions/Keychain+Extensions.swift b/Modules/Sources/Yosemite/Extensions/Keychain+Extensions.swift new file mode 100644 index 00000000000..0da71dedb93 --- /dev/null +++ b/Modules/Sources/Yosemite/Extensions/Keychain+Extensions.swift @@ -0,0 +1,11 @@ +import KeychainAccess +import NetworkingCore + +extension Keychain { + /// AI key provided by the merchant + /// + var merchantAIProviderKey: String? { + get { self[WooConstants.merchantAIProviderKey] } + set { self[WooConstants.merchantAIProviderKey] = newValue } + } +} diff --git a/Modules/Sources/Yosemite/Stores/ProductStore.swift b/Modules/Sources/Yosemite/Stores/ProductStore.swift index bbd9715ff43..ae93fa6cffa 100644 --- a/Modules/Sources/Yosemite/Stores/ProductStore.swift +++ b/Modules/Sources/Yosemite/Stores/ProductStore.swift @@ -1,5 +1,7 @@ import Foundation +import KeychainAccess import Networking +import NetworkingCore import Storage // MARK: - ProductStore @@ -604,8 +606,8 @@ private extension ProductStore { completion(result) case .merchant: let result = await Result { - // Temporary. This will come from the KeyChain rather than the environment - let key = ProcessInfo.processInfo.environment["openai-debug-api-key"] ?? "api key not found" + let keychain = Keychain(service: WooConstants.keychainServiceName) + let key = keychain.merchantAIProviderKey ?? "" return try await MerchantGenerativeContentRemote(apiKey: key).identifyLanguage(siteID: siteID, string: string, feature: feature) @@ -768,7 +770,8 @@ private extension ProductStore { completion(result) case .merchant: let result = await Result { - let key = ProcessInfo.processInfo.environment["openai-debug-api-key"] ?? "api key not found" + let keychain = Keychain(service: WooConstants.keychainServiceName) + let key = keychain.merchantAIProviderKey ?? "" return try await MerchantGenerativeContentRemote(apiKey: key).generateAIProduct(siteID: siteID, productName: productName, keywords: keywords,