Skip to content

Commit

Permalink
feature: removing hard coded tokens (#45)
Browse files Browse the repository at this point in the history
* feature: removing hard coded tokens
  • Loading branch information
AlanJaeger authored Nov 28, 2024
1 parent f4130c8 commit aae3a3f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
8 changes: 4 additions & 4 deletions insights/sources/orders/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
class VtexOrdersRestClient(VtexAuthentication):
def __init__(self, auth_params, cache_client: CacheClient) -> None:
self.headers = {
"X-VTEX-API-AppToken": auth_params["VTEX-API-AppToken"],
"X-VTEX-API-AppKey": auth_params["VTEX-API-AppKey"],
"X-VTEX-API-AppToken": auth_params["app_token"],
"X-VTEX-API-AppKey": auth_params["app_key"],
}
self.base_url = auth_params["domain"]
self.cache = cache_client
Expand All @@ -29,9 +29,9 @@ def get_vtex_endpoint(self, query_filters: dict, page_number: int = 1):
utm_source = query_filters.get("utm_source")

if start_date is not None:
url = f"https://{self.base_url}.myvtex.com/api/oms/pvt/orders/?f_UtmSource={utm_source}&per_page=100&page={page_number}&f_authorizedDate=authorizedDate:[{start_date} TO {end_date}]&f_status=invoiced"
url = f"{self.base_url}/api/oms/pvt/orders/?f_UtmSource={utm_source}&per_page=100&page={page_number}&f_authorizedDate=authorizedDate:[{start_date} TO {end_date}]&f_status=invoiced"
else:
url = f"https://{self.base_url}.myvtex.com/api/oms/pvt/orders/?f_UtmSource={utm_source}&per_page=100&page={page_number}&f_status=invoiced"
url = f"{self.base_url}.myvtex.com/api/oms/pvt/orders/?f_UtmSource={utm_source}&per_page=100&page={page_number}&f_status=invoiced"
return url

def parse_datetime(self, date_str):
Expand Down
20 changes: 8 additions & 12 deletions insights/sources/vtexcredentials/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ def __init__(self, project) -> None:
self.url = f"{settings.INTEGRATIONS_URL}/api/v1/apptypes/vtex/integration-details/{project}"

def get_vtex_auth(self):
# response = requests.get(url=self.url, headers=self.headers)
# print("url", self.url)
# print("RESPONSE", response)
# tokens = response.json()
# print("TOKEN", tokens)
# credentials = {
# "app_key": tokens["app_key"],
# "app_token": tokens["app_token"],
# "domain": tokens["domain"],
# }
# print("credenciais")
return {}
response = requests.get(url=self.url, headers=self.headers)
tokens = response.json()
credentials = {
"app_key": tokens["app_key"],
"app_token": tokens["app_token"],
"domain": tokens["domain"],
}
return credentials
27 changes: 10 additions & 17 deletions insights/widgets/usecases/get_source_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from insights.projects.parsers import parse_dict_to_json
from insights.shared.viewsets import get_source
from insights.widgets.models import Widget
from insights.widgets.usecases.get_tokens import get_tokens


def set_live_day(default_filters):
Expand Down Expand Up @@ -163,22 +162,16 @@ def get_source_data_from_widget(
f"could not find a source with the slug {source}, make sure that the widget is configured with a supported source"
)

# serialized_auth = {}
tokens = {}
serialized_auth = {}
if widget.type == "vtex_order":
tokens = get_tokens(project_uuid=widget.project.uuid)
# ESSA FUNÇÃO GET_TOKENS VAI FAZER AS VEZES DO
# SOURCE DO INTEGRATIONS QUE RETORNA OS TOKENS ENQUANTO
# O PROBLEMA DOS TOKENS É RESOLVIDO.

# auth_source = get_source(slug="vtexcredentials")
# serialized_auth: dict = auth_source.execute(
# filters={"project": "d8d6d71d-3daf-4d2e-812b-85cc252a96d8"},
# operation="get_vtex_auth",
# parser=parse_dict_to_json,
# return_format="",
# query_kwargs={},
# )
auth_source = get_source(slug="vtexcredentials")
serialized_auth: dict = auth_source.execute(
filters={"project": widget.project.uuid},
operation="get_vtex_auth",
parser=parse_dict_to_json,
return_format="",
query_kwargs={},
)

operation_function = (
cross_source_data_operation
Expand All @@ -192,7 +185,7 @@ def get_source_data_from_widget(
is_live=is_live,
filters=filters,
user_email=user_email,
auth_params=tokens,
auth_params=serialized_auth,
)

except Widget.DoesNotExist:
Expand Down

0 comments on commit aae3a3f

Please sign in to comment.