feat: Merges dev
All checks were successful
CI / Run Tests (push) Successful in 2m43s

This commit is contained in:
2024-12-17 15:55:36 -05:00
parent 857177032c
commit faa28749bc
88 changed files with 4513 additions and 2301 deletions

View File

@@ -1,4 +1,6 @@
import ArgumentParser
import Dependencies
import VaultClient
struct DecryptCommand: AsyncParsableCommand {
@@ -9,23 +11,22 @@ struct DecryptCommand: AsyncParsableCommand {
abstract: createAbstract("Decrypt a vault file.")
)
@OptionGroup var options: VaultOptions
@Option(
name: .shortAndLong,
help: "Output file."
)
var output: String?
@OptionGroup var options: VaultOptions
mutating func run() async throws {
var args = ["decrypt"]
if let output {
args.append(contentsOf: ["--output", output])
}
try await runVault(
@Dependency(\.vaultClient) var vaultClient
let output = try await vaultClient.run.decrypt(options.runOptions(
commandName: Self.commandName,
options: options,
args
)
outputFilePath: output
))
print(output)
}
}

View File

@@ -0,0 +1 @@

View File

@@ -1,4 +1,6 @@
import ArgumentParser
import Dependencies
import VaultClient
struct EncryptCommand: AsyncParsableCommand {
@@ -9,23 +11,22 @@ struct EncryptCommand: AsyncParsableCommand {
abstract: createAbstract("Encrypt a vault file.")
)
@OptionGroup var options: VaultOptions
@Option(
name: .shortAndLong,
help: "Output file."
)
var output: String?
@OptionGroup var options: VaultOptions
mutating func run() async throws {
var args = ["encrypt"]
if let output {
args.append(contentsOf: ["--output", output])
}
try await runVault(
@Dependency(\.vaultClient) var vaultClient
let output = try await vaultClient.run.encrypt(options.runOptions(
commandName: Self.commandName,
options: options,
args
)
outputFilePath: output
))
print(output)
}
}

View File

@@ -1,4 +1,5 @@
import ArgumentParser
import CliDoc
struct VaultCommand: AsyncParsableCommand {
@@ -7,14 +8,23 @@ struct VaultCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: commandName,
abstract: createAbstract("Vault commands."),
discussion: Discussion(
.text("""
Allows you to run `ansible-vault` commands on your project or project-template.
"""),
.seeAlso(label: "Ansible Vault", command: "ansible-vault")
).render(),
discussion: Discussion {
VStack {
"""
Allows you to run `ansible-vault` commands on your project or project-template.
Ansible-vault allows you to store sensitive variables in an encrypted format.
"""
SeeAlso {
"ansible-vault --help"
} label: {
"Ansible Vault"
}
}
.separator(.newLine(count: 2))
},
subcommands: [
EncryptCommand.self, DecryptCommand.self
DecryptCommand.self, EncryptCommand.self
]
)
}

View File

@@ -1,4 +1,6 @@
import ArgumentParser
import CommandClient
import VaultClient
// Holds the common options for vault commands, as they all share the
// same structure.
@@ -17,7 +19,7 @@ struct VaultOptions: ParsableArguments {
@Argument(
help: "Extra arguments to pass to the vault command."
)
var extraArgs: [String] = []
var extraOptions: [String] = []
subscript<T>(dynamicMember keyPath: WritableKeyPath<BasicGlobalOptions, T>) -> T {
get { globals[keyPath: keyPath] }
@@ -29,3 +31,23 @@ struct VaultOptions: ParsableArguments {
}
}
extension VaultOptions {
func runOptions(
commandName: String,
outputFilePath: String? = nil
) -> VaultClient.RunOptions {
.init(
extraOptions: extraOptions,
loggingOptions: .init(
commandName: commandName,
logLevel: .init(globals: globals, quietOnlyPlaybook: false)
),
outputFilePath: outputFilePath,
quiet: globals.quiet,
shell: globals.shell,
vaultFilePath: file
)
}
}