Skip to content

Commit 354c531

Browse files
authored
Replace partial-validate with validation-mode in the CLI (#915)
Signed-off-by: Magnus Markling <[email protected]>
1 parent e8fcaf4 commit 354c531

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

cedar-policy-cli/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
- The default `--schema-format` is now `human` for all subcommands that take
88
`--schema-format`.
9+
- The `--partial-validate` option has been replaced with `--validation-mode`,
10+
taking the values `strict`, `permissive` (new) and `partial`.
11+
The latter two are kept behind their respective feature flags.
912

1013
## 3.2.0
1114

@@ -50,6 +53,7 @@ Now uses Cedar language version 3.1.0.
5053
- The `evaluate` command now shows source spans on parse errors.
5154

5255
### Fixed
56+
5357
- The `link` command now accepts templates in the Cedar JSON (EST) syntax.
5458

5559
## 3.0.1

cedar-policy-cli/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ thiserror = "1.0"
2222

2323
[features]
2424
default = []
25-
experimental = ["partial-validate"]
25+
experimental = ["permissive-validate", "partial-validate"]
26+
permissive-validate = ["cedar-policy/permissive-validate"]
2627
partial-validate = ["cedar-policy/partial-validate"]
2728

2829
[dev-dependencies]

cedar-policy-cli/src/lib.rs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ impl Default for SchemaFormat {
135135
}
136136
}
137137

138+
#[derive(Debug, Clone, Copy, ValueEnum)]
139+
pub enum ValidationMode {
140+
/// Strict validation
141+
Strict,
142+
/// Permissive validation
143+
Permissive,
144+
/// Partial validation
145+
Partial,
146+
}
147+
138148
#[derive(Args, Debug)]
139149
pub struct ValidateArgs {
140150
/// File containing the schema
@@ -146,14 +156,15 @@ pub struct ValidateArgs {
146156
/// Report a validation failure for non-fatal warnings
147157
#[arg(long)]
148158
pub deny_warnings: bool,
149-
/// Validate the policy using partial schema validation. This option is
150-
/// experimental and will cause the CLI to exit if it was not built with the
151-
/// experimental `partial-validate` feature enabled.
152-
#[arg(long = "partial-validate")]
153-
pub partial_validate: bool,
154159
/// Schema format (Human-readable or json)
155160
#[arg(long, value_enum, default_value_t = SchemaFormat::Human)]
156161
pub schema_format: SchemaFormat,
162+
/// Validate the policy using this mode.
163+
/// The options `permissive` and `partial` are experimental
164+
/// and will cause the CLI to exit if it was not built with the
165+
/// experimental feature `permissive-validate` and `partial-validate`, respectively, enabled.
166+
#[arg(long, value_enum, default_value_t = ValidationMode::Strict)]
167+
pub validation_mode: ValidationMode,
157168
}
158169

159170
#[derive(Args, Debug)]
@@ -519,16 +530,26 @@ pub fn check_parse(args: &CheckParseArgs) -> CedarExitCode {
519530
}
520531

521532
pub fn validate(args: &ValidateArgs) -> CedarExitCode {
522-
let mode = if args.partial_validate {
523-
#[cfg(not(feature = "partial-validate"))]
524-
{
525-
eprintln!("Error: arguments include the experimental option `--partial-validate`, but this executable was not built with `partial-validate` experimental feature enabled");
526-
return CedarExitCode::Failure;
533+
let mode = match args.validation_mode {
534+
ValidationMode::Strict => cedar_policy::ValidationMode::Strict,
535+
ValidationMode::Permissive => {
536+
#[cfg(not(feature = "permissive-validate"))]
537+
{
538+
eprintln!("Error: arguments include the experimental option `--validation-mode permissive`, but this executable was not built with `permissive-validate` experimental feature enabled");
539+
return CedarExitCode::Failure;
540+
}
541+
#[cfg(feature = "permissive-validate")]
542+
cedar_policy::ValidationMode::Permissive
543+
}
544+
ValidationMode::Partial => {
545+
#[cfg(not(feature = "partial-validate"))]
546+
{
547+
eprintln!("Error: arguments include the experimental option `--validation-mode partial`, but this executable was not built with `partial-validate` experimental feature enabled");
548+
return CedarExitCode::Failure;
549+
}
550+
#[cfg(feature = "partial-validate")]
551+
cedar_policy::ValidationMode::Partial
527552
}
528-
#[cfg(feature = "partial-validate")]
529-
ValidationMode::Partial
530-
} else {
531-
ValidationMode::default()
532553
};
533554

534555
let pset = match args.policies.get_policy_set() {

cedar-policy-cli/tests/sample.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ fn run_validate_test(
483483
template_linked_file: None,
484484
},
485485
deny_warnings: false,
486-
partial_validate: false,
486+
validation_mode: cedar_policy_cli::ValidationMode::Strict,
487487
schema_format: SchemaFormat::Json,
488488
};
489489
let output = validate(&cmd);
@@ -501,7 +501,7 @@ fn run_validate_test(
501501
template_linked_file: None,
502502
},
503503
deny_warnings: false,
504-
partial_validate: false,
504+
validation_mode: cedar_policy_cli::ValidationMode::Strict,
505505
schema_format: SchemaFormat::Human,
506506
};
507507
let output = validate(&cmd);

0 commit comments

Comments
 (0)