Skip to content

Commit

Permalink
#10938 fix docs and spec (#11803)
Browse files Browse the repository at this point in the history
* #10938 fix docs and spec

* #10938 add pr

* auto-bump connector version

Co-authored-by: Octavia Squidington III <[email protected]>
  • Loading branch information
davydov-d and octavia-squidington-iii authored Apr 13, 2022
1 parent 395cb7e commit a673a47
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
- name: Google Analytics
sourceDefinitionId: eff3616a-f9c3-11eb-9a03-0242ac130003
dockerRepository: airbyte/source-google-analytics-v4
dockerImageTag: 0.1.17
dockerImageTag: 0.1.18
documentationUrl: https://docs.airbyte.io/integrations/sources/google-analytics-v4
icon: google-analytics.svg
sourceType: api
Expand Down
18 changes: 8 additions & 10 deletions airbyte-config/init/src/main/resources/seed/source_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2754,7 +2754,7 @@
oauthFlowOutputParameters:
- - "access_token"
- - "refresh_token"
- dockerImage: "airbyte/source-google-analytics-v4:0.1.17"
- dockerImage: "airbyte/source-google-analytics-v4:0.1.18"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/sources/google-analytics-v4"
connectionSpecification:
Expand Down Expand Up @@ -2783,7 +2783,7 @@
- "2020-06-01"
window_in_days:
type: "integer"
title: "Window in days"
title: "Window in days (Optional)"
description: "The amount of days for each data-chunk beginning from start_date.\
\ Bigger the value - faster the fetch. (Min=1, as for a Day; Max=364,\
\ as for a Year)."
Expand All @@ -2798,7 +2798,7 @@
custom_reports:
order: 3
type: "string"
title: "Custom Reports (optional)"
title: "Custom Reports (Optional)"
description: "A JSON array describing the custom reports you want to sync\
\ from GA. Check out the <a href=\"https://docs.airbyte.io/integrations/sources/google-analytics-v4\"\
>docs</a> to get more information about this field."
Expand All @@ -2818,31 +2818,32 @@
auth_type:
type: "string"
const: "Client"
enum:
- "Client"
default: "Client"
order: 0
client_id:
title: "Client ID"
type: "string"
description: "The Client ID of your Google Analytics developer application."
airbyte_secret: true
order: 1
client_secret:
title: "Client Secret"
type: "string"
description: "The Client Secret of your Google Analytics developer\
\ application."
airbyte_secret: true
order: 2
refresh_token:
title: "Refresh Token"
type: "string"
description: "The token for obtaining a new access token."
airbyte_secret: true
order: 3
access_token:
title: "Access Token"
title: "Access Token (Optional)"
type: "string"
description: "Access Token for making authenticated requests."
airbyte_secret: true
order: 4
- type: "object"
title: "Service Account Key Authentication"
required:
Expand All @@ -2851,9 +2852,6 @@
auth_type:
type: "string"
const: "Service"
enum:
- "Service"
default: "Service"
order: 0
credentials_json:
title: "JSON credentials"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ COPY main.py ./
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.1.17
LABEL io.airbyte.version=0.1.18
LABEL io.airbyte.name=airbyte/source-google-analytics-v4
Original file line number Diff line number Diff line change
Expand Up @@ -523,21 +523,20 @@ def get_authenticator(config: Mapping) -> Oauth2Authenticator:
if config.get("credentials_json"):
return GoogleAnalyticsServiceOauth2Authenticator(config)

auth_params = config.get("credentials")
auth_params = config["credentials"]

if auth_params.get("auth_type") == "Service" or auth_params.get("credentials_json"):
if auth_params["auth_type"] == "Service" or auth_params.get("credentials_json"):
return GoogleAnalyticsServiceOauth2Authenticator(auth_params)
else:
return Oauth2Authenticator(
token_refresh_endpoint="https://oauth2.googleapis.com/token",
client_secret=auth_params.get("client_secret"),
client_id=auth_params.get("client_id"),
refresh_token=auth_params.get("refresh_token"),
client_secret=auth_params["client_secret"],
client_id=auth_params["client_id"],
refresh_token=auth_params["refresh_token"],
scopes=["https://www.googleapis.com/auth/analytics.readonly"],
)

def check_connection(self, logger: logging.Logger, config: MutableMapping) -> Tuple[bool, Any]:

