Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up[apps] Aliyun ActionTrail app #792
Conversation
|
this is nice work!! added a few quick first round comments :) |
|
|
||
| from aliyunsdkcore.client import AcsClient | ||
| from aliyunsdkcore.acs_exception.exceptions import ClientException | ||
| from aliyunsdkcore.acs_exception.exceptions import ServerException |
ryandeivert
Jul 25, 2018
Contributor
can you group this exception with the import above pls
can you group this exception with the import above pls
|
|
||
| from app_integrations import LOGGER | ||
| from app_integrations.apps.app_base import StreamAlertApp, AppIntegration | ||
|
|
ryandeivert
Jul 25, 2018
Contributor
add an extra new line here please (2 lines between imports and class declarations)
add an extra new line here please (2 lines between imports and class declarations)
|
|
||
| def _gather_logs(self): | ||
| auth = self._config.auth | ||
| client = AcsClient(auth['access_key_id'], auth['access_key_secret'], auth['region_id']) |
ryandeivert
Jul 25, 2018
Contributor
the _gather_logs method could be called a bunch of times in an execution - therefore, would it make sense to have the AcsClient created upon __init__ and cached as an instance property?
the _gather_logs method could be called a bunch of times in an execution - therefore, would it make sense to have the AcsClient created upon __init__ and cached as an instance property?
|
|
||
| return json_response['Events'] | ||
|
|
||
| except ServerException as e: |
ryandeivert
Jul 25, 2018
Contributor
These two except blocks could be consolidated into one with:
except (ServerException, ClientException) as err:
LOGGER.exception("%s exception occurred", err.get_error_type())
return False
also, there's no need to include the actual content of the exception (with str(e)) when using LOGGER.exception - this call handles all of that for you.
These two except blocks could be consolidated into one with:
except (ServerException, ClientException) as err:
LOGGER.exception("%s exception occurred", err.get_error_type())
return False
also, there's no need to include the actual content of the exception (with str(e)) when using LOGGER.exception - this call handles all of that for you.
| def region_validator(region): | ||
| """Region names pulled from https://www.alibabacloud.com/help/doc-detail/40654.htm""" | ||
|
|
||
| if region in ["cn-qingdao", "cn-beijing", "cn-zhangjiakou", "cn-huhehaote", |
ryandeivert
Jul 25, 2018
Contributor
please use single (') quotes on string literals and not double (") quotes
please use single (') quotes on string literals and not double (") quotes
chunyong-lin
Jul 25, 2018
Contributor
Small request, can we use set instead of list, it is not big a deal though.
Small request, can we use set instead of list, it is not big a deal though.
| 'access_key_id': { | ||
| 'description': ('The access key id generated for a RAM user. This ' | ||
| 'should be a string of alphanumeric characters.'), | ||
| 'format': re.compile(r'.*') |
ryandeivert
Jul 25, 2018
Contributor
are there no restrictions similar to AWS for their access and secret keys? ie - AWS access keys are 20 alphanumeric all-caps characters and must start with A, etc
are there no restrictions similar to AWS for their access and secret keys? ie - AWS access keys are 20 alphanumeric all-caps characters and must start with A, etc
GarretReece
Jul 26, 2018
Author
Contributor
I can't find any documentation anywhere regarding the format. The values I have are a mix of digits and upper and lower case letters, with the id 16 characters in length and the secret 30 characters in length. I'm perfectly willing to put those in as restrictions, but I don't have any reference for that being the supported format.
I can't find any documentation anywhere regarding the format. The values I have are a mix of digits and upper and lower case letters, with the id 16 characters in length and the secret 30 characters in length. I'm perfectly willing to put those in as restrictions, but I don't have any reference for that being the supported format.
| 'region_id': { | ||
| 'description': ('The region for the Aliyun API. This should be ' | ||
| 'a string like \'ap-northeast-1\'.'), | ||
| 'format': region_validator |
ryandeivert
Jul 25, 2018
Contributor
++ this is great
++ this is great
| Returns: | ||
| int: Number of seconds the polling function should sleep for | ||
| """ | ||
| return 0 |
ryandeivert
Jul 25, 2018
Contributor
I think if this is 0 it can be left off completely. I do like the context you've added in the docstring, though, so I'm not sure if I feel strongly about removing the method
I think if this is 0 it can be left off completely. I do like the context you've added in the docstring, though, so I'm not sure if I feel strongly about removing the method
| @@ -203,6 +203,8 @@ class AppIntegrationPackage(LambdaPackage): | |||
| package_name = 'stream_alert_app' | |||
| precompiled_libs = {'boxsdk[jwt]==2.0.0a11'} | |||
| third_party_libs = { | |||
| 'aliyun-python-sdk-core==2.8.5', | |||
ryandeivert
Jul 25, 2018
Contributor
this is great - thank you for pinning the version!
this is great - thank you for pinning the version!
| def service(cls): | ||
| return 'aliyun' | ||
|
|
||
|
|
ryandeivert
Jul 25, 2018
Contributor
Looks like there's an extra new line here
Looks like there's an extra new line here
|
Hey @GarretReece thanks for working on this App. It looks great too me. I added some comments. |
| https://www.alibabacloud.com/help/doc-detail/28849.htm | ||
| """ | ||
|
|
||
| _MAX_RESULTS = 50 |
chunyong-lin
Jul 25, 2018
Contributor
Any reason we don't pull 100 results each time?
Any reason we don't pull 100 results each time?
GarretReece
Jul 26, 2018
Author
Contributor
The documentation lists the range for the MaxResult parameter as 0-50; I'll admit I haven't tested with higher values to see if it worked anyhow.
The documentation lists the range for the MaxResult parameter as 0-50; I'll admit I haven't tested with higher values to see if it worked anyhow.
chunyong-lin
Jul 26, 2018
•
Contributor
Can I have one more testing request? Can you add a test case when NextToken is available in your testing environment? (I am not talking about unit test)
A while ago, I have a simple script to retrieve ActionTrail events, and set max results per request to 2. I encountered the issue that NextToken doesn't take effect, and the 2nd request returned as same events as 1st request recieved.
Can you verify this in the testing environment? Thanks!
Can I have one more testing request? Can you add a test case when NextToken is available in your testing environment? (I am not talking about unit test)
A while ago, I have a simple script to retrieve ActionTrail events, and set max results per request to 2. I encountered the issue that NextToken doesn't take effect, and the 2nd request returned as same events as 1st request recieved.
Can you verify this in the testing environment? Thanks!
|
|
||
| @classmethod | ||
| def _type(cls): | ||
| return 'events' |
chunyong-lin
Jul 25, 2018
Contributor
actiontrail would be more descriptive.
actiontrail would be more descriptive.
| @@ -1,3 +1,5 @@ | |||
| aliyun-python-sdk-core==2.8.5 | |||
| aliyun-python-sdk-actiontrail==2.0.0 | |||
chunyong-lin
Jul 25, 2018
Contributor
Can you add these two packages to requirements-top-level.txt as well?
Can you add these two packages to requirements-top-level.txt as well?
GarretReece
Jul 26, 2018
Author
Contributor
added them in!
added them in!
| def region_validator(region): | ||
| """Region names pulled from https://www.alibabacloud.com/help/doc-detail/40654.htm""" | ||
|
|
||
| if region in ["cn-qingdao", "cn-beijing", "cn-zhangjiakou", "cn-huhehaote", |
chunyong-lin
Jul 25, 2018
Contributor
Small request, can we use set instead of list, it is not big a deal though.
Small request, can we use set instead of list, it is not big a deal though.
| auth = self._config.auth | ||
| client = AcsClient(auth['access_key_id'], auth['access_key_secret'], auth['region_id']) | ||
|
|
||
| request = LookupEventsRequest.LookupEventsRequest() |
chunyong-lin
Jul 25, 2018
Contributor
I think we also can cache request to __init__.
I think we also can cache request to __init__.
| @@ -1666,5 +1666,40 @@ | |||
| "reason" | |||
| ] | |||
| } | |||
| }, | |||
| "aliyun:events": { | |||
chunyong-lin
Jul 25, 2018
Contributor
Remind to update schema name if you agree with me renaming _type to actiontrail.
Remind to update schema name if you agree with me renaming _type to actiontrail.
|
LGTM! |
to: @airbnb/streamalert-maintainers
cc:
size: medium
Background
SteamAlert doesn't have an app that collects ActionTrail events from Aliyun
Changes
Testing
Barebones StreamAlert session created, the Aliyun app configured and deployed, and verifying that events are listed as captured in the log