mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-13 07:04:58 +00:00
Merge pull request #10121 from microsoft/saulparedes/add_version_flag
genpolicy: add --version flag
This commit is contained in:
commit
43dca8deb4
1
src/tools/genpolicy/.gitignore
vendored
Normal file
1
src/tools/genpolicy/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
src/version.rs
|
@ -8,6 +8,7 @@ name = "genpolicy"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["The Kata Containers community <kata-dev@lists.katacontainers.io>"]
|
authors = ["The Kata Containers community <kata-dev@lists.katacontainers.io>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Logging.
|
# Logging.
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# Copyright (c) 2020 Intel Corporation
|
# Copyright (c) 2020 Intel Corporation
|
||||||
|
# Portions Copyright (c) Microsoft Corporation.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
#
|
#
|
||||||
@ -9,10 +10,24 @@ ifeq ($(ARCH), ppc64le)
|
|||||||
override ARCH = powerpc64le
|
override ARCH = powerpc64le
|
||||||
endif
|
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_GOAL := default
|
||||||
default: build
|
default: build
|
||||||
|
|
||||||
build:
|
build: $(GENERATED_FILES)
|
||||||
@RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo build --target $(TRIPLE) --$(BUILD_TYPE)
|
@RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo build --target $(TRIPLE) --$(BUILD_TYPE)
|
||||||
|
|
||||||
static-checks-build:
|
static-checks-build:
|
||||||
@ -20,16 +35,17 @@ static-checks-build:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
cargo clean
|
cargo clean
|
||||||
|
rm -f $(GENERATED_FILES)
|
||||||
|
|
||||||
vendor:
|
vendor:
|
||||||
cargo vendor
|
cargo vendor
|
||||||
|
|
||||||
test:
|
test:
|
||||||
|
|
||||||
install:
|
install: $(GENERATED_FILES)
|
||||||
@RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo install --locked --target $(TRIPLE) --path .
|
@RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo install --locked --target $(TRIPLE) --path .
|
||||||
|
|
||||||
check: standard_rust_check
|
check: $(GENERATED_CODE) standard_rust_check
|
||||||
|
|
||||||
.PHONY: \
|
.PHONY: \
|
||||||
build \
|
build \
|
||||||
|
@ -27,6 +27,7 @@ mod settings;
|
|||||||
mod stateful_set;
|
mod stateful_set;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod verity;
|
mod verity;
|
||||||
|
mod version;
|
||||||
mod volume;
|
mod volume;
|
||||||
mod yaml;
|
mod yaml;
|
||||||
|
|
||||||
@ -35,6 +36,16 @@ async fn main() {
|
|||||||
env_logger::init();
|
env_logger::init();
|
||||||
let config = utils::Config::new();
|
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...");
|
debug!("Creating policy from yaml, settings, and rules.rego files...");
|
||||||
let mut policy = policy::AgentPolicy::from_files(&config).await.unwrap();
|
let mut policy = policy::AgentPolicy::from_files(&config).await.unwrap();
|
||||||
|
|
||||||
|
@ -96,6 +96,8 @@ struct CommandLineOptions {
|
|||||||
require_equals = true
|
require_equals = true
|
||||||
)]
|
)]
|
||||||
layers_cache_file_path: Option<String>,
|
layers_cache_file_path: Option<String>,
|
||||||
|
#[clap(short, long, help = "Print version information and exit")]
|
||||||
|
version: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Application configuration, derived from on command line parameters.
|
/// Application configuration, derived from on command line parameters.
|
||||||
@ -115,6 +117,7 @@ pub struct Config {
|
|||||||
pub base64_out: bool,
|
pub base64_out: bool,
|
||||||
pub containerd_socket_path: Option<String>,
|
pub containerd_socket_path: Option<String>,
|
||||||
pub layers_cache_file_path: Option<String>,
|
pub layers_cache_file_path: Option<String>,
|
||||||
|
pub version: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@ -153,6 +156,7 @@ impl Config {
|
|||||||
base64_out: args.base64_out,
|
base64_out: args.base64_out,
|
||||||
containerd_socket_path: args.containerd_socket_path,
|
containerd_socket_path: args.containerd_socket_path,
|
||||||
layers_cache_file_path,
|
layers_cache_file_path,
|
||||||
|
version: args.version,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/tools/genpolicy/src/version.rs.in
Normal file
12
src/tools/genpolicy/src/version.rs.in
Normal file
@ -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…
Reference in New Issue
Block a user