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 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 test_scan_service_raise_unknown_service_call(self): aws = AwsServices('test') with self.assertRaises(UnknownServiceCall): aws.scan_service('describe_instanes', 'ec2')
def test_scan_service_raise_service_error(self): aws = AwsServices('test') with self.assertRaises(UnknownServiceError): aws.scan_service('describe_instances', 'ec22')
def test_scan_service(self): aws = AwsServices('test') items = aws.scan_service('describe_instances', 'ec2') self.assertGreater(len(items), 0)
def test_scan_services(self): aws = AwsServices('test') items = aws.scan_services() self.assertGreater(len(items), 0)
def test_get_service_mappings_empty(self): aws = AwsServices('test') aws.service_mappings = {} with self.assertRaises(InvalidServiceMappings): aws.get_service_mappings()
def test_get_service_mappings(self): aws = AwsServices('test') self.assertGreater(len(aws.get_service_mappings()), 0)
def test_init_aws_service_fail(self): with self.assertRaises(ProfileNotFound): AwsServices('test-fail')
def test_init_aws_service(self): aws = AwsServices('test') self.assertIsInstance(aws, object) self.assertTrue(aws.session)