Insert an IP into the tracking table This function completely rebuilds the record because it is simpler and cleaner than tracking which data came from which location and whether to expire specific sections.
(
self,
ip,
source=None,
account_id=None,
cloud_env=None,
account_info=None,
fqdn=None,
)
| 567 | return rnds_value, rdns_zone |
| 568 | |
| 569 | def insert_record( |
| 570 | self, |
| 571 | ip, |
| 572 | source=None, |
| 573 | account_id=None, |
| 574 | cloud_env=None, |
| 575 | account_info=None, |
| 576 | fqdn=None, |
| 577 | ): |
| 578 | """ |
| 579 | Insert an IP into the tracking table |
| 580 | This function completely rebuilds the record because it is simpler and cleaner than tracking which |
| 581 | data came from which location and whether to expire specific sections. |
| 582 | """ |
| 583 | |
| 584 | if ip is None or ip == "": |
| 585 | self._logger.error("ERROR: Sent an invalid IP address: " + str(ip)) |
| 586 | return |
| 587 | |
| 588 | if isinstance(ip, str): |
| 589 | ip_addr = IPAddress(ip) |
| 590 | else: |
| 591 | ip_addr = ip |
| 592 | ip = str(ip_addr) |
| 593 | |
| 594 | if ip_addr is None: |
| 595 | self._logger.error("ERROR: Could not insert: " + str(ip)) |
| 596 | return |
| 597 | |
| 598 | if self.is_local_ip(ip): |
| 599 | if fqdn is not None: |
| 600 | self._logger.warning( |
| 601 | "WARNING: all_ips does not track local IP addresses: " + str(fqdn) |
| 602 | ) |
| 603 | else: |
| 604 | self._logger.warning( |
| 605 | "WARNING: all_ips does not track local IP addresses" |
| 606 | ) |
| 607 | return |
| 608 | |
| 609 | record = {} |
| 610 | record["ip"] = ip |
| 611 | record["version"] = ip_addr.version |
| 612 | record["updated"] = datetime.now() |
| 613 | |
| 614 | if account_info is not None: |
| 615 | record["accountInfo"] = account_info |
| 616 | |
| 617 | if account_id is None and account_info is not None: |
| 618 | for entry in account_info: |
| 619 | if entry["key"] == "accountId": |
| 620 | account_id = entry["value"] |
| 621 | |
| 622 | # Check existance |
| 623 | result = self._mongo_connector.perform_find_one( |
| 624 | self.all_ips_collection, {"ip": ip} |
| 625 | ) |
| 626 | if result is not None: |
no test coverage detected