Skip to content

Commit

Permalink
Merge pull request #7 from cbgbt/sdk-vended-models
Browse files Browse the repository at this point in the history
Use bottlerocket-settings-sdk for settings models needed in core-kit
  • Loading branch information
bcressey authored Jun 19, 2024
2 parents aa1d20d + 4d94a74 commit a2fdb43
Show file tree
Hide file tree
Showing 70 changed files with 516 additions and 5,821 deletions.
485 changes: 388 additions & 97 deletions sources/Cargo.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion sources/api/bootstrap-containers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ exclude = ["README.md"]
base64 = "0.21"
constants = { path = "../../constants", version = "0.1" }
log = "0.4"
modeled-types = { path = "../../models/modeled-types", version = "0.1" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
simplelog = "0.12"
snafu = "0.8"
toml = "0.8"

[dependencies.bottlerocket-modeled-types]
git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk"
tag = "bottlerocket-settings-models-v0.1.0"
version = "0.1.0"

[build-dependencies]
generate-readme = { version = "0.1", path = "../../generate-readme" }
6 changes: 4 additions & 2 deletions sources/api/bootstrap-containers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::str::FromStr;

use modeled_types::{BootstrapContainerMode, Identifier, Url, ValidBase64};
use bottlerocket_modeled_types::{BootstrapContainerMode, Identifier, Url, ValidBase64};

const ENV_FILE_DIR: &str = "/etc/bootstrap-containers";
const DROPIN_FILE_DIR: &str = "/etc/systemd/system";
Expand Down Expand Up @@ -607,7 +607,9 @@ mod error {

// `try_from` in `BootstrapContainerMode` already returns a useful error message
#[snafu(display("Failed to parse mode: {}", source))]
BootstrapContainerMode { source: modeled_types::error::Error },
BootstrapContainerMode {
source: bottlerocket_modeled_types::error::Error,
},

#[snafu(display("'{}' failed - stderr: {}",
bin_path, String::from_utf8_lossy(&output.stderr)))]
Expand Down
5 changes: 5 additions & 0 deletions sources/api/bork/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ exclude = ["README.md"]
[dependencies]
rand = "0.8"
serde_json = "1"

[dependencies.settings-extension-updates]
git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk"
tag = "bottlerocket-settings-models-v0.1.0"
version = "0.1.0"
8 changes: 6 additions & 2 deletions sources/api/certdog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ argh = "0.1"
base64 = "0.21"
constants = { path = "../../constants", version = "0.1" }
log = "0.4"
modeled-types = { path = "../../models/modeled-types", version = "0.1" }
serde = { version = "1.0", features = ["derive"] }
simplelog = "0.12"
snafu = "0.8"
toml = "0.8"
x509-parser = "0.15"
x509-parser = "0.16"

[dependencies.bottlerocket-modeled-types]
git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk"
tag = "bottlerocket-settings-models-v0.1.0"
version = "0.1.0"

[dev-dependencies]
tempfile = "3"
Expand Down
6 changes: 3 additions & 3 deletions sources/api/certdog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::io::{BufRead, Seek};
use std::path::{Path, PathBuf};
use std::process;

use modeled_types::{Identifier, PemCertificateString};
use bottlerocket_modeled_types::{Identifier, PemCertificateString};

