Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

genpolicy: add --version flag #176

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/tools/genpolicy/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
layers_cache
src/version.rs
2 changes: 1 addition & 1 deletion src/tools/genpolicy/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/tools/genpolicy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

[package]
name = "genpolicy"
version = "0.1.0"
version = "3.2.0-azl0.genpolicy1"
authors = ["The Kata Containers community <[email protected]>"]
edition = "2021"
license = "Apache-2.0"

[dependencies]
# Logging.
Expand Down
22 changes: 19 additions & 3 deletions src/tools/genpolicy/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2020 Intel Corporation
# Portions Copyright (c) Microsoft Corporation.
#
# SPDX-License-Identifier: Apache-2.0
#
Expand All @@ -9,27 +10,42 @@ ifeq ($(ARCH), ppc64le)
override ARCH = powerpc64le
endif

COMMIT_HASH := $(shell git rev-parse HEAD 2>/dev/null || true)
# appends '-dirty' to the commit hash if there are uncommitted changes
COMMIT_INFO := $(if $(shell git status --porcelain --untracked-files=no 2>/dev/null || true),${COMMIT_HASH}-dirty,${COMMIT_HASH})

GENERATED_CODE = src/version.rs

GENERATED_REPLACEMENTS= COMMIT_INFO
GENERATED_FILES :=

GENERATED_FILES += $(GENERATED_CODE)

$(GENERATED_FILES): %: %.in
sed $(foreach r,$(GENERATED_REPLACEMENTS),-e 's|@$r@|$($r)|g') "$<" > "$@"

.DEFAULT_GOAL := default
default: build

build:
build: $(GENERATED_FILES)
@RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo build --target $(TRIPLE) --$(BUILD_TYPE)

static-checks-build:
@echo "INFO: static-checks-build do nothing.."

clean:
cargo clean
rm -f $(GENERATED_FILES)

vendor:
cargo vendor

test:

install:
install: $(GENERATED_FILES)
@RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo install --locked --target $(TRIPLE) --path .

check: standard_rust_check
check: $(GENERATED_CODE) standard_rust_check

.PHONY: \
build \
Expand Down
11 changes: 11 additions & 0 deletions src/tools/genpolicy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod settings;
mod stateful_set;
mod utils;
mod verity;
mod version;
mod volume;
mod yaml;

Expand All @@ -37,6 +38,16 @@ async fn main() {
env_logger::init();
let config = utils::Config::new();

if config.version {
println!(
"Kata Containers policy tool (Rust): id: {}, version: {}, commit: {}",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_VERSION"),
version::COMMIT_INFO
);
return;
}

debug!("Creating policy from yaml, settings, and rules.rego files...");
let mut policy = policy::AgentPolicy::from_files(&config).await.unwrap();

Expand Down
5 changes: 5 additions & 0 deletions src/tools/genpolicy/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ struct CommandLineOptions {
require_equals= true
)]
containerd_socket_path: Option<String>,

#[clap(short, long, help = "Print version information and exit")]
version: bool,
}

/// Application configuration, derived from on command line parameters.
Expand All @@ -91,6 +94,7 @@ pub struct Config {
pub raw_out: bool,
pub base64_out: bool,
pub containerd_socket_path: Option<String>,
pub version: bool,
}

impl Config {
Expand Down Expand Up @@ -118,6 +122,7 @@ impl Config {
raw_out: args.raw_out,
base64_out: args.base64_out,
containerd_socket_path: args.containerd_socket_path,
version: args.version,
}
}
}
12 changes: 12 additions & 0 deletions src/tools/genpolicy/src/version.rs.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2020 Intel Corporation
// Portions Copyright (c) Microsoft Corporation.
//
// SPDX-License-Identifier: Apache-2.0
//

//
// WARNING: This file is auto-generated - DO NOT EDIT!
//

#![allow(dead_code)]
pub const COMMIT_INFO: &str = "@COMMIT_INFO@";
Loading