-
Notifications
You must be signed in to change notification settings - Fork 194
Security groups request ids #935
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
Security groups request ids #935
Conversation
The python api will now output a table with requestIDs for specific calls to security groups apis
Fix unit tests Fix code style issues
Add new return format
Add functionality to get event logs to slcli
Fix Security Group unit tests
Refactor Event Log Code Fix Unit Tests Add Unit Tests Fix Code Styling
Remove unneeded code left over from refactoring Fix incorrect package name
Code Styling changes
Change public facing name to Audit Logs Add functionality to get event log types
Fix ordering of test expecations to be Actual then Expected
Add functionality to filter by eventName
Add functionality to filter by dates
Add request id search functionality
Fix fixtures from merge
Fix tox issues
rlrossiter
left a comment
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 did a first pass through the event log side of things, and I think there could be a little shuffling to organize what functions are where to make it a little more usable.
From an interface standpoint, I think you could have 2 functions on the event log manager publicly exposed, get_logs_by_event() and get_logs_by_object() (or break it apart in any way that makes sense) that would contain most of the filter building that currently exists within the CLI.
We can then add a function to either the event log manager that then gets the audit logs for SG operations. Then the sg CLI could have an extra command add it that does the request log querying instead of building SG functionality into the event log CLI.
SoftLayer/CLI/event_log/get.py
Outdated
|
|
||
|
|
||
| @click.command() | ||
| @click.option('--date_min', '-d', |
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.
For consistency, all of these options should be --date-min (dash in middle instead of underscore). As for the args, click automatically changes it for you (so --date-min becomes date_min)
SoftLayer/CLI/event_log/get.py
Outdated
| @click.option('--obj_id', '-i', | ||
| help="The id of the object we want to get audit logs for") | ||
| @click.option('--request_id', '-r', | ||
| help="The request id we want to look for. If this is set, we will ignore all other arguments.") |
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'd rather throw an error if they're used together instead of ignoring all other arguments. That way it isn't silently doing something the user may not be aware of
SoftLayer/CLI/event_log/get.py
Outdated
| """Get Audit Logs""" | ||
| mgr = SoftLayer.EventLogManager(env.client) | ||
|
|
||
| if request_id is not None: |
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.
So down here you'd add a check for if request_id and any(date_min, date_max, obj_event, ....) and you'd raise a CLIAbort on it
SoftLayer/CLI/event_log/get.py
Outdated
| @click.option('--obj_type', '-t', | ||
| help="The type of the object we want to get audit logs for") | ||
| @click.option('--utc_offset', '-z', | ||
| help="UTC Offset for seatching with dates. The default is -0500") |
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'm nervous to force people into -0500. I'd lean more towards if they don't specify it, just leave it at 0.
SoftLayer/CLI/event_log/get.py
Outdated
| return filtered_logs | ||
|
|
||
|
|
||
| def _parse_date(date_string, utc_offset): |
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'd move this to a utility and unit test the heck out of it since this looks a little complex
SoftLayer/CLI/event_log/get.py
Outdated
| if date_min and date_max: | ||
| request_filter['eventCreateDate'] = { | ||
| 'operation': 'betweenDate', | ||
| 'options': [ |
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.
There are utils for building date filters https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/utils.py#L111. Not sure if that can be used for these as well
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.
These won't work for this case, because of where the Event_Log entries are stored.
We need to have a different filter format for it to work.
SoftLayer/CLI/event_log/get.py
Outdated
| env.fout(table) | ||
|
|
||
|
|
||
| def _build_filter(date_min, date_max, obj_event, obj_id, obj_type, utc_offset): |
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 think this should get moved to the manager instead of doing all of the legwork in the CLI. That way if people want to find certain event logs when using python, they can borrow this filter building.
SoftLayer/managers/event_log.py
Outdated
| :param dict request_filter: filter dict | ||
| :returns: List of event logs | ||
| """ | ||
| results = self.client.call("Event_Log", |
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.
From a convention standpoint, usually you can just store the event log service on the manager itself. So you'd add self.event_log = client['Event_Log'] to __init__(), and then in these functions you can just do self.event_log.getAllObjects(filter=request_filter)
change date_min to date-min in click args change date_max to date-max in click args change how the event log client is initialized move filter building code into event log manager set default utc offset to +0000 move date parsing code into utils add ability to get event logs by type add ability to get event logs by name move requestID searching into Security Groups code Overhaul unit tests
rlrossiter
left a comment
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.
Looks like we're getting close. I tried out most of the slcli audit-log command. I still need to try out the slcli sg audit-log to check that as well, but just wanted to post a few of the comments that I had.
|
|
||
| self.assertEqual(expected, result) | ||
|
|
||
| def test__get_cci_event_logs(self): |
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.
This isn't super important, but it looks like you've got two _ between test and get.
| @click.option('--obj_type', '-t', | ||
| help="The type of the object we want to get audit logs for") | ||
| @click.option('--utc_offset', '-z', | ||
| help="UTC Offset for seatching with dates. The default is -0000") |
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.
searching is misspelled here
| help='The earliest date we want to search for audit logs in mm/dd/yyyy format.') | ||
| @click.option('--date-max', '-D', | ||
| help='The latest date we want to search for audit logs in mm/dd/yyyy format.') | ||
| @click.option('--obj_event', '-e', |
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.
All of these other options still need to be switched over to use - instead of _ as well
| @click.argument('request_id') | ||
| @environment.pass_env | ||
| def get_by_request_id(env, request_id): | ||
| """Search for event logs by request id""" |
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.
(venv) ryans-mbp-2:softlayer-python rlrossit$ slcli sg audit-log -h
Usage: slcli sg audit-log [OPTIONS] REQUEST_ID
Search for event logs by request id
Having it be called sg audit log, with the help text then showing "Search for event logs" is kind of confusing. It looks like throughout most of this PR audit log and event log are being used interchangeably. I'd settle on one of the names, and use it everywhere (file/class names, CLI, etc.)
| raise exceptions.CLIAbort("Could not detach network component") | ||
|
|
||
| table = formatting.Table(REQUEST_COLUMNS) | ||
| table.add_row([success['requestId']]) |
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'd rename the success variable returned from detach, since using it in this situation reads weird. I'd just use ret like all of the other functions are using.
| } | ||
|
|
||
|
|
||
| def format_event_log_date(date_string, utc): |
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.
So it kinda surprises me that there are no unit tests for the utils module, but we should probably have some tests for these functions.
|
@fisherma91 have you had a chance to look at Ryan's suggestions? |
|
@allmightyspiff I have. I've just been heads down with forward development and haven't been able to work in his feedback. |
|
going to be finished in #1099 |
This PR adds the following features to SoftLayer Python:
SoftLayer_Network_SecurityGroup.addRules(),SoftLayer_Network_SecurityGroup.editRules(),SoftLayer_Network_SecurityGroup.removeRules(),SoftLayer_Network_SecurityGroup. attachNetworkComponents()andSoftLayer_Network_SecurityGroup. detachNetworkComponents()Event_Log. getAllEventObjectNames()Event_Logobjects by type, date range, and requestId (Value now returned by the modifiedSoftLayer_Network_SecurityGroupmethods mentioned above)