// Default location of the config file
const DEFAULT_CONFIG_FILE: &str = "/etc/certdog.toml";
Expand Down Expand Up @@ -304,12 +304,12 @@ type Result<T> = std::result::Result<T, error::Error>;
#[cfg(test)]
mod test_certdog {
use super::*;
use modeled_types::{Identifier, PemCertificateString};
use bottlerocket_modeled_types::{Identifier, PemCertificateString};
use std::collections::HashMap;
use std::convert::TryFrom;
use std::fs::File;

static TEST_PEM: &str = include_str!("../../../models/tests/data/test-pem");
static TEST_PEM: &str = include_str!("../tests/data/test-pem");

#[test]
fn bundles_splitted() {
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion sources/api/corndog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ exclude = ["README.md"]

[dependencies]
log = "0.4"
modeled-types = { path = "../../models/modeled-types", version = "0.1" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
simplelog = "0.12"
snafu = "0.8"
toml = "0.8"

[dependencies.bottlerocket-modeled-types]
git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk"
tag = "bottlerocket-settings-models-v0.1.0"
version = "0.1.0"

[build-dependencies]
generate-readme = { version = "0.1", path = "../../generate-readme" }
2 changes: 1 addition & 1 deletion sources/api/corndog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ It sets kernel-related settings, for example:
* lockdown mode, based on the value of `settings.kernel.lockdown`
*/

use bottlerocket_modeled_types::{Lockdown, SysctlKey};
use log::{debug, error, info, trace, warn};
use modeled_types::{Lockdown, SysctlKey};
use serde::{Deserialize, Serialize};
use simplelog::{Config as LogConfig, LevelFilter, SimpleLogger};
use snafu::ResultExt;
Expand Down
6 changes: 5 additions & 1 deletion sources/api/host-containers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ exclude = ["README.md"]
base64 = "0.21"
constants = { path = "../../constants", version = "0.1" }
log = "0.4"
modeled-types = { path = "../../models/modeled-types", version = "0.1" }
serde = { version = "1", features = ["derive"] }
simplelog = "0.12"
snafu = "0.8"
toml = "0.8"

[dependencies.bottlerocket-modeled-types]
git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk"
tag = "bottlerocket-settings-models-v0.1.0"
version = "0.1.0"

[dev-dependencies]
tempfile = "3"

Expand Down
2 changes: 1 addition & 1 deletion sources/api/host-containers/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use modeled_types::{Identifier, Url, ValidBase64};
use bottlerocket_modeled_types::{Identifier, Url, ValidBase64};
use serde::Deserialize;
use std::collections::HashMap;

Expand Down
4 changes: 2 additions & 2 deletions sources/api/host-containers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::path::{Path, PathBuf};
use std::process::{self, Command};
use std::str::FromStr;

use modeled_types::Identifier;
use bottlerocket_modeled_types::Identifier;

const ENV_FILE_DIR: &str = "/etc/host-containers";
const CONFIG_FILE: &str = "/etc/host-containers/host-containers.toml";
Expand Down Expand Up @@ -496,7 +496,7 @@ fn main() {
#[cfg(test)]
mod test {
use super::*;
use modeled_types::{Identifier, Url, ValidBase64};
use bottlerocket_modeled_types::{Identifier, Url, ValidBase64};

#[test]
fn test_get_host_containers() {
Expand Down
6 changes: 5 additions & 1 deletion sources/api/pluto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ http = "0.2"
hyper = "0.14"
hyper-rustls = { version = "0.24", default-features = false, features = ["http2", "native-tokio", "tls12", "logging"] }
imdsclient = { path = "../../imdsclient", version = "0.1" }
modeled-types = { path = "../../models/modeled-types", version = "0.1" }
aws-config = "1"
aws-sdk-eks = "1"
aws-sdk-ec2 = "1"
Expand All @@ -34,5 +33,10 @@ tokio-rustls = "0.24"
url = "2"
log = "0.4.21"

[dependencies.bottlerocket-modeled-types]
git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk"
tag = "bottlerocket-settings-models-v0.1.0"
version = "0.1.0"

[build-dependencies]
generate-readme = { version = "0.1", path = "../../generate-readme" }
4 changes: 2 additions & 2 deletions sources/api/pluto/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) struct AwsK8sInfo {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) cluster_name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) cluster_dns_ip: Option<modeled_types::KubernetesClusterDnsIp>,
pub(crate) cluster_dns_ip: Option<bottlerocket_modeled_types::KubernetesClusterDnsIp>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) node_ip: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand All @@ -44,7 +44,7 @@ pub(crate) struct Kubernetes {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) cluster_name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) cluster_dns_ip: Option<modeled_types::KubernetesClusterDnsIp>,
pub(crate) cluster_dns_ip: Option<bottlerocket_modeled_types::KubernetesClusterDnsIp>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub(crate) node_ip: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
Expand Down
2 changes: 1 addition & 1 deletion sources/api/pluto/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ mod hyper_proxy;
mod proxy;

use api::AwsK8sInfo;
use bottlerocket_modeled_types::KubernetesClusterDnsIp;
use imdsclient::ImdsClient;
use modeled_types::KubernetesClusterDnsIp;
use snafu::{ensure, OptionExt, ResultExt};
use std::fs::File;
use std::io::{BufRead, BufReader};
Expand Down
6 changes: 5 additions & 1 deletion sources/api/prairiedog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ bytes = "1"
constants = { path = "../../constants", version = "0.1" }
log = "0.4"
nix = "0.26"
modeled-types = { path = "../../models/modeled-types", version = "0.1" }
schnauzer = { path = "../schnauzer", version = "0.1" }
signpost = { path = "../../updater/signpost", version = "0.1" }
simplelog = "0.12"
Expand All @@ -23,6 +22,11 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
toml = "0.8"

[dependencies.bottlerocket-modeled-types]
git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk"
tag = "bottlerocket-settings-models-v0.1.0"
version = "0.1.0"

[dev-dependencies]
maplit = "1"

Expand Down
4 changes: 2 additions & 2 deletions sources/api/prairiedog/src/bootconfig.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::error;
use crate::error::Result;
use crate::initrd::generate_initrd;
use modeled_types::{BootConfigKey, BootConfigValue};
use bottlerocket_modeled_types::{BootConfigKey, BootConfigValue};
use serde::{Deserialize, Serialize};
use snafu::{ensure, ResultExt};
use std::collections::HashMap;
Expand Down Expand Up @@ -352,8 +352,8 @@ mod boot_settings_tests {
boot_config_to_boot_settings_json, boot_settings_change_requires_reboot,
serialize_boot_settings_to_boot_config, DEFAULT_BOOTCONFIG_STR,
};
use bottlerocket_modeled_types::{BootConfigKey, BootConfigValue};
use maplit::hashmap;
use modeled_types::{BootConfigKey, BootConfigValue};
use serde_json::json;
use serde_json::value::Value;
use std::collections::HashMap;
Expand Down
8 changes: 6 additions & 2 deletions sources/api/prairiedog/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ pub(super) enum Error {
InvalidBootConfig,

#[snafu(display("Failed to parse boot config key: {}", source))]
ParseBootConfigKey { source: modeled_types::error::Error },
ParseBootConfigKey {
source: bottlerocket_modeled_types::error::Error,
},

#[snafu(display("Invalid boot config value '{}'. Boot config values may only contain ASCII printable characters except for delimiters such as ';', '\n', ',', '#', and '}}'", input))]
InvalidBootConfigValue { input: String },

#[snafu(display("Failed to parse boot config value: {}", source))]
ParseBootConfigValue { source: modeled_types::error::Error },
ParseBootConfigValue {
source: bottlerocket_modeled_types::error::Error,
},

#[snafu(display("Unsupported boot config key '{}'. `BootSettings` currently only supports boot configuration for 'kernel' and 'init'", key))]
UnsupportedBootConfigKey { key: String },
Expand Down
10 changes: 10 additions & 0 deletions sources/api/schnauzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ tokio = { version = "~1.32", default-features = false, features = ["macros", "rt
toml = "0.8"
url = "2"

[dependencies.bottlerocket-modeled-types]
git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk"
tag = "bottlerocket-settings-models-v0.1.0"
version = "0.1.0"

[dependencies.settings-extension-oci-defaults]
git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk"
tag = "bottlerocket-settings-models-v0.1.0"
version = "0.1.0"

[dev-dependencies]
# Workaround to enable a feature during integration tests.
schnauzer = { path = ".", version = "0.1.0", features = ["testfakes"] }
Expand Down
32 changes: 17 additions & 15 deletions sources/api/schnauzer/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
// text at render time.

use base64::Engine;
use bottlerocket_modeled_types::{OciDefaultsCapability, OciDefaultsResourceLimitType};
use dns_lookup::lookup_host;
use handlebars::{
handlebars_helper, Context, Handlebars, Helper, HelperDef, Output, RenderContext, RenderError,
Renderable,
};
use lazy_static::lazy_static;
use model::modeled_types::{OciDefaultsCapability, OciDefaultsResourceLimitType};
use model::OciDefaultsResourceLimit;
use serde::Deserialize;
use serde_json::value::Value;
use serde_plain::derive_fromstr_from_deserialize;
use settings_extension_oci_defaults::OciDefaultsResourceLimitV1;
use snafu::{OptionExt, ResultExt};
use std::borrow::Borrow;
use std::collections::HashMap;
Expand Down Expand Up @@ -1269,7 +1269,7 @@ pub fn localhost_aliases(

let mut results: Vec<String> = vec![];

let hosts: Option<model::modeled_types::EtcHostsEntries> = (!hosts_value.is_null())
let hosts: Option<bottlerocket_modeled_types::EtcHostsEntries> = (!hosts_value.is_null())
.then(|| {
serde_json::from_value(hosts_value.clone()).context(
error::UnparseableTemplateValueSnafu {
Expand Down Expand Up @@ -1348,12 +1348,14 @@ pub fn etc_hosts_entries(
// Otherwise we need to generate /etc/hosts lines, ignoring loopback.
let mut result_lines: Vec<String> = Vec::new();

let hosts: model::modeled_types::EtcHostsEntries = serde_json::from_value(hosts_value.clone())
.context(error::UnparseableTemplateValueSnafu {
expected: "EtcHostsEntries",
value: hosts_value.to_owned(),
template: template_name.to_owned(),
})?;
let hosts: bottlerocket_modeled_types::EtcHostsEntries = serde_json::from_value(
hosts_value.clone(),
)
.context(error::UnparseableTemplateValueSnafu {
expected: "EtcHostsEntries",
value: hosts_value.to_owned(),
template: template_name.to_owned(),
})?;
trace!("Hosts from template: {:?}", hosts);

hosts
Expand Down Expand Up @@ -1571,7 +1573,7 @@ impl Runtime {
fn get_resource_limits(
&self,
rlimit_type: &OciDefaultsResourceLimitType,
values: &OciDefaultsResourceLimit,
values: &OciDefaultsResourceLimitV1,
) -> String {
match self {
Self::Docker => Docker::get_resource_limits(rlimit_type, values),
Expand All @@ -1592,7 +1594,7 @@ impl Docker {
/// Formats resource limits for Docker
fn get_resource_limits(
rlimit_type: &OciDefaultsResourceLimitType,
values: &OciDefaultsResourceLimit,
values: &OciDefaultsResourceLimitV1,
) -> String {
format!(
r#" "{}":{{ "Name": "{}", "Hard": {}, "Soft": {} }}"#,
Expand Down Expand Up @@ -1634,7 +1636,7 @@ impl Containerd {
/// Formats resource limits for Containerd
fn get_resource_limits(
rlimit_type: &OciDefaultsResourceLimitType,
values: &OciDefaultsResourceLimit,
values: &OciDefaultsResourceLimitV1,
) -> String {
format!(
r#"{{ "type": "{}", "hard": {}, "soft": {} }}"#,
Expand Down Expand Up @@ -1777,7 +1779,7 @@ fn oci_spec_capabilities(value: &Value) -> Result<String, RenderError> {
/// the settings data from the datastore (`settings.oci-defaults.resource-limits`).
fn oci_spec_resource_limits(
value: &Value,
) -> Result<HashMap<OciDefaultsResourceLimitType, OciDefaultsResourceLimit>, RenderError> {
) -> Result<HashMap<OciDefaultsResourceLimitType, OciDefaultsResourceLimitV1>, RenderError> {
Ok(serde_json::from_value(value.clone())?)
}

Expand Down Expand Up @@ -1921,7 +1923,7 @@ fn kube_cpu_helper(num_cores: usize) -> Result<String, TemplateHelperError> {
/// If `configured_hosts` is set, the hostname will be considered resolvable if it is listed as an alias for any given IP address.
fn hostname_resolveable(
hostname: &str,
configured_hosts: Option<&model::modeled_types::EtcHostsEntries>,
configured_hosts: Option<&bottlerocket_modeled_types::EtcHostsEntries>,
) -> bool {
// If the hostname is in our configured hosts, then it *will* be resolvable when /etc/hosts is rendered.
// Note that DNS search paths in /etc/resolv.conf are not relevant here, as they are not checked when searching /etc/hosts.
Expand Down Expand Up @@ -2842,7 +2844,7 @@ mod test_etc_hosts_helpers {
assert!(hostname_resolveable(
"unresolveable.irrelevanthostname.tld",
Some(
&serde_json::from_str::<model::modeled_types::EtcHostsEntries>(
&serde_json::from_str::<bottlerocket_modeled_types::EtcHostsEntries>(
r#"[["10.0.0.1", ["unresolveable.irrelevanthostname.tld"]]]"#
)
.unwrap()
Expand Down
5 changes: 5 additions & 0 deletions sources/api/simple-settings-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ serde_json = "1.0.116"
git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk"
tag = "bottlerocket-settings-plugin-v0.1.0"
version = "0.1.0"

[dependencies.bottlerocket-settings-models]
git = "https://github.com/bottlerocket-os/bottlerocket-settings-sdk"
tag = "bottlerocket-settings-models-v0.1.0"
version = "0.1.0"
Loading

0 comments on commit a2fdb43

Please sign in to comment.