gpt-3.5-turbo-0125· OpenAI
WildChat-4.8M (AI2)
Simplify and optimize: if awsaccountid: cursor.execute( "SELECT ashc.awsaccountid,…
- User
Simplify and optimize:
if aws_account_id: cursor.execute( "SELECT ashc.aws_account_id, COUNT(CASE WHEN ashc.status = 'FAILED' THEN 1 END) AS failed_controls, COUNT(CASE WHEN ashc.status = 'PASSED' THEN 1 END) AS passed_controls FROM aws_securityhub_controls ashc WHERE aws_account_id = %s GROUP BY ashc.aws_account_id;", (aws_account_id,)) result = cursor.fetchone() data = {'aws_account_id': result[0], 'failed_controls': result[1], 'passed_controls': result[2]} else: cursor.execute( "SELECT ashc.aws_account_id, COUNT(CASE WHEN ashc.status = 'FAILED' THEN 1 END) AS failed_controls, COUNT(CASE WHEN ashc.status = 'PASSED' THEN 1 END) AS passed_controls FROM aws_securityhub_controls ashc GROUP BY ashc.aws_account_id;") result = cursor.fetchall() data = [] for item in result: data.append({'aws_account_id': item[0], 'failed_controls': item[1], 'passed_controls': item[2]}) - Assistant
If aws_account_id is provided, execute a query to select the count of failed and passed controls for the specified account ID in the AWS Security Hub Controls table. Store the results in a dictionary 'data' with the account ID, failed controls, and passed controls. If aws_account_id is not provided, execute a query to select the count of failed and passed controls for all account IDs in the AWS Security Hub Controls table. Store the results in a list of dictionaries 'data', where each dictionary contains an account ID, failed controls, and passed controls.