clippy
Diff
chartered-db/src/crates.rs | 6 +++---
chartered-db/src/lib.rs | 3 ++-
chartered-db/src/users.rs | 3 ++-
chartered-db/src/uuid.rs | 2 +-
chartered-fs/src/lib.rs | 10 +++++-----
chartered-git/src/generators.rs | 6 +++---
chartered-git/src/main.rs | 20 +++++++++++---------
chartered-git/src/tree.rs | 8 +++++---
chartered-types/src/cargo.rs | 10 +++++++++-
chartered-types/src/lib.rs | 3 +++
chartered-web/src/main.rs | 1 +
chartered-git/src/command_handlers/fetch.rs | 2 +-
chartered-git/src/command_handlers/ls_refs.rs | 2 +-
chartered-git/src/command_handlers/mod.rs | 2 ++
chartered-git/src/git/packfile/high_level.rs | 32 +++++++++++++++++++++-----------
chartered-web/src/endpoints/cargo_api/publish.rs | 5 +++--
chartered-web/src/endpoints/web_api/auth/openid.rs | 11 +++++++----
chartered-web/src/endpoints/web_api/crates/search.rs | 7 +++----
18 files changed, 78 insertions(+), 55 deletions(-)
@@ -349,7 +349,7 @@
Ok(CrateVersion::belonging_to(&self.crate_)
.order_by(crate_versions::id.desc())
.limit(1)
.get_result::<CrateVersion>(&conn)
.get_result::<CrateVersion<'_>>(&conn)
.optional()?)
})
.await?
@@ -367,7 +367,7 @@
Ok(CrateVersion::belonging_to(&self.crate_)
.filter(version.eq(crate_version))
.get_result::<CrateVersion>(&conn)
.get_result::<CrateVersion<'_>>(&conn)
.optional()?)
})
.await?
@@ -382,7 +382,7 @@
Ok(CrateVersion::belonging_to(&self.crate_)
.inner_join(users::table)
.load::<(CrateVersion, User)>(&conn)?)
.load::<(CrateVersion<'_>, User)>(&conn)?)
})
.await?
}
@@ -1,4 +1,5 @@
#![deny(clippy::pedantic)]
#![deny(rust_2018_idioms)]
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::doc_markdown)]
@@ -21,7 +22,7 @@
{
fn to_sql<W: std::io::Write>(
&self,
out: &mut diesel::serialize::Output<W, B>,
out: &mut diesel::serialize::Output<'_, W, B>,
) -> diesel::serialize::Result {
serde_json::to_writer(out, self)
.map(|_| diesel::serialize::IsNull::No)
@@ -276,10 +276,11 @@
.permissions)
}
#[must_use]
pub fn display_name(&self) -> &str {
self.nick
.as_ref()
.or(self.name.as_ref())
.or_else(|| self.name.as_ref())
.unwrap_or(&self.username)
}
}
@@ -45,7 +45,7 @@
{
fn to_sql<W: Write>(
&self,
out: &mut diesel::serialize::Output<W, B>,
out: &mut diesel::serialize::Output<'_, W, B>,
) -> diesel::serialize::Result {
out.write_all(self.0.as_bytes())
.map(|_| diesel::serialize::IsNull::No)
@@ -1,4 +1,5 @@
#![deny(clippy::pedantic)]
#![deny(rust_2018_idioms)]
use std::path::PathBuf;
@@ -35,7 +36,7 @@
Self::S3 {
host: uri.host().unwrap().to_string(),
bucket: path.next().unwrap().to_string(),
path: path.intersperse("/").collect(),
path: Itertools::intersperse(path, "/").collect(),
}
}
"file" => {
@@ -53,7 +54,7 @@
}
impl std::fmt::Display for FileSystemKind {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Local => f.write_str("local"),
Self::S3 => f.write_str("s3"),
@@ -82,7 +83,7 @@
}
impl std::fmt::Display for FileReference {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}:{}", self.file_system, self.reference)
}
}
@@ -145,8 +146,7 @@
#[cfg(test)]
mod tests {
use super::{FileSystem, FS};
use std::str::FromStr;
use super::FileSystem;
#[tokio::test]
#[allow(clippy::pedantic)]
@@ -7,7 +7,7 @@
}
impl CargoConfig {
pub fn new(base: url::Url, api_key: &str, organisation: &str) -> Self {
pub fn new(base: &url::Url, api_key: &str, organisation: &str) -> Self {
let base = format!("{}a/{}/o/{}", base, api_key, organisation);
Self {
@@ -29,11 +29,11 @@
"my-organisation",
);
assert_eq!(
conf.dl.to_string(),
conf.dl,
"https://127.0.0.1:1234/a/my-api-key/o/my-organisation/api/v1/crates"
);
assert_eq!(
conf.api.to_string(),
conf.api,
"https://127.0.0.1:1234/a/my-api-key/o/my-organisation"
);
}
@@ -1,4 +1,5 @@
#![deny(clippy::pedantic)]
#![deny(rust_2018_idioms)]
mod command_handlers;
mod generators;
mod tree;
@@ -26,7 +27,7 @@
};
use thrussh_keys::{key, PublicKeyBase64};
use tokio_util::codec::{Decoder, Encoder as TokioEncoder};
use tracing::{debug, error, event, info, warn, Instrument};
use tracing::{debug, error, info, warn, Instrument};
use url::Url;
#[tokio::main]
@@ -151,6 +152,7 @@
) -> Self::FutureUnit {
self.span.in_scope(|| debug!("env set {}={}", name, value));
#[allow(clippy::single_match)]
match (name, value) {
("GIT_PROTOCOL", "version=2") => self.is_git_protocol_v2 = true,
_ => {}
@@ -274,7 +276,7 @@
self,
_user: &str,
_submethods: &str,
_response: Option<server::Response>,
_response: Option<server::Response<'_>>,
) -> Self::FutureAuth {
self.finished_auth(server::Auth::UnsupportedMethod)
}
@@ -313,20 +315,20 @@
let mut packfile = GitRepository::default();
let config = CargoConfig::new(
Url::parse("http://127.0.0.1:8888/")?,
&Url::parse("http://127.0.0.1:8888/")?,
&authed.auth_key,
org_name,
);
let config = serde_json::to_vec(&config)?;
packfile.insert(ArrayVec::<_, 0>::new(), "config.json", &config);
packfile.insert(ArrayVec::<_, 0>::new(), "config.json", &config)?;
let tree =
Tree::build(self.db.clone(), authed.user.id, org_name.to_string()).await;
tree.write_to_packfile(&mut packfile);
tree.write_to_packfile(&mut packfile)?;
let (commit_hash, packfile_entries) =
packfile.commit("computer", "john@computer.no", "Update crates");
packfile.commit("computer", "john@computer.no", "Update crates")?;
match frame.command.as_ref() {
b"command=ls-refs" => {
@@ -336,8 +338,7 @@
channel,
frame.metadata,
&commit_hash,
)
.await?
)?;
}
b"command=fetch" => {
command_handlers::fetch::handle(
@@ -346,8 +347,7 @@
channel,
frame.metadata,
packfile_entries,
)
.await?
)?;
}
v => {
error!(
@@ -49,11 +49,13 @@
Self { crates }
}
pub fn write_to_packfile<'a>(&'a self, repo: &mut GitRepository<'a>) {
pub fn write_to_packfile<'a>(&'a self, repo: &mut GitRepository<'a>) -> Result<(), anyhow::Error> {
for (name, content) in &self.crates {
let crate_folder = get_crate_folder(&name);
repo.insert(crate_folder, &name, content.as_bytes());
let crate_folder = get_crate_folder(name);
repo.insert(crate_folder, name, content.as_bytes())?;
}
Ok(())
}
}
@@ -1,3 +1,5 @@
#![deny(clippy::pedantic)]
@@ -17,11 +19,16 @@
}
impl CrateVersion<'_> {
#[must_use]
pub fn into_owned(self) -> CrateVersion<'static> {
CrateVersion {
name: Cow::Owned(self.name.into_owned()),
vers: Cow::Owned(self.vers.into_owned()),
deps: self.deps.into_iter().map(|v| v.into_owned()).collect(),
deps: self
.deps
.into_iter()
.map(CrateDependency::into_owned)
.collect(),
features: self.features,
links: self.links.map(|v| Cow::Owned(v.into_owned())),
}
@@ -53,6 +60,7 @@
}
impl CrateDependency<'_> {
#[must_use]
pub fn into_owned(self) -> CrateDependency<'static> {
CrateDependency {
name: Cow::Owned(self.name.into_owned()),
@@ -1,1 +1,4 @@
#![deny(clippy::pedantic)]
#![deny(rust_2018_idioms)]
pub mod cargo;
@@ -1,4 +1,5 @@
#![deny(clippy::pedantic)]
#![deny(rust_2018_idioms)]
#![allow(clippy::module_name_repetitions)]
mod config;
@@ -9,7 +9,7 @@
Handler,
};
pub(crate) async fn handle(
pub(crate) fn handle(
handle: &mut Handler,
session: &mut Session,
channel: ChannelId,
@@ -12,7 +12,7 @@
Handler,
};
pub(crate) async fn handle(
pub(crate) fn handle(
handle: &mut Handler,
session: &mut Session,
channel: ChannelId,
@@ -1,2 +1,4 @@
#![allow(clippy::needless_pass_by_value)]
pub mod fetch;
pub mod ls_refs;
@@ -9,32 +9,32 @@
pub struct Directory<'a>(IndexMap<&'a str, Box<TreeItem<'a>>>);
impl<'a> Directory<'a> {
fn into_packfile_entries(
fn to_packfile_entries(
&self,
pack_file: &mut IndexMap<HashOutput, PackFileEntry<'a>>,
) -> HashOutput {
) -> Result<HashOutput, anyhow::Error> {
let mut tree = Vec::with_capacity(self.0.len());
for (name, item) in &self.0 {
tree.push(match item.as_ref() {
TreeItem::Blob(hash) => LowLevelTreeItem {
kind: TreeItemKind::File,
name: &name,
name,
hash: *hash,
},
TreeItem::Directory(dir) => LowLevelTreeItem {
kind: TreeItemKind::Directory,
name: &name,
hash: dir.into_packfile_entries(pack_file),
name,
hash: dir.to_packfile_entries(pack_file)?,
},
})
});
}
let tree = PackFileEntry::Tree(tree);
let hash = tree.hash().unwrap();
let hash = tree.hash()?;
pack_file.insert(hash, tree);
hash
Ok(hash)
}
}
@@ -56,7 +56,7 @@
path: ArrayVec<&'a str, N>,
file: &'a str,
content: &'a [u8],
) {
) -> Result<(), anyhow::Error> {
let mut directory = &mut self.tree;
for part in path {
@@ -68,18 +68,20 @@
if let TreeItem::Directory(d) = tree_item.as_mut() {
directory = d;
} else {
panic!("one of the path items was a blob");
anyhow::bail!("one of the path items was a blob");
}
}
let entry = PackFileEntry::Blob(content);
let file_hash = entry.hash().unwrap();
let file_hash = entry.hash()?;
directory
.0
.insert(file, Box::new(TreeItem::Blob(file_hash)));
self.file_entries.insert(file_hash, entry);
Ok(())
}
pub fn commit(
@@ -87,8 +89,8 @@
name: &'static str,
email: &'static str,
message: &'static str,
) -> (HashOutput, Vec<PackFileEntry<'a>>) {
let tree_hash = self.tree.into_packfile_entries(&mut self.file_entries);
) -> Result<(HashOutput, Vec<PackFileEntry<'a>>), anyhow::Error> {
let tree_hash = self.tree.to_packfile_entries(&mut self.file_entries)?;
let commit_user = CommitUserInfo {
name,
@@ -103,10 +105,10 @@
message,
});
let commit_hash = commit.hash().unwrap();
let commit_hash = commit.hash()?;
self.file_entries.insert(commit_hash, commit);
(commit_hash, self.file_entries.values().cloned().collect())
Ok((commit_hash, self.file_entries.values().cloned().collect()))
}
}
@@ -71,7 +71,7 @@
) -> Result<axum::response::Json<PublishCrateResponse>, Error> {
let (_, (metadata_bytes, crate_bytes)) =
parse(body.as_ref()).map_err(|_| Error::MetadataParse)?;
let metadata: Metadata = serde_json::from_slice(metadata_bytes)?;
let metadata: Metadata<'_> = serde_json::from_slice(metadata_bytes)?;
if !validate_crate_name(&metadata.inner.name) {
return Err(Error::InvalidCrateName);
@@ -177,7 +177,7 @@
}
}
#[derive(Deserialize, Debug)]
pub struct MetadataCrateDependency<'a> {
@@ -194,6 +194,7 @@
impl From<MetadataCrateDependency<'_>> for CrateDependency<'static> {
fn from(us: MetadataCrateDependency<'_>) -> CrateDependency<'static> {
#[allow(clippy::option_if_let_else)]
let (name, package) = if let Some(explicit_name_in_toml) = us.explicit_name_in_toml {
(
explicit_name_in_toml.into_owned(),
@@ -17,6 +17,7 @@
providers: Vec<String>,
}
#[allow(clippy::unused_async)]
pub async fn list_providers(
extract::Extension(oidc_clients): extract::Extension<Arc<OidcClients>>,
) -> Json<ListProvidersResponse> {
@@ -24,7 +25,7 @@
providers: oidc_clients
.keys()
.into_iter()
.map(|v| v.to_string())
.map(std::string::ToString::to_string)
.collect(),
})
}
@@ -40,6 +41,7 @@
redirect_url: String,
}
#[allow(clippy::unused_async)]
pub async fn begin_oidc(
extract::Path(provider): extract::Path<String>,
extract::Extension(config): extract::Extension<Arc<Config>>,
@@ -56,7 +58,7 @@
scope: Some("openid email profile".into()),
nonce: Some(base64::encode_config(&nonce, base64::URL_SAFE_NO_PAD)),
state: Some(encrypt_url_safe(&state, &config)?),
..Default::default()
..Options::default()
});
Ok(Json(BeginResponse {
@@ -64,6 +66,7 @@
}))
}
#[allow(dead_code)]
#[derive(Deserialize)]
pub struct CompleteOidcParams {
state: String,
@@ -92,7 +95,7 @@
client.decode_token(&mut id_token)?;
let nonce = base64::encode_config(state.nonce, base64::URL_SAFE_NO_PAD);
client.validate_token(&id_token, Some(nonce.as_str()), None)?;
client.validate_token(id_token, Some(nonce.as_str()), None)?;
} else {
return Err(Error::MissingToken);
}
@@ -122,7 +125,7 @@
let nonce = ChaCha20Poly1305Nonce::from_slice(&nonce);
let mut ciphertext = cipher.encrypt(nonce, input)?;
ciphertext.extend_from_slice(&nonce);
ciphertext.extend_from_slice(nonce);
Ok(base64::encode_config(&ciphertext, base64::URL_SAFE_NO_PAD))
}
@@ -34,7 +34,7 @@
Crate::search(db.clone(), user.id, req.q, 5)
.await?
.into_iter()
.map(move |(org, crates_with_permissions)| {
.flat_map(move |(org, crates_with_permissions)| {
let db = db.clone();
crates_with_permissions
@@ -54,12 +54,11 @@
version: version.map(|v| v.version).unwrap_or_default(),
homepage: v.crate_.homepage.clone(),
repository: v.crate_.repository.clone(),
permissions: v.permissions.clone(),
permissions: v.permissions,
})
}
})
})
.flatten(),
}),
)
.await?;