Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model: Use SingleLineString for all appropriate Strings #453

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions workspaces/api/apiserver/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use crate::modeled_types::{SingleLineString, ValidBase64};
#[serde(deny_unknown_fields, rename = "settings", rename_all = "kebab-case")]
pub struct Settings {
#[serde(skip_serializing_if = "Option::is_none")]
pub timezone: Option<String>,
pub timezone: Option<SingleLineString>,

#[serde(skip_serializing_if = "Option::is_none")]
pub hostname: Option<String>,
pub hostname: Option<SingleLineString>,

#[serde(skip_serializing_if = "Option::is_none")]
pub kubernetes: Option<KubernetesSettings>,
Expand All @@ -47,13 +47,13 @@ pub struct KubernetesSettings {
// Settings we require the user to specify, likely via user data.

#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_name: Option<String>,
pub cluster_name: Option<SingleLineString>,

#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_certificate: Option<ValidBase64>,

#[serde(skip_serializing_if = "Option::is_none")]
pub api_server: Option<String>,
pub api_server: Option<SingleLineString>,

#[serde(skip_serializing_if = "Option::is_none")]
pub node_labels: Option<HashMap<SingleLineString, SingleLineString>>,
Expand All @@ -64,7 +64,7 @@ pub struct KubernetesSettings {
// Dynamic settings.

#[serde(skip_serializing_if = "Option::is_none")]
pub max_pods: Option<String>,
pub max_pods: Option<SingleLineString>,

#[serde(skip_serializing_if = "Option::is_none")]
pub cluster_dns_ip: Option<Ipv4Addr>,
Expand All @@ -73,7 +73,7 @@ pub struct KubernetesSettings {
pub node_ip: Option<Ipv4Addr>,

#[serde(skip_serializing_if = "Option::is_none")]
pub pod_infra_container_image: Option<String>,
pub pod_infra_container_image: Option<SingleLineString>,
}

// Updog settings. Taken from userdata. The 'seed' setting is generated
Expand All @@ -82,10 +82,10 @@ pub struct KubernetesSettings {
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub struct UpdatesSettings {
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata_base_url: Option<String>,
pub metadata_base_url: Option<SingleLineString>,

#[serde(skip_serializing_if = "Option::is_none")]
pub target_base_url: Option<String>,
pub target_base_url: Option<SingleLineString>,

#[serde(skip_serializing_if = "Option::is_none")]
pub seed: Option<u32>,
Expand All @@ -109,7 +109,7 @@ pub struct ContainerImage {
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
pub struct NtpSettings {
#[serde(skip_serializing_if = "Option::is_none")]
pub time_servers: Option<Vec<String>>,
pub time_servers: Option<Vec<SingleLineString>>,
}

///// Internal services
Expand All @@ -126,7 +126,7 @@ pub type Services = HashMap<String, Service>;
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields, rename = "", rename_all = "kebab-case")]
pub struct Service {
pub configuration_files: Vec<String>,
pub configuration_files: Vec<SingleLineString>,
pub restart_commands: Vec<String>,
}

Expand All @@ -135,16 +135,16 @@ pub type ConfigurationFiles = HashMap<String, ConfigurationFile>;
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields, rename = "", rename_all = "kebab-case")]
pub struct ConfigurationFile {
pub path: String,
pub template_path: String,
pub path: SingleLineString,
pub template_path: SingleLineString,
}

///// Metadata

#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields, rename = "metadata", rename_all = "kebab-case")]
pub struct Metadata {
pub key: String,
pub md: String,
pub key: SingleLineString,
pub md: SingleLineString,
pub val: toml::Value,
}
12 changes: 12 additions & 0 deletions workspaces/api/apiserver/src/modeled_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ impl fmt::Display for ValidBase64 {
}
}

impl From<ValidBase64> for String {
fn from(x: ValidBase64) -> Self {
x.inner
}
}

#[cfg(test)]
mod test_valid_base64 {
use super::ValidBase64;
Expand Down Expand Up @@ -176,6 +182,12 @@ impl fmt::Display for SingleLineString {
}
}

impl From<SingleLineString> for String {
fn from(x: SingleLineString) -> Self {
x.inner
}
}

#[cfg(test)]
mod test_single_line_string {
use super::SingleLineString;
Expand Down
4 changes: 2 additions & 2 deletions workspaces/api/thar-be-settings/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ pub fn build_template_registry(
&name, &metadata.template_path
);
template_registry
.register_template_file(&name, &metadata.template_path)
.register_template_file(&name, metadata.template_path.as_ref())
.context(error::TemplateRegister {
name: name.as_str(),
path: &metadata.template_path,
path: metadata.template_path.as_ref(),
})?;
}

Expand Down