Skip to content

Commit

Permalink
Add filtering for ansible managed line
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasDeBruijn committed Sep 10, 2024
1 parent 85fa1f0 commit 8f49446
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 9 additions & 3 deletions server/src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ pub trait DataFile: Default + Serialize + DeserializeOwned {
}

let mut f = fs::File::open(from).await?;
let mut buf = Vec::new();
f.read_to_end(&mut buf).await?;
let mut buf = String::new();
f.read_to_string(&mut buf).await?;

Ok(serde_json::from_slice(&buf)?)
// Remove comments, e.g. 'Ansible Managed'
let buf = buf
.lines()
.filter(|v| !v.starts_with("#"))
.collect::<String>();

Ok(serde_json::from_str(&buf)?)
}

async fn try_write_new<P: AsRef<Path>>(to: P) -> Result<(), DataFileError> {
Expand Down
18 changes: 6 additions & 12 deletions server/src/server/types/authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ impl<const ADMIN: bool> FromRequest for Authorization<ADMIN> {
return if Self::ADMIN {
Err(AuthorizationError::NoToken)
} else {
Ok(Self {
is_admin: false,
})
Ok(Self { is_admin: false })
}
},
}
};

let config: &WConfig = req.app_data().unwrap();
Expand All @@ -65,20 +63,16 @@ impl<const ADMIN: bool> FromRequest for Authorization<ADMIN> {
if Self::ADMIN {
Err(AuthorizationError::NoToken)
} else {
Ok(Self {
is_admin: false,
})
Ok(Self { is_admin: false })
}
},
}
_ => {
if Self::ADMIN {
Err(AuthorizationError::Koala)
} else {
Ok(Self {
is_admin: false,
})
Ok(Self { is_admin: false })
}
},
}
}
}
};
Expand Down

0 comments on commit 8f49446

Please sign in to comment.