225 lines
6.9 KiB
Swift
225 lines
6.9 KiB
Swift
import Foundation
|
|
|
|
// NOTE: When adding items, then the 'hpa.toml' resource file needs to be updated.
|
|
|
|
/// Represents configurable settings for the application.
|
|
public struct Configuration: Codable, Equatable, Sendable {
|
|
|
|
/// Default arguments / options that can get passed into
|
|
/// ansible-playbook commands.
|
|
public let args: [String]?
|
|
|
|
/// Whether to use the vault arguments as defaults that get passed into
|
|
/// the ansible-playbook commands.
|
|
public let useVaultArgs: Bool
|
|
|
|
/// Configuration for when generating files from templated directories.
|
|
public let generate: Generate?
|
|
|
|
/// Configuration of the ansible-playbook, these are more for developing the
|
|
/// playbook locally and generally not needed by the user.
|
|
public let playbook: Playbook?
|
|
|
|
/// Template configuration options.
|
|
public let template: Template
|
|
|
|
/// Ansible-vault configuration options.
|
|
public let vault: Vault
|
|
|
|
public init(
|
|
args: [String]? = nil,
|
|
useVaultArgs: Bool = true,
|
|
generate: Generate? = nil,
|
|
playbook: Playbook? = nil,
|
|
template: Template = .init(),
|
|
vault: Vault = .init()
|
|
) {
|
|
self.args = args
|
|
self.useVaultArgs = useVaultArgs
|
|
self.generate = generate
|
|
self.playbook = playbook
|
|
self.template = template
|
|
self.vault = vault
|
|
}
|
|
|
|
public static var mock: Self {
|
|
.init(
|
|
args: [],
|
|
useVaultArgs: true,
|
|
playbook: nil,
|
|
template: .mock,
|
|
vault: .mock
|
|
)
|
|
}
|
|
|
|
/// Configuration options for running `pandoc` commands that generate files from
|
|
/// a templated directory.
|
|
///
|
|
/// ## NOTE: Most of these can also be set by the template repository variables.
|
|
///
|
|
///
|
|
public struct Generate: Codable, Equatable, Sendable {
|
|
|
|
/// Specifiy the name of the build directory, generally `.build`.
|
|
public let buildDirectory: String?
|
|
|
|
/// Specifiy the files used in the `pandoc` command to generate a final output file.
|
|
///
|
|
/// - SeeAlso: `pandoc --help`
|
|
public let files: [String]?
|
|
|
|
/// Specifiy the files used in the `pandoc` command to include in the header.
|
|
///
|
|
/// - SeeAlso: `pandoc --help`
|
|
public let includeInHeader: [String]?
|
|
|
|
/// The default name of the output file, this does not require the file extension as we will
|
|
/// add it based on the command that is called. Generally this is 'Report'.
|
|
///
|
|
public let outputFileName: String?
|
|
|
|
/// The default pdf engine to use when generating pdf files using `pandoc`. Generally
|
|
/// this is 'xelatex'.
|
|
public let pdfEngine: String?
|
|
|
|
public init(
|
|
buildDirectory: String? = nil,
|
|
files: [String]? = nil,
|
|
includeInHeader: [String]? = nil,
|
|
outputFileName: String? = nil,
|
|
pdfEngine: String? = nil
|
|
) {
|
|
self.buildDirectory = buildDirectory
|
|
self.files = files
|
|
self.includeInHeader = includeInHeader
|
|
self.outputFileName = outputFileName
|
|
self.pdfEngine = pdfEngine
|
|
}
|
|
|
|
/// Represents the default configuration for generating files using `pandoc`.
|
|
public static let `default` = Self.mock
|
|
|
|
/// Represents mock configuration for generating files using `pandoc`.
|
|
public static var mock: Self {
|
|
.init(
|
|
buildDirectory: ".build",
|
|
files: ["Report.md", "Definitions.md"],
|
|
includeInHeader: ["head.tex", "footer.tex"],
|
|
outputFileName: "Report",
|
|
pdfEngine: "xelatex"
|
|
)
|
|
}
|
|
}
|
|
|
|
/// Configuration options for the ansible-hpa-playbook. The playbook is
|
|
/// the primary driver of templating files, generating repository templates, and building
|
|
/// projects.
|
|
///
|
|
/// ## NOTE: These are generally only used for local development of the playbook.
|
|
///
|
|
///
|
|
public struct Playbook: Codable, Equatable, Sendable {
|
|
|
|
/// The directory location of the ansible playbook.
|
|
public let directory: String?
|
|
|
|
/// The inventory file name / location.
|
|
public let inventory: String?
|
|
|
|
/// The playbook version, branch, or tag.
|
|
public let version: String?
|
|
|
|
public init(
|
|
directory: String? = nil,
|
|
inventory: String? = nil,
|
|
version: String? = nil
|
|
) {
|
|
self.directory = directory
|
|
self.inventory = inventory
|
|
self.version = version
|
|
}
|
|
|
|
public static var mock: Self { .init() }
|
|
}
|
|
|
|
/// Configuration settings for the user's template repository or directory.
|
|
///
|
|
/// A template is what is used to create projects for a user. Generally they setup
|
|
/// their own template by customizing the default template to their needs. This template
|
|
/// can then be stored as a git repository or on the local file system.
|
|
///
|
|
/// The template will hold variables and files that are used to generate the final output
|
|
/// files using `pandoc`. Generally the template will hold files that may only need setup once,
|
|
/// such as header files, footer files, and definitions.
|
|
///
|
|
/// The project directory contains dynamic variables / files that need edited in order
|
|
/// to generate the final output. This allows the project directory to remain smaller so the user
|
|
/// can more easily focus on the tasks required to generate the final output files.
|
|
public struct Template: Codable, Equatable, Sendable {
|
|
|
|
/// A url of the template when it is a remote git repository.
|
|
public let url: String?
|
|
|
|
/// The version, branch, or tag of the remote repository.
|
|
public let version: String?
|
|
|
|
/// The local directory that contains the template on the local file system.
|
|
public let directory: String?
|
|
|
|
public init(
|
|
url: String? = nil,
|
|
version: String? = nil,
|
|
directory: String? = nil
|
|
) {
|
|
self.url = url
|
|
self.version = version
|
|
self.directory = directory
|
|
}
|
|
|
|
public static var mock: Self {
|
|
.init(
|
|
url: "https://git.example.com/consult-template.git",
|
|
version: "1.0.0",
|
|
directory: "/path/to/local/template-directory"
|
|
)
|
|
}
|
|
}
|
|
|
|
/// Configuration for `ansible-vault` commands. Ansible vault is used to encrypt and
|
|
/// decrypt sensitive data. This allows for variables, such as customer name and address
|
|
/// to be stored along with the project in an encrypted file so that it is safer to store them.
|
|
///
|
|
/// These may also be used in general `ansible-playbook` commands if the `useVaultArgs` is set
|
|
/// to `true` in a users configuration.
|
|
///
|
|
public struct Vault: Codable, Equatable, Sendable {
|
|
|
|
/// A list of arguments / options that get passed to the `ansible-vault` command.
|
|
///
|
|
/// - SeeAlso: `ansible-vault --help`
|
|
public let args: [String]?
|
|
|
|
/// An id that is used during encrypting `ansible-vault` files.
|
|
///
|
|
/// - SeeAlso: `ansible-vault encrypt --help`
|
|
public let encryptId: String?
|
|
|
|
public init(
|
|
args: [String]? = nil,
|
|
encryptId: String? = nil
|
|
) {
|
|
self.args = args
|
|
self.encryptId = encryptId
|
|
}
|
|
|
|
public static var mock: Self {
|
|
.init(
|
|
args: [
|
|
"--vault-id=myId@$SCRIPTS/vault-gopass-client"
|
|
],
|
|
encryptId: "myId"
|
|
)
|
|
}
|
|
}
|
|
}
|