Skip to content

Commit

Permalink
Merge pull request #744 from Diego-H-S/mindful_auth
Browse files Browse the repository at this point in the history
Mindful auth
  • Loading branch information
Rafalz13 authored Oct 2, 2023
2 parents 087bf78 + c08d88d commit 37909e0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Changed, `Mindful` credentials passed by the `auth` parameter, instead of by the `header`.

## [0.4.19] - 2023-08-31
### Added
- Added `add_viadot_metadata_columns` function that will be used as a decorator for `to_df` class methods.
Expand Down
13 changes: 7 additions & 6 deletions viadot/sources/mindful.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
from datetime import datetime, timedelta
from io import StringIO
from typing import Any, Dict, Literal
from datetime import datetime, timedelta
from typing import Any, Dict, Literal, Tuple

import pandas as pd
import prefect
from requests.models import Response
from requests.auth import HTTPBasicAuth

from viadot.exceptions import APIError
from viadot.sources.base import Source
Expand All @@ -15,7 +16,7 @@
class Mindful(Source):
def __init__(
self,
header: str,
auth: Tuple[str],
region: Literal["us1", "us2", "us3", "ca1", "eu1", "au1"] = "eu1",
start_date: datetime = None,
end_date: datetime = None,
Expand All @@ -27,7 +28,7 @@ def __init__(
"""Mindful connector which allows listing and downloading into Data Frame or specified format output.
Args:
header (str): Header with credentials for calling Mindful API.
auth (Tuple[str]): Authentication credentials for calling Mindful API. The structure is user and password.
region (Literal[us1, us2, us3, ca1, eu1, au1], optional): SD region from where to interact with the mindful API. Defaults to "eu1".
start_date (datetime, optional): Start date of the request. Defaults to None.
end_date (datetime, optional): End date of the resquest. Defaults to None.
Expand Down Expand Up @@ -73,7 +74,7 @@ def __init__(
)

self.file_extension = file_extension
self.header = header
self.auth = auth

def _mindful_api_response(
self,
Expand All @@ -94,8 +95,8 @@ def _mindful_api_response(
response = handle_api_response(
url=f"https://{self.region}surveydynamix.com/api/{endpoint}",
params=params,
headers=self.header,
method="GET",
auth=HTTPBasicAuth(*self.auth),
)

return response
Expand Down
9 changes: 5 additions & 4 deletions viadot/tasks/mindful.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ def run(
credentials_mindful = None
raise CredentialError("Credentials not found.")

header = {
"Authorization": f"Bearer {credentials_mindful.get('VAULT')}",
}
auth = (
credentials_mindful["CUSTOMER_UUID"],
credentials_mindful["AUTH_TOKEN"],
)

mindful = Mindful(
header=header,
auth=auth,
region=region,
start_date=start_date,
end_date=end_date,
Expand Down

0 comments on commit 37909e0

Please sign in to comment.