Skip to content

Commit

Permalink
Refactor API requests to disable SSL verification
Browse files Browse the repository at this point in the history
  • Loading branch information
rishsriv committed Sep 12, 2024
1 parent 5d20c65 commit 168ac0a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
17 changes: 11 additions & 6 deletions defog/admin_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def update_db_schema(self, path_to_csv, dev=False, temp=False):
"dev": dev,
"temp": temp,
},
verify=False,
)
resp = r.json()
return resp
Expand All @@ -58,7 +59,7 @@ def update_glossary(
}
if customized_glossary:
data["customized_glossary"] = customized_glossary
r = requests.post(f"{self.base_url}/update_glossary", json=data)
r = requests.post(f"{self.base_url}/update_glossary", json=data, verify=False)
resp = r.json()
return resp

Expand All @@ -73,7 +74,7 @@ def delete_glossary(self, user_type=None, dev=False):
}
if user_type:
data["key"] = user_type
r = requests.post(f"{self.base_url}/delete_glossary", json=data)
r = requests.post(f"{self.base_url}/delete_glossary", json=data, verify=False)
if r.status_code == 200:
print("Glossary deleted successfully.")
else:
Expand All @@ -88,6 +89,7 @@ def get_glossary(self, mode="general", dev=False):
r = requests.post(
f"{self.base_url}/get_metadata",
json={"api_key": self.api_key, "dev": dev},
verify=False,
)
resp = r.json()
if mode == "general":
Expand All @@ -103,6 +105,7 @@ def get_metadata(self, format="markdown", export_path=None, dev=False):
r = requests.post(
f"{self.base_url}/get_metadata",
json={"api_key": self.api_key, "dev": dev},
verify=False,
)
resp = r.json()
items = []
Expand Down Expand Up @@ -131,8 +134,7 @@ def get_feedback(self, n_rows: int = 50, start_from: int = 0):
Gets the feedback on the defog servers.
"""
r = requests.post(
f"{self.base_url}/get_feedback",
json={"api_key": self.api_key},
f"{self.base_url}/get_feedback", json={"api_key": self.api_key}, verify=False
)
resp = r.json()
df = pd.DataFrame(resp["data"], columns=resp["columns"])
Expand All @@ -149,8 +151,7 @@ def get_quota(self) -> Optional[Dict]:
"""
api_key = self.api_key
response = requests.post(
f"{self.base_url}/check_api_usage",
json={"api_key": api_key},
f"{self.base_url}/check_api_usage", json={"api_key": api_key}, verify=False
)
# get status code and return None if not 200
if response.status_code != 200:
Expand Down Expand Up @@ -187,6 +188,7 @@ def update_golden_queries(
"scrub": scrub,
"dev": dev,
},
verify=False,
)
resp = r.json()
print(
Expand Down Expand Up @@ -220,6 +222,7 @@ def delete_golden_queries(
r = requests.post(
f"{self.base_url}/delete_golden_queries",
json={"api_key": self.api_key, "all": True, "dev": dev},
verify=False,
)
resp = r.json()
print("All golden queries have now been deleted.")
Expand All @@ -235,6 +238,7 @@ def delete_golden_queries(
"api_key": self.api_key,
"golden_queries": golden_queries,
},
verify=False,
)
resp = r.json()
return resp
Expand All @@ -252,6 +256,7 @@ def get_golden_queries(
"api_key": self.api_key,
"dev": dev,
},
verify=False,
)
resp = r.json()
golden_queries = resp["golden_queries"]
Expand Down
1 change: 1 addition & 0 deletions defog/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def vet_metadata():
"column_name": column_name,
"column_description": column_description,
},
verify=False,
)
resp = r.json()
new_column_description = resp["column_description"]
Expand Down
7 changes: 7 additions & 0 deletions defog/generate_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def generate_postgres_schema(
"api_key": self.api_key,
"schemas": table_columns,
},
verify=False,
)
resp = r.json()
if "csv" in resp:
Expand Down Expand Up @@ -193,6 +194,7 @@ def generate_redshift_schema(
"foreign_keys": [],
"indexes": [],
},
verify=False,
)
resp = r.json()
if "csv" in resp:
Expand Down Expand Up @@ -268,6 +270,7 @@ def generate_mysql_schema(
"foreign_keys": [],
"indexes": [],
},
verify=False,
)
resp = r.json()
if "csv" in resp:
Expand Down Expand Up @@ -342,6 +345,7 @@ def generate_databricks_schema(
"foreign_keys": [],
"indexes": [],
},
verify=False,
)
resp = r.json()
if "csv" in resp:
Expand Down Expand Up @@ -435,6 +439,7 @@ def generate_snowflake_schema(
"foreign_keys": [],
"indexes": [],
},
verify=False,
)
resp = r.json()
if "csv" in resp:
Expand Down Expand Up @@ -508,6 +513,7 @@ def generate_bigquery_schema(
"foreign_keys": [],
"indexes": [],
},
verify=False,
)
resp = r.json()
if "csv" in resp:
Expand Down Expand Up @@ -589,6 +595,7 @@ def generate_sqlserver_schema(
"foreign_keys": [],
"indexes": [],
},
verify=False,
)
resp = r.json()
if "csv" in resp:
Expand Down
5 changes: 5 additions & 0 deletions defog/health_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def check_golden_queries_coverage(self, dev: bool = False):
r = requests.post(
f"{self.base_url}/get_golden_queries_coverage",
json={"api_key": self.api_key, "dev": dev},
verify=False,
)
resp = r.json()
return resp
Expand All @@ -24,6 +25,7 @@ def check_md_valid(self, dev: bool = False):
r = requests.post(
f"{self.base_url}/check_md_valid",
json={"api_key": self.api_key, "db_type": self.db_type, "dev": dev},
verify=False,
)
resp = r.json()
return resp
Expand All @@ -38,6 +40,7 @@ def check_gold_queries_valid(self, dev: bool = False):
r = requests.post(
f"{self.base_url}/check_gold_queries_valid",
json={"api_key": self.api_key, "db_type": self.db_type, "dev": dev},
verify=False,
)
resp = r.json()
return resp
Expand All @@ -50,6 +53,7 @@ def check_glossary_valid(self, dev: bool = False):
r = requests.post(
f"{self.base_url}/check_glossary_valid",
json={"api_key": self.api_key, "dev": dev},
verify=False,
)
resp = r.json()
return resp
Expand All @@ -62,6 +66,7 @@ def check_glossary_consistency(self, dev: bool = False):
r = requests.post(
f"{self.base_url}/check_glossary_consistency",
json={"api_key": self.api_key, "dev": dev},
verify=False,
)
resp = r.json()
return resp
2 changes: 2 additions & 0 deletions defog/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def execute_query(
"temp": temp,
},
timeout=1,
verify=False,
)
except:
pass
Expand All @@ -364,6 +365,7 @@ def execute_query(
r = requests.post(
f"{base_url}/retry_query_after_error",
json=retry,
verify=False,
)
response = r.json()
new_query = response["new_query"]
Expand Down
9 changes: 9 additions & 0 deletions defog/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def get_feedback(
f"{base_url}/feedback",
json=data,
timeout=1,
verify=False,
)
if feedback == "y":
print("Thank you for the feedback!")
Expand All @@ -289,6 +290,7 @@ def get_feedback(
response = requests.post(
f"{base_url}/reflect_on_error",
json=data,
verify=False,
)

if response.status_code == 200:
Expand All @@ -309,6 +311,7 @@ def get_feedback(
md_resp = requests.post(
f"{base_url}/get_metadata",
json={"api_key": api_key},
verify=False,
)
md_resp_dict = md_resp.json()
glossary_current = md_resp_dict.get("glossary", "")
Expand All @@ -319,12 +322,14 @@ def get_feedback(
"api_key": api_key,
"glossary": glossary_updated,
},
verify=False,
)
print("Glossary updated successfully.\n")
elif add_to_glossary != "n":
md_resp = requests.post(
f"{base_url}/get_metadata",
json={"api_key": api_key},
verify=False,
)
md_resp_dict = md_resp.json()
glossary_current = md_resp_dict.get("glossary", "")
Expand All @@ -335,6 +340,7 @@ def get_feedback(
"api_key": api_key,
"glossary": glossary_updated,
},
verify=False,
)
print("Glossary updated successfully.\n")
else:
Expand All @@ -350,6 +356,7 @@ def get_feedback(
r = requests.post(
f"{base_url}/get_metadata",
json={"api_key": api_key},
verify=False,
)
resp = r.json()
md = resp.get("table_metadata", {})
Expand Down Expand Up @@ -392,6 +399,7 @@ def get_feedback(
"table_metadata": new_column_description,
"db_type": db_type,
},
verify=False,
)
print("Metadata updated successfully.\n")
else:
Expand Down Expand Up @@ -423,6 +431,7 @@ def get_feedback(
"golden_queries": reference_queries_to_add,
"scrub": True,
},
verify=False,
)
if r.status_code == 200:
print(
Expand Down

0 comments on commit 168ac0a

Please sign in to comment.