Skip to content

Commit

Permalink
clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
sebt3 committed Nov 15, 2024
1 parent f5de489 commit 7d39ba3
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 247 deletions.
10 changes: 7 additions & 3 deletions agent/scripts/lib/build_context.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// https://github.com/storageclass/storageclass.github.io/blob/main/data/csidrivers.yaml
fn get_prefered_sc(scs) {
let pref = #{
"many_block": (),
"many_safe": (),
"many_cheap": (),
"many_only": (),
"only_block": (),
"only_performance": (),
"only_cheap": (),
"only_safe": (),
Expand All @@ -25,16 +27,18 @@ fn get_prefered_sc(scs) {
pref["only_cheap"] = lp;
}
if scs.some(|s| s.provisioner.ends_with("nfs.csi.ceph.com")) {
let nfs = scs.find(|s| s.provisioner.ends_with("nfs.csi.ceph.com")) .name;
let nfs = scs.find(|s| s.provisioner.ends_with("nfs.csi.ceph.com")).name;
pref["many_safe"] = nfs;
pref["many_cheap"] = nfs;
}
if scs.some(|s| s.provisioner.ends_with("cephfs.csi.ceph.com")) {
let cfs = scs.find(|s| s.provisioner.ends_with("cephfs.csi.ceph.com")) .name;
let cfs = scs.find(|s| s.provisioner.ends_with("cephfs.csi.ceph.com")).name;
pref["many_safe"] = cfs;
}
if scs.some(|s| s.provisioner.ends_with("rbd.csi.ceph.com")) {
let rbd = scs.find(|s| s.provisioner.ends_with("rbd.csi.ceph.com")) .name;
let rbd = scs.find(|s| s.provisioner.ends_with("rbd.csi.ceph.com")).name;
pref["many_block"] = rbd;
pref["only_block"] = rbd;
pref["only_safe"] = rbd;
pref["many_only"] = rbd;
}
Expand Down
18 changes: 9 additions & 9 deletions common/src/handlebarshandler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tracing::*;
handlebars_helper!(base64_decode: |arg:Value| String::from_utf8(STANDARD.decode(arg.as_str().unwrap_or_else(|| {
warn!("handlebars::base64_decode received a non-string parameter: {:?}",arg);
""
}).to_string()).unwrap_or_else(|e| {
})).unwrap_or_else(|e| {
warn!("handlebars::base64_decode failed to decode with: {e:?}");
vec![]
})).unwrap_or_else(|e| {
Expand All @@ -23,7 +23,7 @@ handlebars_helper!(base64_decode: |arg:Value| String::from_utf8(STANDARD.decode(
handlebars_helper!(base64_encode: |arg:Value| STANDARD.encode(arg.as_str().unwrap_or_else(|| {
warn!("handlebars::base64_encode received a non-string parameter: {:?}",arg);
""
}).to_string()));
})));
handlebars_helper!(header_basic: |username:Value, password:Value| format!("Basic {}",STANDARD.encode(format!("{}:{}",username.as_str().unwrap_or_else(|| {
warn!("handlebars::header_basic received a non-string username: {:?}",username);
""
Expand All @@ -42,7 +42,7 @@ handlebars_helper!(gen_password: |len:u32| Passwords::new().generate(len, 6, 2,
handlebars_helper!(gen_password_alphanum: |len:u32| Passwords::new().generate(len, 8, 2, 0));
handlebars_helper!(selector: |ctx: Value, {comp:str=""}| {
let mut sel = ctx.as_object().unwrap()["instance"].as_object().unwrap()["selector"].as_object().unwrap().clone();
if comp != "" {
if !comp.is_empty() {
sel.insert("app.kubernetes.io/componant".into(), Value::from(comp));
}
sel
Expand All @@ -51,7 +51,7 @@ handlebars_helper!(labels: |ctx: Value| {
ctx.as_object().unwrap()["instance"].as_object().unwrap()["labels"].clone()
});
handlebars_helper!(have_crd: |ctx: Value, name: String| {
ctx.as_object().unwrap()["cluster"].as_object().unwrap()["crds"].as_array().unwrap().into_iter().any(|crd| crd.to_string()==name)
ctx.as_object().unwrap()["cluster"].as_object().unwrap()["crds"].as_array().unwrap().iter().any(|crd| *crd==name)
});

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -89,7 +89,7 @@ impl HandleBars<'_> {
pub fn register_template(&mut self, name: &str, template: &str) -> Result<()> {
self.engine
.register_template_string(name, template)
.map_err(|e| Error::HbsTemplateError(e))
.map_err(Error::HbsTemplateError)
}

pub fn rhai_register_template(&mut self, name: String, template: String) -> RhaiRes<()> {
Expand Down Expand Up @@ -118,7 +118,7 @@ impl HandleBars<'_> {

pub fn rhai_register_helper_dir(&mut self, directory: String) -> RhaiRes<()> {
self.register_helper_dir(PathBuf::from(directory))
.map_err(|e| rhai_err(e))
.map_err(rhai_err)
}

pub fn register_partial_dir(&mut self, directory: PathBuf) -> Result<()> {
Expand All @@ -129,7 +129,7 @@ impl HandleBars<'_> {
let filename = path.file_name().unwrap().to_str().unwrap();
if re_rhai.is_match(filename) {
let name = filename[0..(filename.len() - 4)].to_string();
let tmpl = std::fs::read_to_string(path).map_err(|e| Error::Stdio(e))?;
let tmpl = std::fs::read_to_string(path).map_err(Error::Stdio)?;
tracing::debug!("registering {}", name);
self.register_template(&name, &tmpl)?;
}
Expand All @@ -142,13 +142,13 @@ impl HandleBars<'_> {

pub fn rhai_register_partial_dir(&mut self, directory: String) -> RhaiRes<()> {
self.register_partial_dir(PathBuf::from(directory))
.map_err(|e| rhai_err(e))
.map_err(rhai_err)
}

pub fn render(&mut self, template: &str, data: &Value) -> Result<String> {
self.engine
.render_template(template, data)
.map_err(|e| Error::HbsRenderError(e))
.map_err(Error::HbsRenderError)
}

pub fn rhai_render(&mut self, template: String, data: rhai::Map) -> RhaiRes<String> {
Expand Down
6 changes: 6 additions & 0 deletions common/src/hasheshandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pub struct Argon {
salt: SaltString,
argon: Argon2<'static>,
}
impl Default for Argon {
fn default() -> Self {
Self::new()
}
}

impl Argon {
#[must_use]
pub fn new() -> Self {
Expand Down
Loading

0 comments on commit 7d39ba3

Please sign in to comment.