Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mindful auth #744

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says that The structure is user and password. In the task, you are getting CUSTOMER_UUID and AUTH_TOKEN. It doesn't look like a username and password.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the auth accepts the function HTTPBasicAuth which only needs the user and password.
I you think it necessary for name consistency, I could replace user and password in docstring by customer_uuid and auth_token respectively.

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"],
Comment on lines +121 to +122
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are getting CUSTOMER_UUID and AUTH_TOKEN but docstring in the source says that The structure is user and password. What is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In mindful, the user is defined by an ID, in this case, CUSTOMER_UUID, and the password is defined by, what they said AUTH TOKEN, but this is a password, I mean, if you need to generate a token for OAuth, this not would be correct, you would have to create a token.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I saved it to the credentials, I added the same words they decided to use for the user (mindful velux user) and the password (mindful velux password).

)

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