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 Github: Add MultipleTokenAuthenticator #5223

Merged
merged 18 commits into from
Aug 19, 2021

Conversation

gaart
Copy link
Contributor

@gaart gaart commented Aug 5, 2021

What

Multiple token support added to the CDK.
Solving #3250

How

Now we have MultipleTokenAuthenticator which receives a comma-separated list of tokens and rotates them during API calls.

@github-actions github-actions bot added area/connectors Connector related issues CDK Connector Development Kit labels Aug 5, 2021
@gaart gaart changed the title Add multiple token authenticator Python CDK, Source Github: Add multiple token authenticator Aug 5, 2021
@gaart gaart linked an issue Aug 5, 2021 that may be closed by this pull request
Copy link
Contributor

@vitaliizazmic vitaliizazmic left a comment

Choose a reason for hiding this comment

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

Could you please explain how token rotating is implemented while exceeded key limits?

@gaart
Copy link
Contributor Author

gaart commented Aug 10, 2021

@vitaliizazmic

Could you please explain how token rotating is implemented while exceeded key limits?

There's a backoff_time mechanism which adds timeouts when the limits exceeded, this PR doesn't change that behaviour but allows to use multiple tokens rotating them after each API call

@vitaliizazmic
Copy link
Contributor

@gaart sounds good. Don't forget to run tests and format.

@gaart
Copy link
Contributor Author

gaart commented Aug 11, 2021

/test connector=connectors/source-github

🕑 connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1121018057
❌ connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1121018057

@jrhizor jrhizor temporarily deployed to more-secrets August 11, 2021 17:30 Inactive
@gaart
Copy link
Contributor Author

gaart commented Aug 16, 2021

/test connector=connectors/source-github

🕑 connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1135844526
✅ connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1135844526

@jrhizor jrhizor temporarily deployed to more-secrets August 16, 2021 14:38 Inactive
…ure-rotate-tokens

# Conflicts:
#	airbyte-cdk/python/unit_tests/sources/streams/http/auth/test_auth.py
@github-actions github-actions bot added the area/documentation Improvements or additions to documentation label Aug 16, 2021
@gaart gaart requested review from sherifnada and marcosmarxm and removed request for vovavovavovavova and keu August 16, 2021 14:51
@gaart
Copy link
Contributor Author

gaart commented Aug 16, 2021

/test connector=connectors/source-github

🕑 connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1135926556
❌ connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1135926556

@jrhizor jrhizor temporarily deployed to more-secrets August 16, 2021 15:03 Inactive
@lukebussey
Copy link

Why pass a comma separated list of tokens when you can just pass over a List?

Copy link
Contributor

@sherifnada sherifnada left a comment

Choose a reason for hiding this comment

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

one requested change but otherwise looks great



class MultipleTokenAuthenticator(HttpAuthenticator):
def __init__(self, tokens: str, auth_method: str = "Bearer", auth_header: str = "Authorization"):
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 take a list of strings rather than a comma separated string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, updated

@gaart gaart requested a review from sherifnada August 16, 2021 17:22
Copy link
Contributor

@sherifnada sherifnada left a comment

Choose a reason for hiding this comment

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

Added some requested improvements, feel free to merge once they are addressed!

## 0.1.10
Upd multiple token support: switch to list of tokens

## 0.1.9
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need two versions for the same release? can we just make it a single version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not. But both are released already

@@ -36,3 +37,14 @@ def __init__(self, token: str, auth_method: str = "Bearer", auth_header: str = "

def get_auth_header(self) -> Mapping[str, Any]:
return {self.auth_header: f"{self.auth_method} {self._token}"}


class MultipleTokenAuthenticator(HttpAuthenticator):
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 add a doc string explaining what this does e.g:

Uses the input list of tokens for authentication in a round-robin fashion. This allows load balancing quota consumption across multiple tokens. 

@@ -9,7 +9,7 @@
"properties": {
"access_token": {
"type": "string",
"description": "Log into Github and then generate a <a href=\"https://github.com/settings/tokens\"> personal access token</a>.",
"description": "Log into Github and then generate a <a href=\"https://github.com/settings/tokens\"> personal access token</a>. Separate multiple tokens with \",\"",
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, type: string would be an array of strings too. However for backwards compatibility this is not great.

Could you create an issue to update this to a list of strings once #5396 is resolved?

]
if repositories:
repositories_list += repositories

return list(set(repositories_list))

@staticmethod
def _get_authenticator(token: str):
if TOKEN_SEPARATOR not in token:
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need a special edge case for this? multiple auth should still work with one token right?

@gaart
Copy link
Contributor Author

gaart commented Aug 17, 2021

/test connector=connectors/source-github

🕑 connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1139518093
✅ connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1139518093

@jrhizor jrhizor temporarily deployed to more-secrets August 17, 2021 13:54 Inactive
gaart added 2 commits August 18, 2021 20:02
…-feature-rotate-tokens

# Conflicts:
#	airbyte-integrations/connectors/source-github/source_github/source.py
@gaart
Copy link
Contributor Author

gaart commented Aug 18, 2021

/test connector=connectors/source-github

🕑 connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1143998890
❌ connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1143998890

@jrhizor jrhizor temporarily deployed to more-secrets August 18, 2021 17:08 Inactive
@gaart
Copy link
Contributor Author

gaart commented Aug 19, 2021

/test connector=connectors/source-github

🕑 connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1145675767
❌ connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1145675767

@jrhizor jrhizor temporarily deployed to more-secrets August 19, 2021 04:44 Inactive
@gaart gaart changed the title Python CDK, Source Github: Add multiple token authenticator 🎉 Source Github: Add MultipleTokenAuthenticator Aug 19, 2021
@gaart
Copy link
Contributor Author

gaart commented Aug 19, 2021

/test connector=connectors/source-github

🕑 connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1145715532
✅ connectors/source-github https://github.com/airbytehq/airbyte/actions/runs/1145715532

@jrhizor jrhizor temporarily deployed to more-secrets August 19, 2021 05:03 Inactive
@gaart gaart merged commit 51d406d into master Aug 19, 2021
@gaart gaart deleted the gaart/3250-feature-rotate-tokens branch August 19, 2021 05:41
gaart added a commit that referenced this pull request Aug 19, 2021
@gaart
Copy link
Contributor Author

gaart commented Aug 19, 2021

/publish connector=connectors/source-github

Error: No ref found for: gaart/3250-feature-rotate-tokens

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 CDK Connector Development Kit connectors/source/github connectors/sources-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Source Github: Allow rotating between multiple API keys
6 participants