Skip to content

Commit 055a678

Browse files
authored
Merge pull request #111 from Automattic/iangmaia/mount-safe-agent-keys-directory
Mount directory for sharing keys with macOS VMs
2 parents a3e3922 + 5424eb7 commit 055a678

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

Sources/hostmgr/commands/vm/VMStart.swift

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ struct VMStartCommand: AsyncParsableCommand {
1919
@Flag(help: "Mount the system git mirrors directory into the virtual machine on startup?")
2020
var withGitMirrors: Bool = false
2121

22+
@Flag(help: "Mount the directory with shared credentials into the virtual machine on startup?")
23+
var withCommonCredentials: Bool = false
24+
2225
@Flag(help: "Wait indefinitely for the SSH server to become available (useful when provisioning a new image")
2326
var waitForever: Bool = false
2427

@@ -33,6 +36,7 @@ struct VMStartCommand: AsyncParsableCommand {
3336
case name
3437
case handle
3538
case withGitMirrors
39+
case withCommonCredentials
3640
case waitForever
3741
case persistent
3842
case skipNetworkChecks
@@ -72,19 +76,30 @@ struct VMStartCommand: AsyncParsableCommand {
7276
}
7377
}
7478

79+
// Those paths are auto-mounted in the VM in the `/Volumes/My Shared Files/` path
80+
// See https://developer.apple.com/documentation/virtualization/vzvirtiofilesystemdeviceconfiguration
81+
// See Sources/libhostmgr/VM/LaunchConfiguration.swift#L69-L82
7582
var sharedPaths: [LaunchConfiguration.SharedPath] {
7683
get throws {
77-
guard try FileManager.default.directoryExists(at: Paths.gitMirrorStorageDirectory) else {
78-
return []
84+
var paths: [LaunchConfiguration.SharedPath] = []
85+
86+
if self.withGitMirrors {
87+
if try FileManager.default.directoryExists(at: Paths.gitMirrorStorageDirectory) {
88+
paths.append(
89+
LaunchConfiguration.SharedPath(source: Paths.gitMirrorStorageDirectory, readOnly: true)
90+
)
91+
}
7992
}
8093

81-
guard self.withGitMirrors == true else {
82-
return []
94+
if self.withCommonCredentials {
95+
if try FileManager.default.directoryExists(at: Paths.commonCredentialsDirectory) {
96+
paths.append(
97+
LaunchConfiguration.SharedPath(source: Paths.commonCredentialsDirectory, readOnly: true)
98+
)
99+
}
83100
}
84101

85-
return [
86-
LaunchConfiguration.SharedPath(source: Paths.gitMirrorStorageDirectory, readOnly: true)
87-
]
102+
return paths
88103
}
89104
}
90105
}

Sources/libhostmgr/Model/Paths.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public extension Paths {
4444
storageRoot.appendingPathComponent("git-mirrors", isDirectory: true)
4545
}()
4646

47+
static let commonCredentialsDirectory: URL = {
48+
storageRoot.appendingPathComponent("common-credentials", isDirectory: true)
49+
}()
50+
4751
static let restoreImageDirectory: URL = {
4852
storageRoot.appendingPathComponent("restore-images", isDirectory: true)
4953
}()

Sources/libhostmgr/libhostmgr.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import OSLog
33

4-
public let hostmgrVersion = "0.50.2"
4+
public let hostmgrVersion = "0.51.0"
55

66
public extension Logger {
77
private static let subsystem = "com.automattic.hostmgr"

0 commit comments

Comments
 (0)