forked from datahub-project/datahub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ingest/openapi): support proxies and alternate auth schemes (dat…
…ahub-project#9492) Co-authored-by: Fernando Marino <[email protected]> Co-authored-by: Harshal Sheth <[email protected]>
- Loading branch information
1 parent
cfb4d2f
commit b7a0bbc
Showing
2 changed files
with
51 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,13 @@ class OpenApiConfig(ConfigModel): | |
ignore_endpoints: list = Field(default=[], description="") | ||
username: str = Field(default="", description="") | ||
password: str = Field(default="", description="") | ||
proxies: Optional[dict] = Field( | ||
default=None, | ||
description="Eg. " | ||
"`{'http': 'http://10.10.1.10:3128', 'https': 'http://10.10.1.10:1080'}`." | ||
"If authentication is required, add it to the proxy url directly e.g. " | ||
"`http://user:[email protected]:3128/`.", | ||
) | ||
forced_examples: dict = Field(default={}, description="") | ||
token: Optional[str] = Field(default=None, description="") | ||
get_token: dict = Field(default={}, description="") | ||
|
@@ -87,9 +94,13 @@ def get_swagger(self) -> Dict: | |
password=self.password, | ||
tok_url=url4req, | ||
method=self.get_token["request_type"], | ||
proxies=self.proxies, | ||
) | ||
sw_dict = get_swag_json( | ||
self.url, token=self.token, swagger_file=self.swagger_file | ||
self.url, | ||
token=self.token, | ||
swagger_file=self.swagger_file, | ||
proxies=self.proxies, | ||
) # load the swagger file | ||
|
||
else: # using basic auth for accessing endpoints | ||
|
@@ -98,6 +109,7 @@ def get_swagger(self) -> Dict: | |
username=self.username, | ||
password=self.password, | ||
swagger_file=self.swagger_file, | ||
proxies=self.proxies, | ||
) | ||
return sw_dict | ||
|
||
|
@@ -258,10 +270,15 @@ def get_workunits_internal(self) -> Iterable[ApiWorkUnit]: # noqa: C901 | |
tot_url = clean_url(config.url + self.url_basepath + endpoint_k) | ||
|
||
if config.token: | ||
response = request_call(tot_url, token=config.token) | ||
response = request_call( | ||
tot_url, token=config.token, proxies=config.proxies | ||
) | ||
else: | ||
response = request_call( | ||
tot_url, username=config.username, password=config.password | ||
tot_url, | ||
username=config.username, | ||
password=config.password, | ||
proxies=config.proxies, | ||
) | ||
if response.status_code == 200: | ||
fields2add, root_dataset_samples[dataset_name] = extract_fields( | ||
|
@@ -281,10 +298,15 @@ def get_workunits_internal(self) -> Iterable[ApiWorkUnit]: # noqa: C901 | |
url_guess = try_guessing(endpoint_k, root_dataset_samples) | ||
tot_url = clean_url(config.url + self.url_basepath + url_guess) | ||
if config.token: | ||
response = request_call(tot_url, token=config.token) | ||
response = request_call( | ||
tot_url, token=config.token, proxies=config.proxies | ||
) | ||
else: | ||
response = request_call( | ||
tot_url, username=config.username, password=config.password | ||
tot_url, | ||
username=config.username, | ||
password=config.password, | ||
proxies=config.proxies, | ||
) | ||
if response.status_code == 200: | ||
fields2add, _ = extract_fields(response, dataset_name) | ||
|
@@ -304,10 +326,15 @@ def get_workunits_internal(self) -> Iterable[ApiWorkUnit]: # noqa: C901 | |
) | ||
tot_url = clean_url(config.url + self.url_basepath + composed_url) | ||
if config.token: | ||
response = request_call(tot_url, token=config.token) | ||
response = request_call( | ||
tot_url, token=config.token, proxies=config.proxies | ||
) | ||
else: | ||
response = request_call( | ||
tot_url, username=config.username, password=config.password | ||
tot_url, | ||
username=config.username, | ||
password=config.password, | ||
proxies=config.proxies, | ||
) | ||
if response.status_code == 200: | ||
fields2add, _ = extract_fields(response, dataset_name) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters