49 lines
1.1 KiB
Swift
49 lines
1.1 KiB
Swift
import Dependencies
|
|
import ShellClient
|
|
|
|
func runVault(
|
|
commandName: String,
|
|
options: VaultOptions,
|
|
_ args: [String]
|
|
) async throws {
|
|
try await withSetupLogger(commandName: commandName, globals: options.globals) {
|
|
@Dependency(\.cliClient) var cliClient
|
|
@Dependency(\.logger) var logger
|
|
|
|
logger.debug("Begin run vault: \(options)")
|
|
|
|
let configuration = try cliClient.ensuredConfiguration(nil)
|
|
logger.debug("Configuration: \(configuration)")
|
|
|
|
let path: String
|
|
if let file = options.file {
|
|
path = file
|
|
} else {
|
|
path = try cliClient.findVaultFileInCurrentDirectory()
|
|
}
|
|
|
|
logger.debug("Vault path: \(path)")
|
|
|
|
let defaultArgs = configuration.defaultVaultArgs ?? []
|
|
|
|
var vaultArgs = ["ansible-vault"]
|
|
+ args
|
|
+ defaultArgs
|
|
+ options.extraArgs
|
|
+ [path]
|
|
|
|
if args.contains("encrypt"),
|
|
!vaultArgs.contains("--encrypt-vault-id"),
|
|
let id = configuration.defaultVaultEncryptId
|
|
{
|
|
vaultArgs.append(contentsOf: ["--encrypt-vault-id", id])
|
|
}
|
|
|
|
try await cliClient.runCommand(
|
|
quiet: options.quiet,
|
|
shell: options.shellOrDefault,
|
|
vaultArgs
|
|
)
|
|
}
|
|
}
|