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 Google Analytics v4: Declare oauth parameters in google sources #6414

Merged
merged 9 commits into from
Oct 8, 2021

Conversation

gaart
Copy link
Contributor

@gaart gaart commented Sep 23, 2021

What

Add support for connecting via Ouath webflow

How

Update spec.json schema to support 2 types of authorization
Update source.py
Update unit_tests

Pre-merge Checklist

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions
  • Connector version bumped like described here

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here

@github-actions github-actions bot added the area/connectors Connector related issues label Sep 23, 2021
@gaart gaart linked an issue Sep 23, 2021 that may be closed by this pull request
@@ -4,49 +4,9 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Google Analytics V4 Spec",
"type": "object",
"required": ["credentials", "view_id", "start_date"],
"additionalProperties": true,
"required": ["authorization", "view_id", "start_date"],
Copy link
Contributor

Choose a reason for hiding this comment

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

we should keep the name the same since other code in the platform depends on this

"type": "object",
"oneOf": [
{
"title": "Client Auth",
Copy link
Contributor

Choose a reason for hiding this comment

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

could you use the same titles and descriptions in Google Search Console?

}
}
},
"authSpecification": {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should remain, why remove it?

@avida
Copy link
Contributor

avida commented Sep 24, 2021

@sherifnada Google analytics oauth workflow task already completed by #6306 PR, why we need to do it one more time?

@gaart gaart temporarily deployed to more-secrets September 24, 2021 13:06 Inactive
@gaart gaart temporarily deployed to more-secrets September 27, 2021 17:06 Inactive
@CLAassistant
Copy link

CLAassistant commented Sep 27, 2021

CLA assistant check
All committers have signed the CLA.

@gaart gaart temporarily deployed to more-secrets September 28, 2021 14:39 Inactive
@@ -469,17 +442,34 @@ def get_refresh_request_params(self) -> Mapping[str, any]:
}
headers = {"kid": self.client_id}
signed_jwt = jwt.encode(payload, self.client_secret, headers=headers, algorithm="RS256")
return {"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer", "assertion": signed_jwt}
return {"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer", "assertion": str(signed_jwt)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since line 432 was removed, it doesn't seem to be using the method from super() in non-jwt cases... (ie when not using service account json?)

In those cases, it seems the grant_type should be simply a refresh_token value:

Is this making the connector supporting only the service account / jwt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The get_authenticator method contains the logic for choosing the authorization type, there is support for client and service authorization

@gaart gaart temporarily deployed to more-secrets October 1, 2021 07:24 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 1, 2021

/test connector=connectors/source-google-analytics-v4

🕑 connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1294178854
✅ connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1294178854
Python tests coverage:

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                                 Stmts   Miss  Cover
	 ------------------------------------------------------------------------
	 source_acceptance_test/__init__.py                       2      0   100%
	 source_acceptance_test/base.py                          10      4    60%
	 source_acceptance_test/config.py                        74      8    89%
	 source_acceptance_test/conftest.py                     108    108     0%
	 source_acceptance_test/plugin.py                        47     47     0%
	 source_acceptance_test/tests/__init__.py                 4      0   100%
	 source_acceptance_test/tests/test_core.py              158    109    31%
	 source_acceptance_test/tests/test_full_refresh.py       18     11    39%
	 source_acceptance_test/tests/test_incremental.py        69     38    45%
	 source_acceptance_test/utils/__init__.py                 6      0   100%
	 source_acceptance_test/utils/asserts.py                 37      2    95%
	 source_acceptance_test/utils/common.py                  41     25    39%
	 source_acceptance_test/utils/compare.py                 47     20    57%
	 source_acceptance_test/utils/connector_runner.py        82     49    40%
	 source_acceptance_test/utils/json_schema_helper.py      75     11    85%
	 ------------------------------------------------------------------------
	 TOTAL                                                  778    432    44%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                     Stmts   Miss  Cover
	 ------------------------------------------------------------
	 source_google_analytics_v4/__init__.py       2      0   100%
	 source_google_analytics_v4/source.py       224    107    52%
	 ------------------------------------------------------------
	 TOTAL                                      226    107    53%

@jrhizor jrhizor temporarily deployed to more-secrets October 1, 2021 07:46 Inactive


class SourceGoogleAnalyticsV4(AbstractSource):
"""Google Analytics lets you analyze data about customer engagement with your website or application."""

@staticmethod
def get_authenticator(config):
if config.get("credentials_json"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if config.get("credentials_json"):
# backwards compatibility, credentials_json used to be in the top level of the connector
if config.get("credentials_json"):

@@ -4,50 +4,9 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Google Analytics V4 Spec",
"type": "object",
"required": ["credentials", "view_id", "start_date"],
"required": ["view_id", "start_date"],
Copy link
Contributor

Choose a reason for hiding this comment

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

why remove credentials as required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the old configuration does not contain a credential field and when we run the connector the following error appears Exception: Config validation error: 'credentials' is a required property

Copy link
Contributor

Choose a reason for hiding this comment

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

ah I see, good point. Thanks for the clarification

@@ -81,14 +84,14 @@ def test_check_connection_oauth(jwt_encode_mock, mocker, mock_metrics_dimensions
test_config = json.loads(read_file("../integration_tests/sample_config.json"))
del test_config["custom_reports"]
test_config["credentials"] = {
"auth_type": "Client",
"client_id": "client_id_val",
"client_secret": "client_secret_val",
"refresh_token": "refresh_token_val",
}
source = SourceGoogleAnalyticsV4()
assert source.check_connection(MagicMock(), test_config) == (True, None)
jwt_encode_mock.encode.assert_not_called()
Copy link
Contributor

Choose a reason for hiding this comment

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

why was this removed?

@gaart gaart requested a review from sherifnada October 6, 2021 22:24
@gaart gaart temporarily deployed to more-secrets October 6, 2021 22:24 Inactive
@jrhizor jrhizor temporarily deployed to more-secrets October 7, 2021 16:41 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 7, 2021

/test connector=connectors/source-google-analytics-v4

🕑 connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1317119841
❌ connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1317119841
🐛

@jrhizor jrhizor temporarily deployed to more-secrets October 7, 2021 16:51 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 7, 2021

/test connector=connectors/source-google-analytics-v4

🕑 connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1317146994
❌ connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1317146994
🐛 https://gradle.com/s/tys3chploiakw

@gaart gaart temporarily deployed to more-secrets October 7, 2021 16:58 Inactive
@jrhizor jrhizor temporarily deployed to more-secrets October 7, 2021 16:59 Inactive
@gaart gaart temporarily deployed to more-secrets October 7, 2021 17:03 Inactive
@github-actions github-actions bot added the area/documentation Improvements or additions to documentation label Oct 7, 2021
@gaart gaart temporarily deployed to more-secrets October 7, 2021 17:18 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 8, 2021

/test connector=connectors/source-google-analytics-v4

🕑 connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1319663901
✅ connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1319663901
Python tests coverage:

	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                                 Stmts   Miss  Cover
	 ------------------------------------------------------------------------
	 source_acceptance_test/__init__.py                       2      0   100%
	 source_acceptance_test/base.py                          10      4    60%
	 source_acceptance_test/config.py                        74      8    89%
	 source_acceptance_test/conftest.py                     108    108     0%
	 source_acceptance_test/plugin.py                        47     47     0%
	 source_acceptance_test/tests/__init__.py                 4      0   100%
	 source_acceptance_test/tests/test_core.py              200     94    53%
	 source_acceptance_test/tests/test_full_refresh.py       18     11    39%
	 source_acceptance_test/tests/test_incremental.py        69     38    45%
	 source_acceptance_test/utils/__init__.py                 6      0   100%
	 source_acceptance_test/utils/asserts.py                 37      2    95%
	 source_acceptance_test/utils/common.py                  41     24    41%
	 source_acceptance_test/utils/compare.py                 47     20    57%
	 source_acceptance_test/utils/connector_runner.py        82     49    40%
	 source_acceptance_test/utils/json_schema_helper.py     115     14    88%
	 ------------------------------------------------------------------------
	 TOTAL                                                  860    419    51%
	 ---------- coverage: platform linux, python 3.8.10-final-0 -----------
	 Name                                     Stmts   Miss  Cover
	 ------------------------------------------------------------
	 source_google_analytics_v4/__init__.py       2      0   100%
	 source_google_analytics_v4/source.py       224    107    52%
	 ------------------------------------------------------------
	 TOTAL                                      226    107    53%

@jrhizor jrhizor temporarily deployed to more-secrets October 8, 2021 09:04 Inactive
@gaart
Copy link
Contributor Author

gaart commented Oct 8, 2021

/publish connector=connectors/source-google-analytics-v4

🕑 connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1319726872
✅ connectors/source-google-analytics-v4 https://github.com/airbytehq/airbyte/actions/runs/1319726872

@jrhizor jrhizor temporarily deployed to more-secrets October 8, 2021 09:22 Inactive
@gaart gaart merged commit bf3189c into master Oct 8, 2021
@gaart gaart deleted the gaart/5634-google-connectors-ouath branch October 8, 2021 09:38
@philippeboyd
Copy link
Contributor

I created a bug mostly related to this PR, please see #6977

schlattk pushed a commit to schlattk/airbyte that referenced this pull request Jan 4, 2022
…ces (airbytehq#6414)

* Upd auth: oauth support

* Rename authorization/credentials, upd spec, refactor

* Add backward compatibility

* Upd CI

* Bump version

* Upd changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues area/documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Declare oauth parameters in google sources
8 participants