Skip to content

Commit 4559d05

Browse files
committed
lints: Add a set_root_type helper
We have two patterns to initialize a lint: - Bare struct init - A helper function This changes to just one path: A helper function, plus setters for the optional fields. Prep for adding a new lint option, which would otherwise require changes to everything using the bare struct init. Signed-off-by: Colin Walters <[email protected]>
1 parent 22c743f commit 4559d05

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

lib/src/lints.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ impl Lint {
126126
root_type: None,
127127
}
128128
}
129+
130+
const fn set_root_type(mut self, v: RootType) -> Self {
131+
self.root_type = Some(v);
132+
self
133+
}
129134
}
130135

131136
pub(crate) fn lint_list(output: impl std::io::Write) -> Result<()> {
@@ -245,17 +250,16 @@ fn check_var_run(root: &Dir) -> LintResult {
245250
}
246251

247252
#[distributed_slice(LINTS)]
248-
static LINT_BUILDAH_INJECTED: Lint = Lint {
249-
name: "buildah-injected",
250-
description: indoc::indoc! { "
253+
static LINT_BUILDAH_INJECTED: Lint = Lint::new_warning(
254+
"buildah-injected",
255+
indoc::indoc! { "
251256
Check for an invalid /etc/hostname or /etc/resolv.conf that may have been injected by
252257
a container build system." },
253-
ty: LintType::Warning,
254-
f: check_buildah_injected,
255-
// This one doesn't make sense to run looking at the running root,
256-
// because we do expect /etc/hostname to be injected as
257-
root_type: Some(RootType::Alternative),
258-
};
258+
check_buildah_injected,
259+
)
260+
// This one doesn't make sense to run looking at the running root,
261+
// because we do expect /etc/hostname to be injected as
262+
.set_root_type(RootType::Alternative);
259263
fn check_buildah_injected(root: &Dir) -> LintResult {
260264
const RUNTIME_INJECTED: &[&str] = &["etc/hostname", "etc/resolv.conf"];
261265
for ent in RUNTIME_INJECTED {
@@ -499,10 +503,9 @@ fn check_varlog(root: &Dir) -> LintResult {
499503
}
500504

501505
#[distributed_slice(LINTS)]
502-
static LINT_VAR_TMPFILES: Lint = Lint {
503-
name: "var-tmpfiles",
504-
ty: LintType::Warning,
505-
description: indoc! { r#"
506+
static LINT_VAR_TMPFILES: Lint = Lint::new_warning(
507+
"var-tmpfiles",
508+
indoc! { r#"
506509
Check for content in /var that does not have corresponding systemd tmpfiles.d entries.
507510
This can cause a problem across upgrades because content in /var from the container
508511
image will only be applied on the initial provisioning.
@@ -511,9 +514,9 @@ Instead, it's recommended to have /var effectively empty in the container image,
511514
and use systemd tmpfiles.d to generate empty directories and compatibility symbolic links
512515
as part of each boot.
513516
"#},
514-
f: check_var_tmpfiles,
515-
root_type: Some(RootType::Running),
516-
};
517+
check_var_tmpfiles,
518+
)
519+
.set_root_type(RootType::Running);
517520
fn check_var_tmpfiles(_root: &Dir) -> LintResult {
518521
let r = bootc_tmpfiles::find_missing_tmpfiles_current_root()?;
519522
if r.tmpfiles.is_empty() && r.unsupported.is_empty() {
@@ -546,10 +549,9 @@ fn check_var_tmpfiles(_root: &Dir) -> LintResult {
546549
}
547550

548551
#[distributed_slice(LINTS)]
549-
static LINT_SYSUSERS: Lint = Lint {
550-
name: "sysusers",
551-
ty: LintType::Warning,
552-
description: indoc! { r#"
552+
static LINT_SYSUSERS: Lint = Lint::new_warning(
553+
"sysusers",
554+
indoc! { r#"
553555
Check for users in /etc/passwd and groups in /etc/group that do not have corresponding
554556
systemd sysusers.d entries in /usr/lib/sysusers.d.
555557
This can cause a problem across upgrades because if /etc is not transient and is locally
@@ -560,10 +562,9 @@ Using systemd-sysusers to allocate users and groups will ensure that these are a
560562
on system startup alongside other users.
561563
562564
More on this topic in <https://containers.github.io/bootc/building/users-and-groups.html>
563-
"#},
564-
f: check_sysusers,
565-
root_type: None,
566-
};
565+
"# },
566+
check_sysusers,
567+
);
567568
fn check_sysusers(rootfs: &Dir) -> LintResult {
568569
let r = bootc_sysusers::analyze(rootfs)?;
569570
if r.is_empty() {

0 commit comments

Comments
 (0)