feat: Integrates vault-client into hpa-executable.
This commit is contained in:
@@ -31,6 +31,7 @@ let package = Package(
|
|||||||
"ConfigurationClient",
|
"ConfigurationClient",
|
||||||
"FileClient",
|
"FileClient",
|
||||||
"PlaybookClient",
|
"PlaybookClient",
|
||||||
|
"VaultClient",
|
||||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
||||||
.product(name: "CliDoc", package: "swift-cli-doc"),
|
.product(name: "CliDoc", package: "swift-cli-doc"),
|
||||||
.product(name: "Dependencies", package: "swift-dependencies"),
|
.product(name: "Dependencies", package: "swift-dependencies"),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import ArgumentParser
|
import ArgumentParser
|
||||||
import CliClient
|
import CliClient
|
||||||
import Dependencies
|
import Dependencies
|
||||||
|
import VaultClient
|
||||||
|
|
||||||
struct DecryptCommand: AsyncParsableCommand {
|
struct DecryptCommand: AsyncParsableCommand {
|
||||||
|
|
||||||
@@ -11,25 +12,21 @@ struct DecryptCommand: AsyncParsableCommand {
|
|||||||
abstract: createAbstract("Decrypt a vault file.")
|
abstract: createAbstract("Decrypt a vault file.")
|
||||||
)
|
)
|
||||||
|
|
||||||
@OptionGroup var options: VaultOptions
|
|
||||||
|
|
||||||
@Option(
|
@Option(
|
||||||
name: .shortAndLong,
|
name: .shortAndLong,
|
||||||
help: "Output file."
|
help: "Output file."
|
||||||
)
|
)
|
||||||
var output: String?
|
var output: String?
|
||||||
|
|
||||||
|
@OptionGroup var options: VaultOptions
|
||||||
|
|
||||||
mutating func run() async throws {
|
mutating func run() async throws {
|
||||||
@Dependency(\.cliClient) var cliClient
|
@Dependency(\.vaultClient) var vaultClient
|
||||||
|
|
||||||
var args = ["decrypt"]
|
try await vaultClient.run(options.runOptions(
|
||||||
if let output {
|
commandName: Self.commandName,
|
||||||
args.append(contentsOf: ["--output", output])
|
route: .decrypt,
|
||||||
}
|
outputFilePath: output
|
||||||
|
))
|
||||||
try await cliClient.runVaultCommand(
|
|
||||||
options.vaultOptions(arguments: args, configuration: nil),
|
|
||||||
logging: options.loggingOptions(commandName: Self.commandName)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import ArgumentParser
|
import ArgumentParser
|
||||||
import CliClient
|
import CliClient
|
||||||
import Dependencies
|
import Dependencies
|
||||||
|
import VaultClient
|
||||||
|
|
||||||
struct EncryptCommand: AsyncParsableCommand {
|
struct EncryptCommand: AsyncParsableCommand {
|
||||||
|
|
||||||
@@ -11,24 +12,21 @@ struct EncryptCommand: AsyncParsableCommand {
|
|||||||
abstract: createAbstract("Encrypt a vault file.")
|
abstract: createAbstract("Encrypt a vault file.")
|
||||||
)
|
)
|
||||||
|
|
||||||
@OptionGroup var options: VaultOptions
|
|
||||||
|
|
||||||
@Option(
|
@Option(
|
||||||
name: .shortAndLong,
|
name: .shortAndLong,
|
||||||
help: "Output file."
|
help: "Output file."
|
||||||
)
|
)
|
||||||
var output: String?
|
var output: String?
|
||||||
|
|
||||||
mutating func run() async throws {
|
@OptionGroup var options: VaultOptions
|
||||||
@Dependency(\.cliClient) var cliClient
|
|
||||||
|
|
||||||
var args = ["encrypt"]
|
mutating func run() async throws {
|
||||||
if let output {
|
@Dependency(\.vaultClient) var vaultClient
|
||||||
args.append(contentsOf: ["--output", output])
|
|
||||||
}
|
try await vaultClient.run(options.runOptions(
|
||||||
try await cliClient.runVaultCommand(
|
commandName: Self.commandName,
|
||||||
options.vaultOptions(arguments: args, configuration: nil),
|
route: .encrypt,
|
||||||
logging: options.loggingOptions(commandName: Self.commandName)
|
outputFilePath: output
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import ArgumentParser
|
import ArgumentParser
|
||||||
import CliClient
|
import CliClient
|
||||||
|
import VaultClient
|
||||||
|
|
||||||
// Holds the common options for vault commands, as they all share the
|
// Holds the common options for vault commands, as they all share the
|
||||||
// same structure.
|
// same structure.
|
||||||
@@ -18,7 +19,7 @@ struct VaultOptions: ParsableArguments {
|
|||||||
@Argument(
|
@Argument(
|
||||||
help: "Extra arguments to pass to the vault command."
|
help: "Extra arguments to pass to the vault command."
|
||||||
)
|
)
|
||||||
var extraArgs: [String] = []
|
var extraOptions: [String] = []
|
||||||
|
|
||||||
subscript<T>(dynamicMember keyPath: WritableKeyPath<BasicGlobalOptions, T>) -> T {
|
subscript<T>(dynamicMember keyPath: WritableKeyPath<BasicGlobalOptions, T>) -> T {
|
||||||
get { globals[keyPath: keyPath] }
|
get { globals[keyPath: keyPath] }
|
||||||
@@ -36,3 +37,25 @@ extension VaultOptions {
|
|||||||
globals.loggingOptions(commandName: commandName)
|
globals.loggingOptions(commandName: commandName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension VaultOptions {
|
||||||
|
|
||||||
|
func runOptions(
|
||||||
|
commandName: String,
|
||||||
|
route: VaultClient.RunOptions.Route,
|
||||||
|
outputFilePath: String? = nil
|
||||||
|
) -> VaultClient.RunOptions {
|
||||||
|
.init(
|
||||||
|
route,
|
||||||
|
extraOptions: extraOptions,
|
||||||
|
loggingOptions: .init(
|
||||||
|
commandName: commandName,
|
||||||
|
logLevel: .init(globals: globals, quietOnlyPlaybook: false)
|
||||||
|
),
|
||||||
|
outputFilePath: outputFilePath,
|
||||||
|
quiet: globals.quiet,
|
||||||
|
shell: globals.shell,
|
||||||
|
vaultFilePath: file
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user