This repository was archived by the owner on Nov 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Block unblock ips #24
Merged
nellshamrell
merged 18 commits into
rust-lang:master
from
nellshamrell:block-unblock-ips
Apr 14, 2020
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
51e52b6
Sets up skeleton work for new command
nellshamrell a70071e
returns notice if the ip address has already been blocked
nellshamrell 1eff9c7
adds ability to parse a hashset into a string
nellshamrell 220b142
adds ability to block ip addresses
nellshamrell e583f92
adds command to unblock an ip address
nellshamrell c60fd34
apply formmatting
nellshamrell 62fdc3c
removes BLOCKED_IPs config variable if there are no more blocked ips
nellshamrell df3ee3c
slight refactoring
nellshamrell b20202e
successfully creates BLOCKED_IPS env var if it does not already exist
nellshamrell 74dcbce
update README with documentation of block_ip and unblock_ip commands
nellshamrell 53b113f
fixes failing test
nellshamrell dc5fd35
remove BLOCKED_IPS from list of authorized config vars for the update…
nellshamrell 6f731f0
refactors BLOCKED_IPS env var key to a constant
nellshamrell 4151d88
returns from block_ip function when there is an error creating the BL…
nellshamrell 251e52c
partial refactor - only get current config variables from Heroku once…
nellshamrell 53d58e5
handles situation where someone is trying to unblock an ip when no IP…
nellshamrell dc03042
corrects formatting
nellshamrell b7ed4c8
more refinements
nellshamrell 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 contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| use std::collections::HashSet; | ||
|
|
||
| pub fn parse_config_value_set(config_value: String) -> HashSet<String> { | ||
| config_value.split(',').map(String::from).collect() | ||
| } | ||
|
|
||
| pub fn parse_config_value_string(config_value: HashSet<String>) -> String { | ||
| let non_empty: Vec<String> = config_value.into_iter().filter(|s| !s.is_empty()).collect(); | ||
| non_empty.join(",") | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn create_authorized_users_hashset() { | ||
| let test_string = String::from("123,456,789"); | ||
| let users_set = parse_config_value_set(test_string); | ||
|
|
||
| assert!(users_set.contains("123")); | ||
| assert!(users_set.contains("456")); | ||
| assert!(users_set.contains("789")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn create_authorized_users_string() { | ||
| let mut users_hash_set = HashSet::new(); | ||
| users_hash_set.insert("123".to_string()); | ||
| users_hash_set.insert("456".to_string()); | ||
| users_hash_set.insert("789".to_string()); | ||
|
|
||
| let users_string = parse_config_value_string(users_hash_set); | ||
| assert!(users_string.contains("123")); | ||
| assert!(users_string.contains("456")); | ||
| assert!(users_string.contains("789")); | ||
| } | ||
| } |
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.
You can inline this variable – it's used only once.