Skip to content
7 changes: 3 additions & 4 deletions Sources/Internal/CodableTimestamp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@
.firstMatch(in: timestampString, range: NSRange(location: 0,
length: timestampString.count)) !=
nil else {
FirebaseLogger.dataConnect
.error(
"Timestamp string format doesn't support."
)
DataConnectLogger.error(
"Timestamp string format \(timestampString) is not supported."
)
throw DataConnectError.invalidTimestampFormat
}

Expand All @@ -76,7 +75,7 @@

/** Extends Timestamp to conform to Codable. */
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
extension Timestamp: CodableTimestamp {}

Check warning on line 78 in Sources/Internal/CodableTimestamp.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, iOS, Xcode_16)

extension declares a conformance of imported type 'Timestamp' to imported protocols 'Encodable', 'Decodable'; this will not behave correctly if the owners of 'FirebaseCore' introduce this conformance in the future

Check warning on line 78 in Sources/Internal/CodableTimestamp.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, iOS, Xcode_16)

extension declares a conformance of imported type 'Timestamp' to imported protocols 'Encodable', 'Decodable'; this will not behave correctly if the owners of 'FirebaseCore' introduce this conformance in the future

Check warning on line 78 in Sources/Internal/CodableTimestamp.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, tvOS, Xcode_16)

extension declares a conformance of imported type 'Timestamp' to imported protocols 'Encodable', 'Decodable'; this will not behave correctly if the owners of 'FirebaseCore' introduce this conformance in the future

Check warning on line 78 in Sources/Internal/CodableTimestamp.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, tvOS, Xcode_16)

extension declares a conformance of imported type 'Timestamp' to imported protocols 'Encodable', 'Decodable'; this will not behave correctly if the owners of 'FirebaseCore' introduce this conformance in the future

Check warning on line 78 in Sources/Internal/CodableTimestamp.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, macOS, Xcode_16)

extension declares a conformance of imported type 'Timestamp' to imported protocols 'Encodable', 'Decodable'; this will not behave correctly if the owners of 'FirebaseCore' introduce this conformance in the future

Check warning on line 78 in Sources/Internal/CodableTimestamp.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, macOS, Xcode_16)

extension declares a conformance of imported type 'Timestamp' to imported protocols 'Encodable', 'Decodable'; this will not behave correctly if the owners of 'FirebaseCore' introduce this conformance in the future

Check warning on line 78 in Sources/Internal/CodableTimestamp.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, catalyst, Xcode_16)

extension declares a conformance of imported type 'Timestamp' to imported protocols 'Encodable', 'Decodable'; this will not behave correctly if the owners of 'FirebaseCore' introduce this conformance in the future

Check warning on line 78 in Sources/Internal/CodableTimestamp.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, catalyst, Xcode_16)

extension declares a conformance of imported type 'Timestamp' to imported protocols 'Encodable', 'Decodable'; this will not behave correctly if the owners of 'FirebaseCore' introduce this conformance in the future

