Parity with the Android client: drop the "Allow self-signed certificate" escape hatch. The app now performs system TLS trust only — a self-signed appliance must have its CA installed on the device (MDM/profile). A code-only public-key pinning policy remains (no UI). - ServerTrustEvaluator: remove ServerTrustPolicy.allowSelfSignedForHost and its challenge handler; keep .system (default) and .pinPublicKeySHA256. - SettingsView: remove the self-signed toggle/state/prefill; makeConfig uses the default .system policy. - MCMSConnection / APIConfiguration: update usage-sketch + doc comments. - README / GUI-NOTES / MCMS_API.md: document system-trust-only; self-signed boxes need their CA installed on the device. - Add CHANGELOG.md for this session, flagged for the Android port. Note: configs previously persisted with the self-signed policy fail to decode and reset to defaults (one-time re-entry of the server URL). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
65 lines
2.4 KiB
Swift
65 lines
2.4 KiB
Swift
import Foundation
|
|
|
|
/// Builds and holds the networking stack for one MCMS connection. Construct this
|
|
/// once you have a host + trust policy, then hand the repositories to your view
|
|
/// models. Re-create it (or call `reset`) when the host/config changes.
|
|
@MainActor
|
|
final class MCMSConnection {
|
|
let config: APIConfiguration
|
|
let session: SessionStore
|
|
let client: APIClient
|
|
|
|
let auth: AuthRepository
|
|
let onu: ONURepository
|
|
let olt: OLTRepository
|
|
let controller: ControllerRepository
|
|
|
|
init(config: APIConfiguration) {
|
|
self.config = config
|
|
let session = SessionStore(config: config)
|
|
let client = APIClient(config: config, session: session)
|
|
self.session = session
|
|
self.client = client
|
|
self.auth = AuthRepository(client: client, session: session, config: config)
|
|
self.onu = ONURepository(client: client)
|
|
self.olt = OLTRepository(client: client)
|
|
self.controller = ControllerRepository(client: client)
|
|
}
|
|
|
|
/// Fired when any request fails with 401/403 so the app can route back to
|
|
/// login. Forwarded to the underlying `APIClient`.
|
|
var onAuthExpired: (@MainActor () -> Void)? {
|
|
get { client.onAuthExpired }
|
|
set { client.onAuthExpired = newValue }
|
|
}
|
|
}
|
|
|
|
/*
|
|
USAGE SKETCH (delete once real views exist)
|
|
|
|
// The appliance must present a CA-trusted cert (real cert, or an internal CA
|
|
// installed on the device via MDM/profile) — system trust only, no self-signed bypass:
|
|
let url = URL(string: "https://mcms.example.com/api")!
|
|
let config = APIConfiguration(
|
|
baseURL: url,
|
|
apiVersion: "v1", // confirm /api/v1 vs /v1 from openapi.json
|
|
databaseId: nil // or a specific DB id
|
|
) // trustPolicy defaults to .system
|
|
|
|
let connection = MCMSConnection(config: config)
|
|
|
|
// Login (creds pulled from Keychain in real code):
|
|
try await connection.auth.login(email: email, password: password)
|
|
|
|
// Dashboard data:
|
|
let onus = try await connection.onu.allStates()
|
|
let counts = Dictionary(grouping: onus, by: { $0.lifecycle }).mapValues(\.count)
|
|
|
|
// ONU detail:
|
|
let stats = try await connection.onu.stats(id: "BFWS00123193", lastHours: 24)
|
|
|
|
// An operation (gate behind a confirm dialog):
|
|
try await connection.onu.reset(id: "BFWS00123193")
|
|
|
|
try await connection.auth.logout()
|
|
*/
|