Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
*: cleanup redundant code imported from Afterburn
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Bai committed Oct 9, 2019
1 parent da6a36c commit 97f3a1d
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 816 deletions.
16 changes: 2 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
//! Telemetry service for FCOS.

extern crate base64;
#[macro_use]
extern crate error_chain;
extern crate openssh_keys;
extern crate openssl;
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
extern crate serde_xml_rs;
#[macro_use]
extern crate slog;
extern crate slog_async;
extern crate slog_term;
#[macro_use]
extern crate slog_scope;

#[cfg(test)]
Expand All @@ -24,14 +13,13 @@ extern crate mockito;
mod config;
/// `Minimal` Agent identity.
mod minimal;
/// Provider metadata
mod providers;
/// Generic retrying function
mod retry;
// mod retry;
/// A library for consistent and reliable error handling
mod errors;
/// rpm-ostree client.
mod rpm_ostree;
mod util;

use clap::{Arg, crate_authors, crate_description, crate_name, crate_version};
use config::inputs;
Expand Down
9 changes: 9 additions & 0 deletions src/minimal/instance_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Cloud instance type parsing - utility functions

/// Call Afterburn to retrieve metadata from cloud providers
pub(crate) fn fetch_metadata() -> Fallible<String>
where
T: AsRef<str>,
{

}
3 changes: 1 addition & 2 deletions src/minimal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod platform;
mod os_release;

use crate::config::inputs;
use crate::errors::*;
use crate::rpm_ostree;
use failure::{Fallible, ResultExt};
use serde::Serialize;
Expand Down Expand Up @@ -41,7 +40,7 @@ impl Identity {

/// Try to fetch default data
pub fn try_default(level: &str) -> Fallible<Self> {
let platform = platform::read_id(KERNEL_ARGS_FILE)?;
let platform = platform::get_platform(KERNEL_ARGS_FILE)?;
let original_os_version = os_release::read_original_os_version(OS_ALEPH_VERSION_FILE)?;
let current_os_version = rpm_ostree::booted()?.version;

Expand Down
5 changes: 2 additions & 3 deletions src/minimal/os_release.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! OS version parsing - utility functions

use failure::{bail, format_err, Fallible, ResultExt};
use std::io::Read;
use std::{fs, io};
use failure::{format_err, Fallible, ResultExt};
use std::fs;
use serde_json;

/// Read aleph version info from os version json file.
Expand Down
42 changes: 10 additions & 32 deletions src/minimal/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
use failure::{bail, format_err, Fallible, ResultExt};
use std::io::Read;
use std::{fs, io};
use crate::util;

/// Platform key.
static CMDLINE_PLATFORM_FLAG: &str = "ignition.platform.id";
#[cfg(not(feature = "cl-legacy"))]
const CMDLINE_PLATFORM_FLAG: &str = "ignition.platform.id";
/// Platform key (CL and RHCOS legacy name: "OEM").
#[cfg(feature = "cl-legacy")]
const CMDLINE_PLATFORM_FLAG: &str = "coreos.oem.id";

/// Read platform value from cmdline file.
pub(crate) fn read_id<T>(cmdline_path: T) -> Fallible<String>
pub(crate) fn get_platform<T>(cmdline_path: T) -> Fallible<String>
where
T: AsRef<str>,
{
Expand All @@ -31,11 +36,11 @@ where
.with_context(|e| format_err!("failed to read cmdline file {}: {}", fpath, e))?;

// lookup flag by key name
match find_flag_value(CMDLINE_PLATFORM_FLAG, &contents) {
match util::find_flag_value(CMDLINE_PLATFORM_FLAG, &contents) {
Some(platform) => {
log::trace!("found platform id: {}", platform);
Ok(platform)
}
},
None => bail!(
"could not find flag '{}' in {}",
CMDLINE_PLATFORM_FLAG,
Expand All @@ -44,33 +49,6 @@ where
}
}

/// Find OEM ID flag value in cmdline string.
fn find_flag_value(flagname: &str, cmdline: &str) -> Option<String> {
// split content into elements and keep key-value tuples only.
let params: Vec<(&str, &str)> = cmdline
.split(' ')
.filter_map(|s| {
let kv: Vec<&str> = s.splitn(2, '=').collect();
match kv.len() {
2 => Some((kv[0], kv[1])),
_ => None,
}
})
.collect();

// find the oem flag
for (key, val) in params {
if key != flagname {
continue;
}
let bare_val = val.trim();
if !bare_val.is_empty() {
return Some(bare_val.to_string());
}
}
None
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -90,7 +68,7 @@ mod tests {
("ignition.platform.id=ec2 foo=bar", Some("ec2".to_string())),
];
for (tcase, tres) in tests {
let res = find_flag_value(flagname, tcase);
let res = util::find_flag_value(flagname, tcase);
assert_eq!(res, tres, "failed testcase: '{}'", tcase);
}
}
Expand Down
28 changes: 0 additions & 28 deletions src/providers/aws/mock_tests.rs

This file was deleted.

85 changes: 0 additions & 85 deletions src/providers/aws/mod.rs

This file was deleted.

36 changes: 0 additions & 36 deletions src/providers/mod.rs

This file was deleted.

Loading

0 comments on commit 97f3a1d

Please sign in to comment.