Skip to content
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

Add support to specify a report id #3

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The connectors supported by this script have some shared configuration in order
| org | True | string | This is the Socket org as in the URL of the Socket Dashboard. Generally this should match your Github Org name |
| api_key | True | string | This is the Socket API Key created in the Socket dashboard. This should have the scoped permissions to access reports |
| start_date | False | string(`YYYY-MM-DD`) | If this is not defined then it will pull all reports and their corresponding issues. If defined only reports that match or are newer than the start_date will be pulled |

| report_id | False | Socket Report ID | If this is provided then only the specified report ID will be processed |


### Example
Expand All @@ -39,11 +39,13 @@ from core.socket_reports import Reports
if __name__ == '__main__':
socket_org = os.getenv("SOCKET_ORG") or exit(1)
api_key = os.getenv("SOCKET_API_KEY") or exit(1)
start_date = os.getenv("START_DATE") or exit(1)
start_date = os.getenv("START_DATE")
report_id = os.getenv("SOCKET_REPORT_ID")
reports = Reports(
org=socket_org,
api_key=api_key,
start_date=start_date
start_date=start_date,
report_id=report_id
)
issue_data = reports.get_issues()
```
Expand Down Expand Up @@ -72,11 +74,13 @@ from core.connectors.socket_csv import SocketCSV
if __name__ == '__main__':
socket_org = os.getenv("SOCKET_ORG") or exit(1)
api_key = os.getenv("SOCKET_API_KEY") or exit(1)
start_date = os.getenv("START_DATE") or exit(1)
start_date = os.getenv("START_DATE")
report_id = os.getenv("SOCKET_REPORT_ID")
reports = Reports(
org=socket_org,
api_key=api_key,
start_date=start_date
start_date=start_date,
report_id=report_id
)
issue_data = reports.get_issues()

Expand Down Expand Up @@ -111,11 +115,13 @@ from core.connectors.bigquery import BigQuery
if __name__ == '__main__':
socket_org = os.getenv("SOCKET_ORG") or exit(1)
api_key = os.getenv("SOCKET_API_KEY") or exit(1)
start_date = os.getenv("START_DATE") or exit(1)
start_date = os.getenv("START_DATE")
report_id = os.getenv("SOCKET_REPORT_ID")
reports = Reports(
org=socket_org,
api_key=api_key,
start_date=start_date
start_date=start_date,
report_id=report_id
)
issue_data = reports.get_issues()
bigquery_table = os.getenv('GOOGLE_TABLE') or exit(1)
Expand Down Expand Up @@ -145,11 +151,13 @@ from core.connectors.panther import Panther
if __name__ == '__main__':
socket_org = os.getenv("SOCKET_ORG") or exit(1)
api_key = os.getenv("SOCKET_API_KEY") or exit(1)
start_date = os.getenv("START_DATE") or exit(1)
start_date = os.getenv("START_DATE")
report_id = os.getenv("SOCKET_REPORT_ID")
reports = Reports(
org=socket_org,
api_key=api_key,
start_date=start_date
start_date=start_date,
report_id=report_id
)
issue_data = reports.get_issues()
panther_url = os.getenv('PANTHER_URL') or exit(1)
Expand All @@ -176,11 +184,13 @@ from core.connectors.elastic import Elastic
if __name__ == '__main__':
socket_org = os.getenv("SOCKET_ORG") or exit(1)
api_key = os.getenv("SOCKET_API_KEY") or exit(1)
start_date = os.getenv("START_DATE") or exit(1)
start_date = os.getenv("START_DATE")
report_id = os.getenv("SOCKET_REPORT_ID")
reports = Reports(
org=socket_org,
api_key=api_key,
start_date=start_date
start_date=start_date,
report_id=report_id
)
issue_data = reports.get_issues()
elastic_token = os.getenv('ELASTIC_TOKEN') or exit(1)
Expand Down Expand Up @@ -216,11 +226,13 @@ from core.connectors.webhook import Webhook
if __name__ == '__main__':
socket_org = os.getenv("SOCKET_ORG") or exit(1)
api_key = os.getenv("SOCKET_API_KEY") or exit(1)
start_date = os.getenv("START_DATE") or exit(1)
start_date = os.getenv("START_DATE")
report_id = os.getenv("SOCKET_REPORT_ID")
reports = Reports(
org=socket_org,
api_key=api_key,
start_date=start_date
start_date=start_date,
report_id=report_id
)
issue_data = reports.get_issues()
webhook_url = os.getenv("WEBHOOK_URL") or exit(1)
Expand Down
15 changes: 13 additions & 2 deletions core/socket_reports/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ class Reports:
column_names: list
api_key: str
owner: str

def __init__(self, org: str, api_key: str, start_date: str = None):
start_date: str
report_id: str

def __init__(
self,
org: str,
api_key: str,
start_date: str = None,
report_id: str = None
):
self.base_url = f"https://socket.dev/dashboard/org/gh/{org}/reports?"
self.log = logging.getLogger('socket_reports')
self.log.addHandler(logging.NullHandler())
Expand All @@ -28,6 +36,7 @@ def __init__(self, org: str, api_key: str, start_date: str = None):
self.owner = org
self.date_format = "%Y-%m-%d"
self.socket_date_format = "%Y-%m-%dT%H:%M:%S.%fZ"
self.report_id = report_id
self.db = SqliteDB(column_names=self.column_names)
global socket
socket = SocketDev(
Expand Down Expand Up @@ -78,6 +87,8 @@ def check_collect_status(self, report: Report) -> bool:
)
if created_at >= start_date:
collect_report = True
elif self.report_id is not None and report.id == self.report_id:
collect_report = True
else:
collect_report = True
return collect_report
Expand Down