Skip to content

Commit

Permalink
馃悰 Source Amazon Ads: set default value for 'region' if needed (#15822)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Chvalyuk <grubberr@gmail.com>
  • Loading branch information
grubberr committed Aug 23, 2022
1 parent 4c3ebf8 commit ccdaae4
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- name: Amazon Ads
sourceDefinitionId: c6b0a29e-1da9-4512-9002-7bfd0cba2246
dockerRepository: airbyte/source-amazon-ads
dockerImageTag: 0.1.15
dockerImageTag: 0.1.16
documentationUrl: https://docs.airbyte.io/integrations/sources/amazon-ads
icon: amazonads.svg
sourceType: api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-amazon-ads:0.1.15"
- dockerImage: "airbyte/source-amazon-ads:0.1.16"
spec:
documentationUrl: "https://docs.airbyte.com/integrations/sources/amazon-ads"
connectionSpecification:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ RUN pip install .
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.15
LABEL io.airbyte.version=0.1.16
LABEL io.airbyte.name=airbyte/source-amazon-ads
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#

from enum import Enum


class AmazonAdsRegion(str, Enum):
NA = "NA"
EU = "EU"
FE = "FE"


URL_MAPPING = {
"NA": "https://advertising-api.amazon.com/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#


from typing import Any, List, Mapping, Tuple
import logging
import os
from typing import Any, List, Mapping, Optional, Tuple

from airbyte_cdk.logger import AirbyteLogger
from airbyte_cdk.connector import _WriteConfigProtocol
from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.streams import Stream
from airbyte_cdk.sources.streams.http.auth import Oauth2Authenticator

from .constants import AmazonAdsRegion
from .schemas import Profile
from .streams import (
Profiles,
Expand Down Expand Up @@ -38,7 +39,16 @@


class SourceAmazonAds(AbstractSource):
def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) -> Tuple[bool, any]:
def configure(self: _WriteConfigProtocol, config: Mapping[str, Any], temp_dir: str) -> Mapping[str, Any]:
if not config.get("region"):
source_spec = self.spec(logging.getLogger("airbyte"))
default_region = source_spec.connectionSpecification["properties"]["region"]["default"]
config["region"] = default_region
config_path = os.path.join(temp_dir, "config.json")
self.write_config(config, config_path)
return config

def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> Tuple[bool, Optional[Any]]:
"""
:param config: the user-input config object conforming to the connector's spec.json
:param logger: logger object
Expand All @@ -49,7 +59,6 @@ def check_connection(self, logger: AirbyteLogger, config: Mapping[str, Any]) ->
# in response body.
# It doesnt support pagination so there is no sense of reading single
# record, it would fetch all the data anyway.
self._set_defaults(config)
Profiles(config, authenticator=self._make_authenticator(config)).get_all_profiles()
return True, None

Expand All @@ -58,7 +67,6 @@ def streams(self, config: Mapping[str, Any]) -> List[Stream]:
:param config: A Mapping of the user input configuration as defined in the connector spec.
:return list of streams for current source
"""
self._set_defaults(config)
auth = self._make_authenticator(config)
stream_args = {"config": config, "authenticator": auth}
# All data for individual Amazon Ads stream divided into sets of data for
Expand Down Expand Up @@ -99,10 +107,6 @@ def _make_authenticator(config: Mapping[str, Any]):
refresh_token=config["refresh_token"],
)

@staticmethod
def _set_defaults(config: Mapping[str, Any]):
config["region"] = AmazonAdsRegion.NA

@staticmethod
def _choose_profiles(config: Mapping[str, Any], profiles: List[Profile]):
if not config.get("profiles"):
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/amazon-ads.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Information about expected report generation waiting time you may find [here](ht

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:-----------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------|
| 0.1.16 | 2022-08-23 | [15822](https://github.com/airbytehq/airbyte/pull/15822) | Set default value for 'region' if needed |
| 0.1.15 | 2022-08-20 | [15816](https://github.com/airbytehq/airbyte/pull/15816) | Update STATE of incremental sync if no records |
| 0.1.14 | 2022-08-15 | [15637](https://github.com/airbytehq/airbyte/pull/15637) | Generate slices by lazy evaluation |
| 0.1.12 | 2022-08-09 | [15469](https://github.com/airbytehq/airbyte/pull/15469) | Define primary_key for all report streams |
Expand Down

0 comments on commit ccdaae4

Please sign in to comment.