37 stable releases

4.2.2 Nov 11, 2024
4.1.0 Sep 30, 2024
3.4.1 Sep 23, 2024
3.2.1 May 31, 2024
2.3.1 Jul 20, 2023

#469 in Configuration

Download history 268/week @ 2024-08-17 143/week @ 2024-08-24 194/week @ 2024-08-31 165/week @ 2024-09-07 666/week @ 2024-09-14 675/week @ 2024-09-21 840/week @ 2024-09-28 1259/week @ 2024-10-05 811/week @ 2024-10-12 1004/week @ 2024-10-19 1029/week @ 2024-10-26 1658/week @ 2024-11-02 2446/week @ 2024-11-09 2583/week @ 2024-11-16 2564/week @ 2024-11-23 2146/week @ 2024-11-30

10,091 downloads per month
Used in 4 crates

Apache-2.0

2MB
41K SLoC

Cedar Policy Formatter

This package contains a simple formatter library for Cedar policies based on the pretty crate. We integrate it into Cedar CLI so that you can format your Cedar policies directly. You can also use it as a library in your Cedar applications.

Please share your opinions about the format using a feature request. And report any bugs you find using a bug report.

Quick Start

The easiest way to format your Cedar policies is via Cedar CLI's format subcommand.

# Default indentation is two spaces.
# Default line width is 80.
cedar format -p my-policies.cedar
# I want more indentation.
cedar format -i 4 -p my-policies.cedar
# I like shorter lines.
cedar format -l 40 -p my-policies.cedar

Usage

Build

To build, simply run cargo build (or cargo build --release).

Run

The formatter is invoked via Cedar CLI's format subcommand. Its options can be found using the following command.

cedar format -h

Documentation

Generated documentation for the latest version can be accessed on docs.rs.

Testing

Tests for this package use insta for snapshot testing. Tests are executed with the usual cargo test, but, if your changes introduce a difference in how we format any of the test policies, the tests will fail, printing a nicely formatted diff as the error message. You can then run cargo insta review to review how formatting has changed. If the change is expected, accept it and commit the updated snapshot file. Otherwise, reject the change, and fix it as you would any other failing test case.

You can add new test cases just just by placing a .cedar file in the tests directory. The next run of cargo test will fail because there is no snapshot file. Run cargo insta review to review the formatted output for the new tests. Accept and commit the snapshot if it is correct.

Dependencies

~8–18MB
~208K SLoC