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

Source Hubspot: ensure all oauth2.0 scopes in "check" command #12711

Merged
merged 7 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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: 1 addition & 1 deletion airbyte-integrations/connectors/source-hubspot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ COPY source_hubspot ./source_hubspot
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.58
LABEL io.airbyte.version=0.1.59
LABEL io.airbyte.name=airbyte/source-hubspot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
from typing import Any, Iterator, List, Mapping, MutableMapping, Optional, Tuple

import requests
from airbyte_cdk.models import AirbyteMessage, ConfiguredAirbyteCatalog
from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.deprecated.base_source import ConfiguredAirbyteStream
Expand Down Expand Up @@ -44,22 +45,60 @@
Workflows,
)

SCOPES = [
"automation",
"content",
"crm.lists.read",
"crm.objects.companies.read",
"crm.objects.contacts.read",
"crm.objects.deals.read",
"crm.objects.feedback_submissions.read",
"crm.objects.owners.read",
"crm.schemas.companies.read",
"crm.schemas.contacts.read",
"crm.schemas.deals.read",
"e-commerce",
"files",
"files.ui_hidden.read",
"forms",
"forms-uploaded-files",
"sales-email-read",
"tickets",
]


class SourceHubspot(AbstractSource):
def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> Tuple[bool, Optional[Any]]:
"""Check connection"""
common_params = self.get_common_params(config=config)
if common_params.get("authenticator"):
davydov-d marked this conversation as resolved.
Show resolved Hide resolved
access_token = common_params["authenticator"].get_access_token()
url = f"https://api.hubapi.com/oauth/v1/access-tokens/{access_token}"
try:
response = requests.get(url=url)
response.raise_for_status()
return self.check_scopes(response.json())
except Exception as e:
return False, repr(e)

alive = True
error_msg = None
common_params = self.get_common_params(config=config)
try:
contacts = Contacts(**common_params)
_ = contacts.properties
except HTTPError as error:
alive = False
error_msg = repr(error)

return alive, error_msg

@staticmethod
def check_scopes(response_json):
granted_scopes = response_json["scopes"]
missed_scopes = set(SCOPES) - set(granted_scopes)
if missed_scopes:
return False, "missed required scopes: " + ", ".join(sorted(missed_scopes))
return True, None

@staticmethod
def get_api(config: Mapping[str, Any]) -> API:
credentials = config.get("credentials", {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ private String getScopes() {
"crm.schemas.companies.read",
"files",
"forms-uploaded-files",
"files.ui_hidden.read");
"files.ui_hidden.read",
"crm.objects.feedback_submissions.read",
"sales-email-read",
"automation");
}

/**
Expand Down
3 changes: 3 additions & 0 deletions docs/integrations/sources/hubspot.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ If you are using OAuth, most of the streams require the appropriate [scopes](htt
| `deals` | `contacts` |
| `email_events` | `content` |
| `engagements` | `contacts` |
| `engagements_emails` | `sales-email-read` |
| `feedback_submissions` | `crm.objects.feedback_submissions.read` |
| `forms` | `forms` |
| `form_submissions`| `forms` |
| `line_items` | `e-commerce` |
Expand All @@ -147,6 +149,7 @@ If you are using OAuth, most of the streams require the appropriate [scopes](htt

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------|
| 0.1.59 | 2022-05-10 | [\#12711](https://github.com/airbytehq/airbyte/pull/12711) | Ensure oauth2.0 token has all needed scopes in "check" command |
| 0.1.58 | 2022-05-04 | [\#12482](https://github.com/airbytehq/airbyte/pull/12482) | Update input configuration copy |
| 0.1.57 | 2022-05-04 | [12198](https://github.com/airbytehq/airbyte/pull/12198) | Add deals associations for quotes
| 0.1.56 | 2022-05-02 | [12515](https://github.com/airbytehq/airbyte/pull/12515) | Extra logs for troubleshooting 403 errors |
Expand Down