-
Notifications
You must be signed in to change notification settings - Fork 13
Feature/de #40
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
Merged
Merged
Feature/de #40
Changes from all commits
Commits
Show all changes
131 commits
Select commit
Hold shift + click to select a range
66bce0e
Do thing
6dccd93
Add missing word employee
b409154
Add missing word employee
5612b2f
Mega ultra reuse code
872c553
Fix username desc
2ba8392
Merge branch 'master' into chore/refactor-detetctionlists
af781fd
Upgrade py42 and extractor
390bbd2
Merge branch 'chore/refactor-detetctionlists' of https://github.com/c…
c7ac5d3
Undo last commit
557330c
Upgrade py42 and extractor
7f2baf8
Impl add
0cdc409
Add tests
d13fef7
Format
406dd19
Fix search args
1b4c279
Fix underscore to hyphen issue
4be3302
Fix bulk
b6c4590
update py42
d690005
Fix tests
7ac0e40
Fix everything
ca2e168
More tests
966ab82
get handlers
0c02883
Save
63db05b
Remove bulk, had to massage it for that
713f68d
Revise
76cd42f
Fix tests
1f99191
Use generators
61c817f
Add more tests
742b56a
Update changelog
2adf39a
Remove print
59c125c
Remove command
6e78d22
REturn
516a6c0
Check for no user
f90c229
Simplify
41eca3b
Update tests
8c1d863
More tests
70e8d30
Update upstream
01a2922
Remove unused import
50e357e
Bumps
ea9e074
Merge branch 'chore/refactor-detetctionlists' into feature/rm-hr
1bc6d58
Bumps correctly
20d14a8
Tests
afe670b
Reader arg
9462bcb
More tests
ec2ed73
Rename methods
c9cec92
Docstr+ format
5db1983
Genericize the username desc
51ff8fb
Pull out command names
d449473
Add readme
312793f
Errorsgit sgit s
57c30bb
Error handling
5a9a125
Handle template for remove
97c778d
Print message for remove generation
b9cde61
Update CL
cf2aa52
Revise
769f599
Try fix tests
4b85169
Add missing periods
7e1f295
Revise README
13ce049
Revise Bulk docstr
5c226bf
Clarify method names
db13630
Doc
abdaad2
Save
61af99b
Docs revise
eb992f3
Merge branch 'feature/rm-hr' into feature/de
d46be49
Fix critical bug
a2c81fb
Fix critical bug
6737656
Merge branch 'feature/rm-hr' into feature/de
ccb43e0
Load subs
9c379a4
Fix more critical bugs
d5fa1d4
Merge branch 'feature/rm-hr' into feature/de
746ac24
Remove spaces
a418100
Formatting
746b21b
Merge branch 'feature/rm-hr' into feature/de
db3754a
Fix readme issues
25f68f1
Merge branch 'feature/rm-hr' into feature/de
79f6a5b
Merge
4a65322
Missing s
e1ae368
README command replace
a72f45f
Say delimited one line per user in readme
c7fd31b
Generic type for documentation purposes
2fcb5eb
Some pr fb
951c4aa
Merge branch 'master' into feature/rm-hr
9e97e70
Determine which handler to use based on num args
13aacdd
Print message during py42forbidden
9f12ba4
Handle flat files better
81eb8c1
Update readme
a241279
Remove pointless base class
3219f64
Update words
2746127
Make test for error log loc printing simpler
d833b3d
Remove redundancy and fix docstr
7f76cb4
<=
d3c48d9
Docs
95bbdb3
Profile and sdk names reuse
b4a5ca5
Make only accpet single cloud alias
27a206b
Format
37b0888
Better help
4a58374
elif
ffd8bd8
Str or unicode, makes pycharm happier
86ed52a
cloud alias
2f37256
cloud alias for real
e6be3b2
Bumps
7da5346
Remove pinning
28f5aee
Fix tests
52f2e69
Merge branch 'feature/rm-hr' into feature/de
d56d87e
Optimize imports
8029901
Fix tests
3c210ac
Ignore none
72788b9
Fix edge case with blank rows
0de86ad
Put back something that got deleted accidentally
c0a9910
Improve teset
ea0b472
Merge branch 'feature/rm-hr' into feature/de
8d8e10c
Actually use custom ex
3fa604f
Merge branch 'feature/rm-hr' into feature/de
fb3a8c6
Simplify
9acba6e
Simplify
a58bd85
Merge branch 'feature/rm-hr' into feature/de
1e99a11
Simplify
a326f1b
Safety first
7a05b56
Merge branch 'feature/rm-hr' into feature/de
ec6c2aa
Merge branch 'master' into feature/de
540f952
Merge branch 'feature/de' of https://github.com/code42/c42sec into fe…
e92e2d0
Create handlers
7fee80c
Singular cloud alias
dbf9a51
Fix tests
12f45bd
USe enum
200c3bf
undo some stuff
dadb9b5
Resolve flicts
68bf7de
Add format to help str
8f7fc29
Fix alias help
c6e4992
Fix quote
3d6ae5a
Update some docs
00d2b2a
Missing periods
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from code42cli.cmds.detectionlists import ( | ||
DetectionList, | ||
DetectionListHandlers, | ||
load_user_descriptions, | ||
get_user_id, | ||
update_user, | ||
) | ||
|
||
|
||
def load_subcommands(): | ||
handlers = _create_handlers() | ||
detection_list = DetectionList.create_departing_employee_list(handlers) | ||
return detection_list.load_subcommands() | ||
|
||
|
||
def _create_handlers(): | ||
return DetectionListHandlers( | ||
add=add_departing_employee, remove=remove_departing_employee, load_add=_load_add_description | ||
) | ||
|
||
|
||
def add_departing_employee( | ||
sdk, profile, username, cloud_alias=None, departure_date=None, notes=None | ||
): | ||
"""Adds an employee to the departing employee detection list. | ||
|
||
Args: | ||
sdk (py42.sdk.SDKClient): py42. | ||
profile (C42Profile): Your code42 profile. | ||
username (str): The username of the employee to add. | ||
cloud_alias (str): An alternative email address for another cloud service. | ||
departure_date (str): The date the employee is departing in format `YYYY-MM-DD`. | ||
notes: (str): Notes about the employee. | ||
""" | ||
user_id = get_user_id(sdk, username) | ||
update_user(sdk, user_id, cloud_alias, notes=notes) | ||
sdk.detectionlists.departing_employee.add(user_id, departure_date) | ||
|
||
|
||
def remove_departing_employee(sdk, profile, username): | ||
user_id = get_user_id(sdk, username) | ||
sdk.detectionlists.departing_employee.remove(user_id) | ||
|
||
|
||
def _load_add_description(argument_collection): | ||
load_user_descriptions(argument_collection) | ||
departure_date = argument_collection.arg_configs[u"departure_date"] | ||
departure_date.set_help(u"The date the employee is departing in format YYYY-MM-DD.") |
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,91 @@ | ||
from datetime import datetime, timedelta | ||
import re | ||
|
||
from c42eventextractor.common import convert_datetime_to_timestamp | ||
|
||
|
||
_FORMAT_VALUE_ERROR_MESSAGE = ( | ||
u"input must be a date/time string (e.g. 'YYYY-MM-DD', " | ||
u"'YY-MM-DD HH:MM', 'YY-MM-DD HH:MM:SS'), or a short value in days, " | ||
u"hours, or minutes (e.g. 30d, 24h, 15m)" | ||
) | ||
|
||
TIMESTAMP_REGEX = re.compile(u"(\d{4}-\d{2}-\d{2})\s*(.*)?") | ||
MAGIC_TIME_REGEX = re.compile(u"(\d+)([dhm])$") | ||
|
||
|
||
class DateArgumentException(Exception): | ||
def __init__(self, message=_FORMAT_VALUE_ERROR_MESSAGE): | ||
super(DateArgumentException, self).__init__(message) | ||
|
||
|
||
def parse_min_timestamp(begin_date_str, max_days_back=90): | ||
dt = _parse_timestamp(begin_date_str, _round_datetime_to_day_start) | ||
|
||
boundary_date = _round_datetime_to_day_start(datetime.utcnow() - timedelta(days=max_days_back)) | ||
if dt < boundary_date: | ||
raise DateArgumentException(u"'Begin date' must be within 90 days.") | ||
|
||
return convert_datetime_to_timestamp(dt) | ||
|
||
|
||
def parse_max_timestamp(end_date_str): | ||
dt = _parse_timestamp(end_date_str, _round_datetime_to_day_end) | ||
return convert_datetime_to_timestamp(dt) | ||
|
||
|
||
def _parse_timestamp(date_str, rounding_func): | ||
timestamp_match = TIMESTAMP_REGEX.match(date_str) | ||
magic_match = MAGIC_TIME_REGEX.match(date_str) | ||
|
||
if timestamp_match: | ||
date, time = timestamp_match.groups() | ||
dt = _get_dt_from_date_time_pair(date, time) | ||
if not time: | ||
dt = rounding_func(dt) | ||
|
||
elif magic_match: | ||
num, period = magic_match.groups() | ||
dt = _get_dt_from_magic_time_pair(num, period) | ||
if period == u"d": | ||
dt = rounding_func(dt) | ||
|
||
else: | ||
raise DateArgumentException() | ||
return dt | ||
|
||
|
||
def _get_dt_from_date_time_pair(date, time): | ||
date_format = u"%Y-%m-%d %H:%M:%S" | ||
if time: | ||
time = u"{}:{}:{}".format(*time.split(":") + [u"00", u"00"]) | ||
else: | ||
time = u"00:00:00" | ||
date_string = u"{} {}".format(date, time) | ||
try: | ||
dt = datetime.strptime(date_string, date_format) | ||
except ValueError: | ||
raise DateArgumentException() | ||
else: | ||
return dt | ||
|
||
|
||
def _get_dt_from_magic_time_pair(num, period): | ||
num = int(num) | ||
if period == u"d": | ||
dt = datetime.utcnow() - timedelta(days=num) | ||
elif period == u"h": | ||
dt = datetime.utcnow() - timedelta(hours=num) | ||
elif period == u"m": | ||
dt = datetime.utcnow() - timedelta(minutes=num) | ||
else: | ||
raise DateArgumentException(u"Couldn't parse magic time string: {}{}".format(num, period)) | ||
return dt | ||
|
||
|
||
def _round_datetime_to_day_start(dt): | ||
return dt.replace(hour=0, minute=0, second=0, microsecond=0) | ||
|
||
|
||
def _round_datetime_to_day_end(dt): | ||
return dt.replace(hour=23, minute=59, second=59, microsecond=999000) |
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
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.
I like having this pulled out of
cmds