# declare additional variables
authenticator = self.get_authenticator(config)
config["authenticator"] = authenticator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
},
"window_in_days": {
"type": "integer",
"title": "Window in days",
"title": "Window in days (Optional)",
"description": "The amount of days for each data-chunk beginning from start_date. Bigger the value - faster the fetch. (Min=1, as for a Day; Max=364, as for a Year).",
"examples": [30, 60, 90, 120, 200, 364],
"default": 1
},
"custom_reports": {
"order": 3,
"type": "string",
"title": "Custom Reports (optional)",
"title": "Custom Reports (Optional)",
"description": "A JSON array describing the custom reports you want to sync from GA. Check out the <a href=\"https://docs.airbyte.io/integrations/sources/google-analytics-v4\">docs</a> to get more information about this field."
},
"credentials": {
Expand All @@ -47,33 +47,35 @@
"auth_type": {
"type": "string",
"const": "Client",
"enum": ["Client"],
"default": "Client",
"order": 0
},
"client_id": {
"title": "Client ID",
"type": "string",
"description": "The Client ID of your Google Analytics developer application.",
"airbyte_secret": true
"airbyte_secret": true,
"order": 1
},
"client_secret": {
"title": "Client Secret",
"type": "string",
"description": "The Client Secret of your Google Analytics developer application.",
"airbyte_secret": true
"airbyte_secret": true,
"order": 2
},
"refresh_token": {
"title": "Refresh Token",
"type": "string",
"description": "The token for obtaining a new access token.",
"airbyte_secret": true
"airbyte_secret": true,
"order": 3
},
"access_token": {
"title": "Access Token",
"title": "Access Token (Optional)",
"type": "string",
"description": "Access Token for making authenticated requests.",
"airbyte_secret": true
"airbyte_secret": true,
"order": 4
}
}
},
Expand All @@ -85,8 +87,6 @@
"auth_type": {
"type": "string",
"const": "Service",
"enum": ["Service"],
"default": "Service",
"order": 0
},
"credentials_json": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ def test_config():
"start_date": pendulum.now().subtract(days=2).date().strftime("%Y-%m-%d"),
"dimensions": [],
"credentials": {
"type": "Service",
"auth_type": "Client",
"client_id": "client_id_val",
"client_secret": "client_secret_val",
"refresh_token": "refresh_token_val",
},
}
return copy.deepcopy(test_conf)
Expand All @@ -135,17 +138,6 @@ def test_config_auth_service(test_config):
return copy.deepcopy(test_config)


@pytest.fixture()
def test_config_auth_client(test_config):
test_config["credentials"] = {
"auth_type": "Client",
"client_id": "client_id_val",
"client_secret": "client_secret_val",
"refresh_token": "refresh_token_val",
}
return copy.deepcopy(test_config)


def test_metrics_dimensions_type_list(mock_metrics_dimensions_type_list_link):
test_metrics, test_dimensions = GoogleAnalyticsV4TypesList().read_records(sync_mode=None)

Expand Down Expand Up @@ -261,7 +253,7 @@ def test_check_connection_success_jwt(
@patch("source_google_analytics_v4.source.jwt")
def test_check_connection_fails_oauth(
jwt_encode_mock,
test_config_auth_client,
test_config,
mocker,
mock_metrics_dimensions_type_list_link,
mock_auth_call,
Expand All @@ -272,11 +264,10 @@ def test_check_connection_fails_oauth(
then we assume than user doesn't have permission to read requested `view`
"""
source = SourceGoogleAnalyticsV4()
is_success, msg = source.check_connection(MagicMock(), test_config_auth_client)
is_success, msg = source.check_connection(MagicMock(), test_config)
assert is_success is False
assert (
msg
== f"Please check the permissions for the requested view_id: {test_config_auth_client['view_id']}. Cannot retrieve data from that view ID."
msg == f"Please check the permissions for the requested view_id: {test_config['view_id']}. Cannot retrieve data from that view ID."
)
jwt_encode_mock.encode.assert_not_called()
assert "https://www.googleapis.com/auth/analytics.readonly" in unquote(mock_auth_call.last_request.body)
Expand All @@ -290,7 +281,7 @@ def test_check_connection_fails_oauth(
@patch("source_google_analytics_v4.source.jwt")
def test_check_connection_success_oauth(
jwt_encode_mock,
test_config_auth_client,
test_config,
mocker,
mock_metrics_dimensions_type_list_link,
mock_auth_call,
Expand All @@ -301,7 +292,7 @@ def test_check_connection_success_oauth(
then we assume than user has permission to read requested `view`
"""
source = SourceGoogleAnalyticsV4()
is_success, msg = source.check_connection(MagicMock(), test_config_auth_client)
is_success, msg = source.check_connection(MagicMock(), test_config)
assert is_success is True
assert msg is None
jwt_encode_mock.encode.assert_not_called()
Expand Down
Loading

0 comments on commit a673a47

Please sign in to comment.