Secrets: Secret fields
● Intermediate2 min
secret before a field marks it. Logs show such a field as <secret>.
use std.log
type OrderPlaced: LogEvent {
order_id: Int
amount: Decimal
secret card: String
}
fn main() {
log.info(OrderPlaced(order_id: 7, amount: 499.00, card: "4242 4242 4242 4242"))
}The program ran and printed:
kavach run log.kav
INFO OrderPlaced(order_id: 7, amount: 499.00, card: <secret>)The rest of the record is logged as usual, so the entry is still useful. Only the card is hidden.
use std.json
type Card {
holder: String
secret number: String
}
fn main() {
const c = Card(holder: "asha", number: "4111")
print(json.stringify(c))
}The compiler refused the program:
kavach run secret.kav
error: `Card` has the secret field `number`, so it can't be written as JSON (spec 2.11)