Skip to content

Commit 9111c1d

Browse files
committed
use keychain value rather than env value as key for ai gen
1 parent cf1238c commit 9111c1d

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Modules/Sources/NetworkingCore/Settings/WooConstants.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ public enum WooConstants {
1515

1616
/// Slug of the free trial WooExpress plan
1717
public static let freeTrialPlanSlug = "ecommerce-trial-bundle-monthly"
18+
19+
/// Keychain Access's Key for merchant AI provider API key
20+
public static let merchantAIProviderKey = "merchantAIProviderKey"
1821
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import KeychainAccess
2+
import NetworkingCore
3+
4+
extension Keychain {
5+
/// AI key provided by the merchant
6+
///
7+
var merchantAIProviderKey: String? {
8+
get { self[WooConstants.merchantAIProviderKey] }
9+
set { self[WooConstants.merchantAIProviderKey] = newValue }
10+
}
11+
}

Modules/Sources/Yosemite/Stores/ProductStore.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Foundation
2+
import KeychainAccess
23
import Networking
4+
import NetworkingCore
35
import Storage
46

57
// MARK: - ProductStore
@@ -604,8 +606,8 @@ private extension ProductStore {
604606
completion(result)
605607
case .merchant:
606608
let result = await Result {
607-
// Temporary. This will come from the KeyChain rather than the environment
608-
let key = ProcessInfo.processInfo.environment["openai-debug-api-key"] ?? "api key not found"
609+
let keychain = Keychain(service: WooConstants.keychainServiceName)
610+
let key = keychain.merchantAIProviderKey ?? ""
609611
return try await MerchantGenerativeContentRemote(apiKey: key).identifyLanguage(siteID: siteID,
610612
string: string,
611613
feature: feature)
@@ -768,7 +770,8 @@ private extension ProductStore {
768770
completion(result)
769771
case .merchant:
770772
let result = await Result {
771-
let key = ProcessInfo.processInfo.environment["openai-debug-api-key"] ?? "api key not found"
773+
let keychain = Keychain(service: WooConstants.keychainServiceName)
774+
let key = keychain.merchantAIProviderKey ?? ""
772775
return try await MerchantGenerativeContentRemote(apiKey: key).generateAIProduct(siteID: siteID,
773776
productName: productName,
774777
keywords: keywords,

0 commit comments

Comments
 (0)