Skip to content
This repository has been archived by the owner on Apr 18, 2019. It is now read-only.

Commit

Permalink
extract supervisor templating into core
Browse files Browse the repository at this point in the history
Signed-off-by: mwrock <matt@mattwrock.com>
  • Loading branch information
mwrock committed Nov 20, 2018
1 parent 3e03912 commit a0bfd44
Show file tree
Hide file tree
Showing 41 changed files with 7,043 additions and 15 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ matrix:
- kalakris-cmake
packages:
- build-essential
- busybox
- ca-certificates
- cmake
- curl
Expand Down
1,204 changes: 1,203 additions & 1 deletion Cargo.lock

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions components/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ base64 = "*"
gcc = "0.3"

[dependencies]
actix-web = { version = "*", default-features = false }
ansi_term = "*"
clippy = {version = "*", optional = true}
base64 = "*"
dirs = "*"
errno = "*"
handlebars = { version = "= 0.28.3", default-features = false }
hex = "*"
lazy_static = "*"
libarchive = "*"
Expand All @@ -26,16 +28,22 @@ regex = "*"
serde = "*"
serde_derive = "*"
serde_json = "*"
serde-transcode = "*"
serde_yaml = "*"
sodiumoxide = "0.0.16"
tempfile = "*"
time = "*"
toml = { version = "*", default-features = false }
typemap = "*"
url = "*"
valico = "*"

[target.'cfg(not(windows))'.dependencies]
users = "*"

[target.'cfg(target_os = "linux")'.dependencies]
caps = "*"

[target.'cfg(windows)'.dependencies]
ctrlc = "*"
habitat_win_users = { path = "../win-users" }
Expand All @@ -45,6 +53,7 @@ windows-acl = "*"

[dev-dependencies]
hyper = "0.10"
json = "*"

[features]
default = []
Expand Down
37 changes: 35 additions & 2 deletions components/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum Error {
/// Occurs when a `habitat_core::package::PackageArchive` is being read.
ArchiveError(libarchive::error::ArchiveError),
BadBindingMode(String),
BadEnvConfig(String),
/// An invalid path to a keyfile was given.
BadKeyPath(String),
/// An operation expected a composite package
Expand Down Expand Up @@ -135,18 +136,28 @@ pub enum Error {
PackageUnpackFailed(String),
/// When an error occurs parsing an integer.
ParseIntError(num::ParseIntError),
/// Occurs when setting ownership or permissions on a file or directory fails.
/// Occurs upon errors related to file or directory permissions.
PermissionFailed(String),
/// Error parsing the contents of a plan file were incomplete or malformed.
PlanMalformed,
// When CreateProcessAsUserW does not have the correct privileges
PrivilegeNotHeld,
/// When an error occurs parsing or compiling a regular expression.
RegexParse(regex::Error),
/// Whwn an error occurs serializing rendering context
RenderContextSerialization(serde_json::Error),
/// When an error occurs converting a `String` from a UTF-8 byte vector.
StringFromUtf8Error(string::FromUtf8Error),
/// When the system target (platform and architecture) do not match the package target.
TargetMatchError(String),
/// When an error occurs registering template file
TemplateFileError(handlebars::TemplateFileError),
/// When an error occurs rendering template
TemplateRenderError(handlebars::RenderError),
/// When an error occurs merging toml
TomlMergeError(String),
/// When an error occurs parsing toml
TomlParser(toml::de::Error),
/// Occurs when a `uname` libc call returns an error.
UnameFailed(String),
/// Occurs when a `waitpid` libc call returns an error.
Expand All @@ -173,6 +184,9 @@ impl fmt::Display for Error {
let msg = match *self {
Error::ArchiveError(ref err) => format!("{}", err),
Error::BadBindingMode(ref value) => format!("Unknown binding mode '{}'", value),
Error::BadEnvConfig(ref varname) => {
format!("Unable to find valid TOML or JSON in {} ENVVAR", varname)
}
Error::BadKeyPath(ref e) => format!(
"Invalid keypath: {}. Specify an absolute path to a file on disk.",
e
Expand Down Expand Up @@ -326,8 +340,15 @@ impl fmt::Display for Error {
user"
),
Error::RegexParse(ref e) => format!("{}", e),
Error::RenderContextSerialization(ref e) => {
format!("Unable to serialize rendering context, {}", e)
}
Error::StringFromUtf8Error(ref e) => format!("{}", e),
Error::TargetMatchError(ref e) => format!("{}", e),
Error::TemplateFileError(ref err) => format!("{:?}", err),
Error::TemplateRenderError(ref err) => format!("{}", err),
Error::TomlMergeError(ref e) => format!("Failed to merge TOML: {}", e),
Error::TomlParser(ref err) => format!("Failed to parse TOML: {}", err),
Error::UnameFailed(ref e) => format!("{}", e),
Error::WaitpidFailed(ref e) => format!("{}", e),
Error::SignalFailed(ref r, ref e) => {
Expand All @@ -353,6 +374,7 @@ impl error::Error for Error {
match *self {
Error::ArchiveError(ref err) => err.description(),
Error::BadBindingMode(_) => "Unknown binding mode",
Error::BadEnvConfig(_) => "Unknown syntax in Env Configuration",
Error::BadKeyPath(_) => "An absolute path to a file on disk is required",
Error::CompositePackageExpected(_) => "A composite package was expected",
Error::ConfigFileIO(_, _) => "Unable to read the raw contents of a configuration file",
Expand Down Expand Up @@ -458,10 +480,11 @@ impl error::Error for Error {
Error::PackageNotFound(_) => "Cannot find a package",
Error::PackageUnpackFailed(_) => "Package could not be unpacked",
Error::ParseIntError(_) => "Failed to parse an integer from a string!",
Error::PermissionFailed(_) => "Failed to set permissions",
Error::PermissionFailed(_) => "File system permissions error",
Error::PlanMalformed => "Failed to read or parse contents of Plan file",
Error::PrivilegeNotHeld => "Privilege not held to spawn process as different user",
Error::RegexParse(_) => "Failed to parse a regular expression",
Error::RenderContextSerialization(_) => "Unable to serialize rendering context",
Error::StringFromUtf8Error(_) => "Failed to convert a string from a Vec<u8> as UTF-8",
Error::TargetMatchError(_) => "System target does not match package target",
Error::UnameFailed(_) => "uname failed",
Expand All @@ -470,7 +493,11 @@ impl error::Error for Error {
Error::WaitpidFailed(_) => "waitpid failed",
Error::GetExitCodeProcessFailed(_) => "GetExitCodeProcess failed",
Error::WaitForSingleObjectFailed(_) => "WaitForSingleObjectFailed failed",
Error::TemplateFileError(ref err) => err.description(),
Error::TemplateRenderError(ref err) => err.description(),
Error::TerminateProcessFailed(_) => "Failed to call TerminateProcess",
Error::TomlMergeError(_) => "Failed to merge TOML!",
Error::TomlParser(_) => "Failed to parse TOML!",
Error::Utf8Error(_) => "Failed to interpret a sequence of bytes as a string",
Error::WrongActivePackageTarget(_, _) => {
"Package target is not supported as this system has a different \
Expand Down Expand Up @@ -521,3 +548,9 @@ impl From<regex::Error> for Error {
Error::RegexParse(err)
}
}

impl From<handlebars::TemplateFileError> for Error {
fn from(err: handlebars::TemplateFileError) -> Self {
Error::TemplateFileError(err)
}
}
Loading

0 comments on commit a0bfd44

Please sign in to comment.