class CodableTimestampHelper {
static let regex =
Expand Down
54 changes: 0 additions & 54 deletions Sources/Internal/FirebaseLogger/FirebaseLogger.swift

This file was deleted.

160 changes: 50 additions & 110 deletions Sources/Internal/GrpcClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import Foundation
@preconcurrency import FirebaseAuth
import FirebaseCore
import GRPC
import Logging
import NIOCore
import NIOHPACK
import NIOPosix
import OSLog
import SwiftProtobuf

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
Expand Down Expand Up @@ -50,9 +50,6 @@ actor GrpcClient: CustomStringConvertible {

private let callerSDKType: CallerSDKType

// Remove debug flag when logging privacy is properly handled.
private let debugEnable = false

enum RequestHeaders {
static let googRequestParamsHeader = "x-goog-request-params"
static let authorizationHeader = "x-firebase-auth-token"
Expand All @@ -65,11 +62,8 @@ actor GrpcClient: CustomStringConvertible {

private lazy var client: FirebaseDataConnectAsyncClient? = {
do {
if debugEnable == true {
FirebaseLogger.dataConnect.debug("\(self.description) initialization starts.")
} else {
FirebaseLogger.dataConnect.debug("GrpcClient initialization starts.")
}
DataConnectLogger
.debug("GrpcClient: \(self.description, privacy: .private) initialization starts.")
let group = PlatformSupport.makeEventLoopGroup(loopCount: threadPoolSize)
let channel = try GRPCChannelPool.with(
target: .host(serverSettings.host, port: serverSettings.port),
Expand All @@ -78,18 +72,12 @@ actor GrpcClient: CustomStringConvertible {
.plaintext,
eventLoopGroup: group
)
if debugEnable == true {
FirebaseLogger.dataConnect.debug("\(self.description) has been created.")
} else {
FirebaseLogger.dataConnect.debug("GrpcClient has been created.")
}
DataConnectLogger
.debug("GrpcClient: \(self.description, privacy: .private) has been created.")
return FirebaseDataConnectAsyncClient(channel: channel)
} catch {
if debugEnable == true {
FirebaseLogger.dataConnect.error("Error:\(error) when creating \(self.description).")
} else {
FirebaseLogger.dataConnect.debug("Error:\(error) when creating GrpcClient.")
}
DataConnectLogger
.debug("Error:\(error) when creating GrpcClient: \(self.description, privacy: .private).")
return nil
}
}()
Expand Down Expand Up @@ -128,7 +116,6 @@ actor GrpcClient: CustomStringConvertible {
googRequestHeaderValue = "location=\(self.connectorConfig.location)&frontend=data"

description = """
GrpcClient: \
projectId=\(projectId) \
connector=\(connectorConfig.connector) \
host=\(serverSettings.host) \
Expand All @@ -143,8 +130,7 @@ actor GrpcClient: CustomStringConvertible {
.Type)
async throws -> OperationResult<ResultType> {
guard let client else {
FirebaseLogger.dataConnect
.error("When calling executeQuery(), grpc client has not been configured.")
DataConnectLogger.error("When calling executeQuery(), grpc client has not been configured.")
throw DataConnectError.grpcNotConfigured
}

Expand All @@ -153,49 +139,28 @@ actor GrpcClient: CustomStringConvertible {
connectorName: connectorName,
request: request
)
let requestString = try grpcRequest.jsonString()

do {
if debugEnable == true {
try FirebaseLogger.dataConnect
.debug("executeQuery() sends grpc request: \(grpcRequest.jsonString()).")
} else {
try FirebaseLogger.dataConnect
.debug("executeQuery() sends grpc request.")
}
DataConnectLogger
.debug("executeQuery() sends grpc request: \(requestString, privacy: .private).")
let results = try await client.executeQuery(grpcRequest, callOptions: createCallOptions())
if debugEnable == true {
try FirebaseLogger.dataConnect
.debug("executeQuery() receives response: \(results.jsonString()).")
} else {
try FirebaseLogger.dataConnect
.debug("executeQuery() receives response.")
}
let resultsString = try results.jsonString()
DataConnectLogger
.debug("executeQuery() receives response: \(resultsString, privacy: .private).")
// Not doing error decoding here
if let decodedResults = try codec.decode(result: results.data, asType: resultType) {
return OperationResult(data: decodedResults)
} else {
// In future, set this as error in OperationResult
if debugEnable == true {
try FirebaseLogger.dataConnect
.error("executeQuery() response: \(results.jsonString()) decode failed.")
} else {
try FirebaseLogger.dataConnect
.error("executeQuery() response decode failed.")
}
DataConnectLogger
.debug("executeQuery() response: \(resultsString, privacy: .private) decode failed.")
throw DataConnectError.decodeFailed
}
} catch {
if debugEnable == true {
try FirebaseLogger.dataConnect
.error(
"executeQuery() with request: \(grpcRequest.jsonString()) grpc call FAILED with \(error)."
)
} else {
try FirebaseLogger.dataConnect
.error(
"executeQuery() grpc call FAILED with \(error)."
)
}
DataConnectLogger.error(
"executeQuery(): \(requestString, privacy: .private) grpc call FAILED with \(error)."
)
throw error
}
}
Expand All @@ -206,7 +171,7 @@ actor GrpcClient: CustomStringConvertible {
.Type)
async throws -> OperationResult<ResultType> {
guard let client else {
FirebaseLogger.dataConnect
DataConnectLogger
.error("When calling executeMutation(), grpc client has not been configured.")
throw DataConnectError.grpcNotConfigured
}
Expand All @@ -217,46 +182,26 @@ actor GrpcClient: CustomStringConvertible {
request: request
)

let requestString = try grpcRequest.jsonString()

do {
if debugEnable == true {
try FirebaseLogger.dataConnect
.debug("executeMutation() sends grpc request: \(grpcRequest.jsonString()).")
} else {
try FirebaseLogger.dataConnect
.debug("executeMutation() sends grpc request.")
}
DataConnectLogger
.debug("executeMutation() sends grpc request: \(requestString, privacy: .private).")
let results = try await client.executeMutation(grpcRequest, callOptions: createCallOptions())
if debugEnable == true {
try FirebaseLogger.dataConnect
.debug("executeMutation() receives response: \(results.jsonString()).")
} else {
try FirebaseLogger.dataConnect
.debug("executeMutation() receives response.")
}
let resultsString = try results.jsonString()
DataConnectLogger
.debug("executeMutation() receives response: \(resultsString, privacy: .private).")
if let decodedResults = try codec.decode(result: results.data, asType: resultType) {
return OperationResult(data: decodedResults)
} else {
if debugEnable == true {
try FirebaseLogger.dataConnect
.error("executeMutation() response: \(results.jsonString()) decode failed.")
} else {
try FirebaseLogger.dataConnect
.error("executeMutation() response decode failed.")
}
DataConnectLogger
.debug("executeMutation() response: \(resultsString, privacy: .private) decode failed.")
throw DataConnectError.decodeFailed
}
} catch {
if debugEnable == true {
try FirebaseLogger.dataConnect
.error(
"executeMutation() with request: \(grpcRequest.jsonString()) grpc call FAILED with \(error)."
)
} else {
try FirebaseLogger.dataConnect
.error(
"executeMutation() grpc call FAILED with \(error)."
)
}
DataConnectLogger.error(
"executeMutation(): \(requestString, privacy: .private) grpc call FAILED with \(error)."
)
throw error
}
}
Expand All @@ -274,44 +219,39 @@ actor GrpcClient: CustomStringConvertible {
do {
if let token = try await auth.currentUser?.getIDToken() {
headers.add(name: RequestHeaders.authorizationHeader, value: "\(token)")
if debugEnable == true {
FirebaseLogger.dataConnect
.debug("Auth token added: \(token)")
} else {
FirebaseLogger.dataConnect
.debug("Auth token added.")
}
DataConnectLogger.debug("Auth token added.")
} else {
FirebaseLogger.dataConnect.debug("No auth token available. Not adding auth header.")
DataConnectLogger.debug("No auth token available. Not adding auth header.")
}
} catch {
FirebaseLogger.dataConnect
DataConnectLogger
.debug("Cannot get auth token successfully due to: \(error). Not adding auth header.")
}

// Add AppCheck token if available
do {
if let token = try await appCheck?.token(forcingRefresh: false) {
headers.add(name: RequestHeaders.appCheckHeader, value: token.token)
if debugEnable == true {
FirebaseLogger.dataConnect
.debug("App Check token added: \(token.token)")
} else {
FirebaseLogger.dataConnect
.debug("App Check token added.")
}
DataConnectLogger.debug("App Check token added.")
} else {
FirebaseLogger.dataConnect
.debug("App Check token unavailable. Not adding App Check header.")
DataConnectLogger.debug("App Check token unavailable. Not adding App Check header.")
}
} catch {
FirebaseLogger.dataConnect
.debug(
"Cannot get App Check token successfully due to: \(error). Not adding App Check header."
)
DataConnectLogger.debug(
"Cannot get App Check token successfully due to: \(error). Not adding App Check header."
)
}

var options = CallOptions(customMetadata: headers)

// Enable GRPC tracing
if DataConnectLogger.logLevel.rawValue >= FirebaseLoggerLevel.debug.rawValue,
DataConnectLogger.privateLoggingEnabled == false {
var logger = Logger(label: "com.google.firebase.dataconnect.grpc")
logger.logLevel = .trace
options.logger = logger
}

let options = CallOptions(customMetadata: headers)
return options
}
}
Loading
Loading