def main(): # Get arguments passed from the command line args = Arguments().get_args() # Instantiate an Aws session based on the profile name aws = AwsServices(args.profile) # Scan all services that are specified in aws.service_mappings items = aws.scan_services() # Create a new workbook based on the workbook name excel = ExcelWorkbooks(args.workbook_name) service_mappings = aws.get_service_mappings() # Iterate through the aws service mappings for service in service_mappings: for service_attr, jq_filter in service_mappings[service].items(): # Format the service_attr into something more appealing since this # is used for setting the worksheets name service_name = service_attr.replace('describe_', '').replace('_', ' ') excel.create_worksheet(service_name) # Leverage `pyjq` to iterate through a valid aws service response # and parse the details into what we need. `jq_filter` should be # a valid `jq` filter string filtered_items = pyjq.all(jq_filter, items[service][service_attr]) try: excel.create_headers_from_dict(service_name, filtered_items[0]) excel.add_rows_to_worksheet_from_json(service_name, filtered_items) except IndexError: pass excel.close()
def main(): # Get arguments passed from the command line args = Arguments().get_args() # Instantiate an Aws session based on the profile name aws = AwsServices(args.profile) # Scan all services that are specified in aws.service_mappings items = aws.scan_services() # Create a new workbook based on the workbook name if not os.path.exists(str(os.getcwd()) + '/Inventory_Documentation'): os.makedirs(str(os.getcwd()) + '/Inventory_Documentation/') try: excel = ExcelWorkbooks(args.workbook_name) except: timestr = time.strftime("%m:%d:%Y time %H %M %S") excel = ExcelWorkbooks( str(os.getcwd()) + '/Inventory_Documentation/' + str(args.profile) + ' Nessus Snucovery Inventory' + timestr) #excel = ExcelWorkbooks("test") #else: service_mappings = aws.get_service_mappings() # Iterate through the aws service mappings for service in service_mappings: for service_attr, jq_filter in service_mappings[service].items(): # Format the service_attr into something more appealing since this # is used for setting the worksheets name service_name = service_attr.replace('describe_', '').replace('_', ' ') excel.create_worksheet(service_name) # Leverage `pyjq` to iterate through a valid aws service response # and parse the details into what we need. `jq_filter` should be # a valid `jq` filter string filtered_items = pyjq.all(jq_filter, items[service][service_attr]) try: excel.create_headers_from_dict(service_name, filtered_items[0]) excel.add_rows_to_worksheet_from_json(service_name, filtered_items) except IndexError: pass excel.close() printer(excel.workbook_name)
def test_init_aws_service(self): excel = ExcelWorkbooks('test_workbook.xlsx') self.assertIsInstance(excel, object)
def test_get_workbook_with_unset(self): excel = ExcelWorkbooks('test_workbook') del excel.workbook self.assertTrue(excel.get_workbook())
def test_get_workbook(self): excel = ExcelWorkbooks('test_workbook') self.assertTrue(excel.get_workbook())
def test_set_workbook_name_with_ext(self): excel = ExcelWorkbooks('test_workbook.xlsx') self.assertEqual(excel.workbook_name, 'test_workbook.xlsx')
def test_get_worksheet_raise_exception(self): excel = ExcelWorkbooks('test_workbook') with self.assertRaises(WorksheetNotExists): excel.get_worksheet('foo_test')
def test_get_worksheet(self): excel = ExcelWorkbooks('test_workbook') excel.create_worksheet('foo_test') self.assertTrue(excel.get_worksheet('foo_test'))
def test_get_worksheets(self): excel = ExcelWorkbooks('test_workbook') excel.create_worksheet('foo_test') self.assertGreater(len(excel.get_worksheets()), 0)
def test_add_new_worksheet(self): excel = ExcelWorkbooks('test_workbook') excel.create_worksheet('foo_test') self.assertTrue(excel.worksheets['foo_test'])
def test_create_worksheet_fail(self): excel = ExcelWorkbooks('test_workbook') with self.assertRaises(InvalidWorksheetName): excel.create_worksheet('')
def test_create_worksheet(self): excel = ExcelWorkbooks('test_workbook') worksheet = excel.create_worksheet('foo') self.assertIsInstance(worksheet, object)
def test_get_workbook_name_no_ext(self): excel = ExcelWorkbooks('test_workbook') self.assertEqual(excel.workbook_name[-5:], '.xlsx')
def test_create_workbook(self): excel = ExcelWorkbooks('test_workbook.xlsx') self.assertTrue(excel.workbook)