summaryrefslogtreecommitdiff
path: root/src/cloudinit.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-01-24 13:47:31 +0200
committerLars Wirzenius <liw@liw.fi>2021-01-24 13:47:31 +0200
commite6455df900d71826b04d33fba358f0c91e54eec3 (patch)
treeba8e49e791b536c354945c0773a103a7ed10e590 /src/cloudinit.rs
downloadvmadm-e6455df900d71826b04d33fba358f0c91e54eec3.tar.gz
feat: add initial CloudInitConfig
Diffstat (limited to 'src/cloudinit.rs')
-rw-r--r--src/cloudinit.rs51
1 files changed, 51 insertions, 0 deletions
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");
+ }
+}