diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-01-24 13:47:31 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-01-24 13:47:31 +0200 |
commit | e6455df900d71826b04d33fba358f0c91e54eec3 (patch) | |
tree | ba8e49e791b536c354945c0773a103a7ed10e590 | |
download | vmadm-e6455df900d71826b04d33fba358f0c91e54eec3.tar.gz |
feat: add initial CloudInitConfig
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Cargo.toml | 9 | ||||
-rw-r--r-- | src/cloudinit.rs | 51 | ||||
-rw-r--r-- | src/lib.rs | 1 |
4 files changed, 63 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96ef6c0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..fac79e6 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "vmadm" +version = "0.1.0" +authors = ["Lars Wirzenius <liw@liw.fi>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/cloudinit.rs b/src/cloudinit.rs new file mode 100644 index 0000000..de256d8 --- /dev/null +++ b/src/cloudinit.rs @@ -0,0 +1,51 @@ +use std::default::Default; + +#[derive(Default, Debug)] +pub struct CloudInitConfig { + hostname: String, + authorized_keys: String, +} + +impl CloudInitConfig { + pub fn hostname(&self) -> &str { + &self.hostname + } + + pub fn set_hostname(&mut self, hostname: &str) { + self.hostname = hostname.to_string(); + } + + pub fn authorized_keys(&self) -> &str { + &self.authorized_keys + } + + pub fn set_authorized_keys(&mut self, keys: &str) { + self.authorized_keys = keys.to_string(); + } +} + +#[cfg(test)] +mod test { + use super::CloudInitConfig; + + #[test] + fn is_empty_by_default() { + let init = CloudInitConfig::default(); + assert_eq!(init.hostname(), ""); + assert_eq!(init.authorized_keys(), ""); + } + + #[test] + fn sets_hostname() { + let mut init = CloudInitConfig::default(); + init.set_hostname("foo"); + assert_eq!(init.hostname(), "foo"); + } + + #[test] + fn sets_authorized_keys() { + let mut init = CloudInitConfig::default(); + init.set_authorized_keys("auth"); + assert_eq!(init.authorized_keys(), "auth"); + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..3766a04 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod cloudinit; |