-
Notifications
You must be signed in to change notification settings - Fork 3
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
Change watchdog to a single binary #10
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2ee5607
refactor: Change watchdog to a single binary
kanav99 bd5c6bc
refactor: Use `Result` for better error handling
kanav99 ca63fca
refactor: Removes all rust logging using `log` and `simple-log`
kanav99 39441ef
(chore) Fix auth and GitHub API deprecation
kanav99 c2a0bc9
(chore) Fix install scripts
kanav99 30e7e0c
(typo) Remove debug statement
kanav99 d21bf5b
(chore) Add logfile to pam exec statements
kanav99 9b998eb
(feat) Add watchdog log commands
kanav99 5cc8a9e
(chore) rustfmt
kanav99 28f6ede
(chore) Requested Changes
kanav99 6959c22
(refactor) Shift library code to folder
kanav99 67dcf33
(fix) Fix GitHub API deprecation in get_name
kanav99 dd85931
(chore) Remove unnecesary fields in Config
kanav99 be5cce8
(chore) Remove 'test:' from SSH notifications
kanav99 bf5b9ad
(refactor) Refactor logs
kanav99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,51 @@ | ||
use common_lib::config::read_config; | ||
use common_lib::errors::*; | ||
use common_lib::init::init; | ||
use common_lib::keyhouse::{get_name, validate_user}; | ||
use common_lib::notifier::{Notifier, Slack}; | ||
use std::fs; | ||
use std::process::Command; | ||
|
||
pub fn handle_auth(ssh_host_username: &str, ssh_key: &str) -> Result<()> { | ||
let config = read_config()?; | ||
init(&config)?; | ||
|
||
match validate_user(&config, ssh_host_username.to_string(), ssh_key) { | ||
Ok(true) => { | ||
let data = format!( | ||
"ssh_host_username = '{}'\nssh_key = '{}'\n", | ||
ssh_host_username, ssh_key | ||
); | ||
|
||
fs::write(&config.temp_env_file, data) | ||
.chain_err(|| "Cannot write temporary environment file. Please check if the watchdog `auth_keys_cmd` is run by the root user")?; | ||
|
||
println!("{}", ssh_key); | ||
Ok(()) | ||
} | ||
|
||
Ok(false) => { | ||
let name = get_name(&config, ssh_key)?; | ||
|
||
match Slack::new(&config) { | ||
Some(notifier) => notifier.post_ssh_summary( | ||
&config, | ||
false, | ||
name, | ||
ssh_host_username.to_string(), | ||
)?, | ||
None => {} | ||
}; | ||
Ok(()) | ||
} | ||
|
||
Err(e) => Err(e).chain_err(|| "Error while validating user from keyhouse"), | ||
} | ||
} | ||
|
||
pub fn handle_auth_logs() { | ||
Command::new("less") | ||
.arg("/opt/watchdog/logs/ssh.logs") | ||
.status() | ||
.expect("Something went wrong. Is `less` command present in your environment?"); | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,34 +1,6 @@ | ||
extern crate simplelog; | ||
use crate::config::Config; | ||
use crate::errors::*; | ||
|
||
use crate::config; | ||
use log::error; | ||
use simplelog::*; | ||
use std::fs::OpenOptions; | ||
|
||
pub fn init(config: &config::Config) { | ||
init_logger(&config); | ||
} | ||
|
||
pub fn init_logger(config: &config::Config) { | ||
let log_file = match OpenOptions::new() | ||
.create_new(true) | ||
.read(true) | ||
.append(true) | ||
.open(&config.error_log_file) | ||
{ | ||
Ok(f) => f, | ||
Err(_) => { | ||
error!("Watchdog: Couldn't open log file"); | ||
panic!("Watchdog: Couldn't open log file"); | ||
} | ||
}; | ||
|
||
let _res = match CombinedLogger::init(vec![WriteLogger::new( | ||
LevelFilter::Info, | ||
Config::default(), | ||
log_file, | ||
)]) { | ||
Ok(_) => {} | ||
Err(_) => error!("Watchdog: Couldnt start logger for some reason"), | ||
}; | ||
pub fn init(_config: &Config) -> Result<()> { | ||
Ok(()) | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use lib instead of common_lib