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

Remove the environmental awareness feature #16

Merged
merged 15 commits into from
Sep 26, 2022
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
7 changes: 3 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
kind: pipeline
--- kind: pipeline
name: default

platform:
Expand Down Expand Up @@ -36,7 +35,7 @@ steps:
- name: cargo-clippy-ci
image: rust:1.61
commands:
- cargo clippy -- -D warnings && cargo clippy --features environment-aware -- -D warnings
- cargo clippy -- -D warnings && cargo clippy --features toggle -- -D warnings
environment:
BUILD_ENV: dev
CARGO_HOME: /drone/src/.cargo
Expand All @@ -46,7 +45,7 @@ steps:
- name: cargo-test
image: rust:1.61
commands:
- cargo test --all && cargo test --all --features environment-aware
MaeIsBad marked this conversation as resolved.
Show resolved Hide resolved
- cargo test --all && cargo test --all --features toggle
environment:
BUILD_ENV: dev
CARGO_HOME: /drone/src/.cargo
Expand Down
173 changes: 4 additions & 169 deletions Cargo.lock

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

21 changes: 9 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ license = "MIT"
repository = "https://github.com/primait/veil"

[workspace]
members = [
"veil-macros",
"veil-tests",
"veil-tests/environment-aware",
"veil-tests/environment-aware-fallback-on",
"veil-tests/environment-aware-fallback-off",
"veil-tests/environment-aware-fallback-panic",
"veil-tests/environment-aware-disable",
members = ["veil-macros", "veil-tests"
# Because those tests deal with global state we need to run them in a separate process.
# The easiest/only way to do this with the standard rust test harness is to put them in a
# separate crate
,"veil-tests/disable-redaction-test"
]

[features]
environment-aware = ["veil-macros/environment-aware", "lazy_static"]
MaeIsBad marked this conversation as resolved.
Show resolved Hide resolved

[dependencies]
veil-macros = { path = "veil-macros" }
lazy_static = { version = "1", optional = true }
once_cell = "1"

[features]
toggle = []
41 changes: 5 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,8 @@ enum InsuranceStatus {
}
```

# Environment Awareness

You can configure Veil to redact or skip redacting data based on environment variables. Enable the `environment-aware` Cargo feature like so in your Cargo.toml:

```toml
[dependencies]
veil = { version = "0.1", features = ["environment-aware"] }
```

## `VEIL_DISABLE_REDACTION`

Redaction can be completely disabled by setting the `VEIL_DISABLE_REDACTION` environment variable. This is only checked once during the program lifetime for security purposes.

## `.veil.toml`

Redaction can also be configured on a per-project basis using a `.veil.toml` file. Put this file in your crate or workspace root and Veil will read it at compile time.

**Please note, if you change the file, Veil won't see the changes until you do a clean build of your crate.**

### Example

`APP_ENV` is just an example here. You can match multiple environment variables with any UTF-8 name and value(s).

```toml
[env.APP_ENV]
redact = ["production", "staging"] # redact data if "APP_ENV" is set to any of these values
skip-redact = ["dev", "qa"] # SKIP redacting data if "APP_ENV" is set to any of these values

# If "APP_ENV" isn't set or isn't recognised...
[fallback]
redact = true # do redact data (default)
# OR
redact = false # don't redact data
# OR
redact = "panic" # panic at runtime
```
# Skip redacting data
In testing environments it may be useful not to censor your logs. You can globally disable Veil's redaction behavior at runtime by enabling the *non-default* feature flag `toggle` and:
- Setting the VEIL_DISABLE_REDACTION environment variable.
MaeIsBad marked this conversation as resolved.
Show resolved Hide resolved
or
- Calling the `disable` function. See this [example](examples/disable_redaction.rs).
MaeIsBad marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions examples/disable_redaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::env;
use veil::Redact;

#[derive(Redact)]
pub struct Customer {
#[redact(partial)]
first_name: String,
}

fn main() {
// If the environment variable APP_ENV is set to "dev" veil will not redact anything
if let Ok(env) = env::var("APP_ENV") {
if env == "dev" {
// Note that veil::disable needs the `toggle` feature flag enabled
veil::disable().unwrap();
}
}

println!(
"{:#?}",
Customer {
first_name: "John".to_string(),
}
);
}
Loading