def create_snyk_item_in_postgres(item_in_json): connect_database() sid = 0 # TODO: Clearup all fields lstrip/rstrip item_in_json["disclosed"] = datetime.utcnow() if item_in_json["disclosed"] == "undefined" else item_in_json["disclosed"] item_in_json["published"] = datetime.utcnow() if item_in_json["published"] == "undefined" else item_in_json["published"] snyk = SNYK( type=str(item_in_json["type"]), cve_id=str(item_in_json["cve_id"]), cve_url=str(item_in_json["cve_url"]), cwe_id=str(item_in_json["cwe_id"]), cwe_url=str(item_in_json["cwe_url"]), header_title=str(item_in_json["header_title"]), affecting_github=str(item_in_json["affecting_github"]), versions=str(item_in_json["versions"]), overview=str(item_in_json["overview"]), references=str(item_in_json["references"]), credit=str(item_in_json["credit"]), snyk_id=str(item_in_json["snyk_id"]), source=str(item_in_json["source"]), source_url=str(item_in_json["source_url"]), disclosed=str(item_in_json["disclosed"]), published=str(item_in_json["published"]) ) snyk.save() disconnect_database() return sid
def count_snyk_table(): connect_database() count = SNYK.select().count() if count: disconnect_database() return count return 0
def update_snyk_item_in_postgres(item_in_json, sid): connect_database() snyk = SNYK.get_by_id(sid) modified = False if snyk.type != item_in_json["type"] or \ snyk.cve_id != item_in_json["cve_id"] or \ snyk.cve_url != item_in_json["cve_url"]or \ snyk.cwe_id != item_in_json["cwe_id"] or \ snyk.cwe_url != item_in_json["cwe_url"] or \ snyk.header_title != item_in_json["header_title"] or \ snyk.affecting_github != item_in_json["affecting_github"] or \ snyk.versions != item_in_json["versions"] or \ snyk.overview != item_in_json["overview"] or \ snyk.details != item_in_json["details"] or \ snyk.references != item_in_json["references"] or \ snyk.credit != item_in_json["credit"] or \ snyk.snyk_id != item_in_json["snyk_id"] or \ snyk.source != item_in_json["source"] or \ snyk.source_url != item_in_json["source_url"]: modified = True if modified: item_in_json["disclosed"] = datetime.utcnow() if item_in_json[ "disclosed"] == "undefined" else item_in_json["disclosed"] item_in_json["published"] = datetime.utcnow() if item_in_json[ "published"] == "undefined" else item_in_json["published"] snyk.type = item_in_json["type"] snyk.cve_id = item_in_json["cve_id"] snyk.cve_url = item_in_json["cve_url"] snyk.cwe_id = item_in_json["cwe_id"] snyk.cwe_url = item_in_json["cwe_url"] snyk.header_title = item_in_json["header_title"] snyk.affecting_github = item_in_json["affecting_github"] snyk.versions = item_in_json["versions"] snyk.overview = item_in_json["overview"] snyk.details = item_in_json["details"] snyk.references = item_in_json["references"] snyk.credit = item_in_json["credit"] snyk.snyk_id = item_in_json["snyk_id"] snyk.source = item_in_json["source"] snyk.source_url = item_in_json["source_url"] snyk.disclosed = item_in_json["disclosed"] snyk.published = item_in_json["published"] snyk.save() disconnect_database() return True else: disconnect_database() return False
def check_if_snyk_item_exists_in_postgres(item_in_json): connect_database() sid = -1 snyks = [] # if "cve_id" in item_in_json and "header_title" in item_in_json: # cve_id = item_in_json["cve_id"] # header_title = item_in_json["header_title"] if "snyk_id" in item_in_json: snyk_id = item_in_json["snyk_id"] snyks = list(SNYK.select().where( # (SNYK.cve_id == cve_id) & (SNYK.header_title == header_title) & (SNYK.snyk_id == snyk_id) (SNYK.snyk_id == snyk_id))) if len(snyks) == 0: disconnect_database() return False, sid else: sid = snyks[0].to_json["id"] disconnect_database() return True, sid
def create_snyk_table(): if not SNYK.table_exists(): SNYK.create_table()
def drop_snyk_table(): if SNYK.table_exists(): SNYK.drop_table()
def create_snyk_table(): connect_database() if not SNYK.table_exists(): SNYK.create_table() disconnect_database()
def drop_snyk_table(): connect_database() if SNYK.table_exists(): SNYK.drop_table() disconnect_database()