-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(jans-cedarling): move
cedarling
from jans-lock
to `jans-ced…
…arling` top level Squash all previous changes: chore(jans-cedarling): refactor, improve organization of config entity imports docs(jans-cedarling): add to README how to generate documentation chore(jans-cedarling): rename unexported field in the writer feat(jans-cedarling): add Authz to the Cedarling instance feat(jans-cedarling): add Cedarling instance docs(jans-cedarling): fix docstring test(jans-cedarling): fix log/test, import LogWriter docs(jans-cedarling): added to README information how to run unit tests test(jans-cedarling): move unit test for LogStrategy to log/test module docs(jans-cedarling): added to README information how to get code-coverage test(jans-cedarling): add unit test for LogStrategy test(jans-cedarling): add unit test for MemoryLogger chore(jans-cedarling): make fields in AuthorizationLogInfo struct public test(jans-cedarling): add unit test for StdOutLogger docs(jans-cedarling): added README to log module chore(jans-cedarling): add note about using uuids in different situation docs(jans-cedarling): improved README, added not about `log_init.rs` file. And information about each log type. chore(jans-cedarling): fix clippy warnings about doc identation chore(jans-cedarling): fix clippy warnings docs(jans-cedarling): improved documentation in the log crate. docs(jans-cedarling): add links to the bootstrap properties in the documentation docs(jans-cedarling): improved documentation in the log crate. Made it public to see message from autogenerated documentation page chore(jans-cedarling): remove unused imports chore(jans-cedarling): add macros allow(dead_code) to the Authz struct chore(jans-cedarling): refactor make StdOutLogger more simple chore(jans-cedarling): refactor to use imported names for shorter match cases feat(jans-cedarling): add example of run cedarling Authz and updated Readme chore(jans-cedarling): refactor implementation MemoryLogger method log chore(jans-cedarling): rename method get_logs to get_log_ids according to last changes in the `Final Cedarling Log Design` chore(jans-cedarling): change name on init Authz chore(jans-cedarling): add derive Clone, Copy to the LogType and MemoryLogConfig chore(jans-cedarling): added doc message to MemoryLogConfig chore(jans-cedarling): add documentation notes for LogStrategy chore(jans-cedarling): add copyright note chore(jans-cedarling): add simple Authz with initialization logger service chore(jans-cedarling): add init_logger function chore(jans-cedarling): fix missed documentation chore(jans-cedarling): initialize logger using configuration settings chore(jans-cedarling): add configs for logger chore(jans-cedarling): add LogStrategy to unify multiple implementations under a common API chore(jans-cedarling): add MemoryLogger chore(jans-cedarling): add MemoryLogger and implement LogWriter trait chore(jans-cedarling): make LogEntry properties public chore(jans-cedarling): added to sparkv error text error message chore(jans-cedarling): added сopyright note to sparkv chore(jans-cedarling): added StdOutLogger chore(jans-cedarling): added NopLogger, that do nothing. chore(jans-cedarling): added log interfaces chore(jans-cedarling): added log LogEntry struct and related to it. feat(jans-cedarling): added fork of the SparKV as is Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
- Loading branch information
1 parent
4dcd3a3
commit 55b33a2
Showing
28 changed files
with
1,803 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use cedarling::{ | ||
AuthzConfig, BootstrapConfig, Cedarling, LogConfig, LogStorage, LogType, MemoryLogConfig, | ||
}; | ||
use std::env; | ||
|
||
fn main() { | ||
// Collect command-line arguments | ||
let args: Vec<String> = env::args().collect(); | ||
|
||
// Ensure at least one argument is provided (the program name itself is the first argument) | ||
if args.len() < 2 { | ||
eprintln!("Usage: {} <log_type> [ttl in seconds]", args[0]); | ||
eprintln!("<log_type> can be one of off,stdout,memory"); | ||
std::process::exit(1); | ||
} | ||
|
||
// Parse the log type from the first argument | ||
let log_type_arg = &args[1]; | ||
let log_type = match log_type_arg.as_str() { | ||
"off" => LogType::Off, | ||
"stdout" => LogType::StdOut, | ||
"lock" => LogType::Lock, | ||
"memory" => extract_memory_config(args), | ||
_ => { | ||
eprintln!("Invalid log type, defaulting to StdOut."); | ||
LogType::StdOut | ||
}, | ||
}; | ||
|
||
println!("Authz initialized with log type: {:?}", log_type); | ||
|
||
// Create the Authz instance with the selected log type | ||
let authz = Cedarling::new(BootstrapConfig { | ||
authz_config: AuthzConfig { | ||
application_name: "test_app".to_string(), | ||
}, | ||
log_config: LogConfig { log_type }, | ||
}); | ||
|
||
println!("Stage 1:"); | ||
let logs_ids = authz.get_log_ids(); | ||
println!( | ||
"Show results of get_logs(): returns a list of all log ids: {:?}", | ||
&logs_ids | ||
); | ||
println!("\n\n Stage 2:\nShow result of get_log_by_id for each key."); | ||
for id in logs_ids { | ||
let entry = authz | ||
.get_log_by_id(&id) | ||
.map(|v| serde_json::json!(v).to_string()); | ||
println!("\nkey:{}\nvalue:{:?}", id, entry); | ||
} | ||
|
||
println!("\n\n Stage 3:\nShow result of pop_logs"); | ||
for (i, entry) in authz.pop_logs().iter().enumerate() { | ||
println!("entry n:{i}\nvalue: {}", serde_json::json!(entry)) | ||
} | ||
|
||
println!("\n\n Stage 4:\nShow len of keys left using get_log_ids"); | ||
println!("Number of keys left: {:?}", authz.get_log_ids().len()); | ||
} | ||
|
||
fn extract_memory_config(args: Vec<String>) -> LogType { | ||
if args.len() < 3 { | ||
eprintln!("Memory log type requires two additional arguments: ttl value in seconds"); | ||
std::process::exit(1); | ||
} | ||
// Parse additional arguments for MemoryLogConfig | ||
let log_ttl: u64 = args[2] | ||
.parse() | ||
.expect("Invalid ttl value, should be integer"); | ||
LogType::Memory(MemoryLogConfig { log_ttl }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Log Engine | ||
|
||
Log Engine is responsible for log all authz and init events. | ||
|
||
## Cedarling log types | ||
|
||
In Cedarling framework [Bootstrap properties](https://github.com/JanssenProject/jans/wiki/Cedarling-Nativity-Plan#bootstrap-properties), a configuration property called`CEDARLING_LOG_TYPE` can take on one of the following values:: | ||
|
||
* off | ||
* memory | ||
* std_out | ||
* lock | ||
|
||
### Log type `off` | ||
|
||
This log type is do nothing. It means that all logs will be ignored. | ||
|
||
#### Log type `memory` | ||
|
||
This log type stores all logs in memory with a time-to-live (TTL) eviction policy. | ||
|
||
`CEDARLING_LOG_TTL` - variable determines how long logs are stored in memory, measured in seconds. | ||
|
||
### Log type `std_out` | ||
|
||
This log type writes all logs to `stdout`. Without storing or additional handling log messages. | ||
[Standart streams](https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html). | ||
|
||
### Log type `lock` | ||
|
||
This log type is send logs to the server (corporate feature). Will be discussed later. | ||
|
||
## Log Strategy | ||
|
||
We use `LogStrategy` logger to implement all types of logger under one interface. | ||
On creating (method new()) it consumes the `LogConfig` with all information about log type and it configuration. And this **factory** method | ||
|
||
## Interfaces | ||
|
||
Currently we have 2 interfaces (traits): | ||
|
||
* `LogWriter` (not public) it is used to write logs. | ||
|
||
All log implementations should implement this. | ||
|
||
* `LogStorage` are used to gettting logs from storage. | ||
|
||
Currently only `MemoryLogger` implement it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* This software is available under the Apache-2.0 license. | ||
* See https://www.apache.org/licenses/LICENSE-2.0.txt for full text. | ||
* | ||
* Copyright (c) 2024, Gluu, Inc. | ||
*/ | ||
|
||
//! Log interface | ||
//! Contains the interface for logging. And getting log information from storage. | ||
use crate::models::log_entry::LogEntry; | ||
|
||
/// Log Writer | ||
/// interface for logging events | ||
pub(crate) trait LogWriter { | ||
/// log logging entry | ||
fn log(&self, entry: LogEntry); | ||
} | ||
|
||
/// Log Storage | ||
/// interface for getting log entries from the storage | ||
pub trait LogStorage { | ||
/// return logs and remove them from the storage | ||
fn pop_logs(&self) -> Vec<LogEntry>; | ||
|
||
/// get specific log entry | ||
fn get_log_by_id(&self, id: &str) -> Option<LogEntry>; | ||
|
||
/// returns a list of all log ids | ||
fn get_log_ids(&self) -> Vec<String>; | ||
} |
Oops, something went wrong.