Skip to content

Commit aa608ef

Browse files
committed
fix(ComposeUp): Fix guard-else syntax and optional chaining in secrets loading
- Replace invalid guard-else with proper if-else pattern - Fix optional chaining on non-optional String at line 1305 - Resolves syntax errors blocking build
1 parent 73dcb9b commit aa608ef

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

Sources/Container-Compose/Commands/ComposeUp.swift

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,39 +1284,37 @@ public struct ComposeUp: AsyncParsableCommand, @unchecked Sendable {
12841284
Self.resolveServicePlaceholder(value, containerIps: containerIps, containerPorts: containerPorts, knownServiceNames: knownServiceNames)
12851285
}
12861286

1287-
// Load secrets from x-apple-secrets filter if present
1288-
var secretsEnv: [String: String] = [:]
1289-
if let secretsConfig = service.x_apple_secrets,
1290-
let filter = secretsConfig.filter, !filter.isEmpty {
1291-
// Get enclave path from global config or default to ~/.enclave
1292-
let enclavePath = dockerCompose.xAppleSecretsGlobal?.enclave
1293-
?? (NSHomeDirectory() + "/.enclave")
1294-
let fileManager = FileManager.default
1295-
guard fileManager.fileExists(atPath: enclavePath) else {
1296-
print("Warning: Enclave not found at \(enclavePath) for service \(serviceName). Skipping secrets.".yellow)
1297-
return
1298-
}
1299-
1300-
// Process secrets from enclave
1301-
do {
1302-
let allFiles = try fileManager.contentsOfDirectory(atPath: enclavePath)
1303-
for fileName in allFiles {
1304-
let normalizedName = fileName
1305-
.replacingOccurrences(of: ".txt", with: "")
1306-
.uppercased()
1307-
if filter.contains(normalizedName) {
1308-
let path = "\(enclavePath)/\(fileName)"
1309-
if let content = try? String(contentsOfFile: path, encoding: .utf8)?
1310-
.trimmingCharacters(in: .whitespacesAndNewlines) {
1311-
secretsEnv[normalizedName] = content
1312-
}
1313-
}
1314-
}
1315-
} catch {
1316-
print("Warning: Failed to load secrets for service \(serviceName): \(error). Continuing without secrets.".yellow)
1317-
}
1318-
}
1319-
}
1287+
// Load secrets from x-apple-secrets filter if present
1288+
var secretsEnv: [String: String] = [:]
1289+
if let secretsConfig = service.x_apple_secrets,
1290+
let filter = secretsConfig.filter, !filter.isEmpty {
1291+
// Get enclave path from global config or default to ~/.enclave
1292+
let enclavePath = dockerCompose.xAppleSecretsGlobal?.enclave
1293+
?? (NSHomeDirectory() + "/.enclave")
1294+
let fileManager = FileManager.default
1295+
if fileManager.fileExists(atPath: enclavePath) {
1296+
// Process secrets from enclave
1297+
do {
1298+
let allFiles = try fileManager.contentsOfDirectory(atPath: enclavePath)
1299+
for fileName in allFiles {
1300+
let normalizedName = fileName
1301+
.replacingOccurrences(of: ".txt", with: "")
1302+
.uppercased()
1303+
if filter.contains(normalizedName) {
1304+
let path = "\(enclavePath)/\(fileName)"
1305+
if let content = try? String(contentsOfFile: path, encoding: .utf8)
1306+
.trimmingCharacters(in: .whitespacesAndNewlines) {
1307+
secretsEnv[normalizedName] = content
1308+
}
1309+
}
1310+
}
1311+
} catch {
1312+
print("Warning: Failed to load secrets for service \(serviceName): \(error). Continuing without secrets.".yellow)
1313+
}
1314+
} else {
1315+
print("Warning: Enclave not found at \(enclavePath) for service \(serviceName). Skipping secrets.".yellow)
1316+
}
1317+
}
13201318

13211319
// Build the `container run` argument list using the standardized helper
13221320
let runCommandArgs = try Self.makeRunArgs(

0 commit comments

Comments
 (0)