Skip to content

Commit

Permalink
fix slack notifs. use real requests library
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel committed Jun 21, 2020
1 parent c18dbd3 commit 5c2bcae
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lambda/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pack:
./pack.sh

remove:
aws s3 rm s3://s3eker-buckets/s3eker-open.s3-website-us-east-1.amazonaws.com
2 changes: 1 addition & 1 deletion lambda/ingest/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from botocore.vendored import requests
import requests
import logging
import boto3
import botocore
Expand Down
1 change: 1 addition & 0 deletions lambda/ingest/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
30 changes: 24 additions & 6 deletions lambda/scan/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
from botocore.vendored import requests
import requests
import boto3
from botocore.exception import InsufficientPermissionsException, ClientError
import json
from botocore.exceptions import ClientError
import base64

logging.basicConfig()
Expand All @@ -19,12 +20,15 @@ def main(event, context):
logging.info(f"Bucket {target_bucket} is open!")

webhook = get_secret()
response = requests.post(webhook, headers={'Content-type': 'application/json'}, data={"text": f"Bucket {target_bucket} is open!"})
response = requests.post(webhook, headers={'Content-type': 'application/json'}, data=json.dumps({"text": f"Bucket `{target_bucket}` is open!"}))
if response.status_code != 200:
logging.error(f"Slack returned status code {response.status_code}.")

except InsufficientPermissionsException:
logging.info(f"Permission denied for bucket {target_bucket}")
except ClientError as e:
if e.response['Error']['Code'] == "AccessDenied":
logging.info(f"Permission denied for bucket {target_bucket}")
else:
raise

def get_secret():

Expand Down Expand Up @@ -77,4 +81,18 @@ def get_secret():


if __name__ == "__main__":
main(None, None)
blah = {
'Records': [
{
's3': {
'bucket': {
'name': 'bloopy'
},
'object': {
'key': 's3eker-open.s3-website-us-east-1.amazonaws.com'
}
}
}
]
}
main(blah, None)
1 change: 1 addition & 0 deletions lambda/scan/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests

0 comments on commit 5c2bcae

Please sign in to comment.