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

add basic auth for Lever #17996

Merged
merged 19 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 17 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"client_id": "client_id",
"client_secret": "client_secret",
"refresh_token": "refresh_token",
"environment": "Sandbox",
"start_date": "2021-07-12T00:00:00Z"
}
{ "credentials" : {
alexchouraki marked this conversation as resolved.
Show resolved Hide resolved
"api_key": "c1adBeHUJKqyPM0X01tshKl4Pwh1LyPdmlorXjfmoDE0lVxZl",
"auth_type": "Api Key"
},
"start_date": "2021-07-12T00:00:00Z",
"environment": "Sandbox"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
"auth_type": {
"type": "string",
"const": "Client",
"enum": ["Client"],
"default": "Client",
"order": 0
},
"client_id": {
Expand All @@ -37,19 +35,32 @@
"description": "The Client Secret of your Lever Hiring developer application.",
"airbyte_secret": true
},
"option_title": {
"type": "string",
"title": "Credentials Title",
"description": "OAuth Credentials",
"const": "OAuth Credentials"
},
"refresh_token": {
"type": "string",
"title": "Refresh Token",
"description": "The token for obtaining new access token.",
"airbyte_secret": true
}
}
},
{
"type": "object",
"title": "Authenticate via Lever (Api Key)",
"required": ["api_key"],
"properties": {
"auth_type": {
"type": "string",
"const": "Api Key",
"order": 0
},
"api_key": {
"title": "Api key",
"type": "string",
"description": "The Api Key of your Lever Hiring account.",
"airbyte_secret": true,
"order":1
}
}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@

from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.streams import Stream
from airbyte_cdk.sources.streams.http.auth import Oauth2Authenticator
from airbyte_cdk.sources.streams.http.auth import BasicHttpAuthenticator, Oauth2Authenticator

from .streams import Applications, Interviews, Notes, Offers, Opportunities, Referrals, Users


def _auth_from_config(config):
return Oauth2Authenticator(
client_id=config["credentials"]["client_id"],
client_secret=config["credentials"]["client_secret"],
refresh_token=config["credentials"]["refresh_token"],
token_refresh_endpoint=f"{SourceLeverHiring.URL_MAP_ACCORDING_ENVIRONMENT[config['environment']]['login']}oauth/token",
)
try:
if config["credentials"]["auth_type"] == "Api Key":
return BasicHttpAuthenticator(username=config["credentials"]["api_key"], password=None, auth_method="Basic")
elif config["credentials"]["auth_type"] == "Client":
return Oauth2Authenticator(
client_id=config["credentials"]["client_id"],
client_secret=config["credentials"]["client_secret"],
refresh_token=config["credentials"]["refresh_token"],
token_refresh_endpoint=f"{SourceLeverHiring.URL_MAP_ACCORDING_ENVIRONMENT[config['environment']]['login']}oauth/token",
)
else:
print("Auth type was not configured properly")
return None
except Exception as e:
print(f"{e.__class__} occurred, there's an issue with credentials in your config")
raise e


class SourceLeverHiring(AbstractSource):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
"auth_type": {
"type": "string",
"const": "Client",
"enum": ["Client"],
"default": "Client",
"order": 0
},
"client_id": {
Expand All @@ -37,19 +35,32 @@
"description": "The Client Secret of your Lever Hiring developer application.",
"airbyte_secret": true
},
"option_title": {
"type": "string",
"title": "Credentials Title",
"description": "OAuth Credentials",
"const": "OAuth Credentials"
},
"refresh_token": {
"type": "string",
"title": "Refresh Token",
"description": "The token for obtaining new access token.",
"airbyte_secret": true
}
}
},
{
"type": "object",
"title": "Authenticate via Lever (Api Key)",
"required": ["api_key"],
"properties": {
"auth_type": {
"type": "string",
"const": "Api Key",
"order": 0
},
"api_key": {
"title": "Api key",
"type": "string",
"description": "The Api Key of your Lever Hiring account.",
"airbyte_secret": true,
"order":1
}
}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@
from pytest import fixture


@fixture
def test_config():
return {
"credentials": {
"client_id": "test_client_id",
"client_secret": "test_client_secret",
"refresh_token": "test_refresh_token",
"access_token": "test_access_token",
"expires_in": 3600,
},
"environment": "Sandbox",
"start_date": "2021-05-07T00:00:00Z",
}


@fixture
def test_full_refresh_config():
return {"base_url": "test_base_url"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,51 @@

from unittest.mock import MagicMock

import pytest
import responses
from source_lever_hiring.source import SourceLeverHiring


def setup_responses():
responses.add(
responses.POST, "https://sandbox-lever.auth0.com/oauth/token", json={"access_token": "fake_access_token", "expires_in": 3600}
)


@pytest.mark.parametrize(
("response", "url", "payload", "test_config"),
[
(
responses.POST,
"https://sandbox-lever.auth0.com/oauth/token",
{"access_token": "test_access_token", "expires_in": 3600},
{
"credentials": {
"auth_type": "Client",
"client_id": "test_client_id",
"client_secret": "test_client_secret",
"refresh_token": "test_refresh_token",
"access_token": "test_access_token",
"expires_in": 3600,
},
"environment": "Sandbox",
"start_date": "2021-05-07T00:00:00Z",
},
),
(
None,
None,
None,
{
"credentials": {
"auth_type": "Api Key",
"api_key": "test_api_key",
},
"environment": "Sandbox",
"start_date": "2021-05-07T00:00:00Z",
},
),
],
)
@responses.activate
def test_check_connection(test_config):
setup_responses()
def test_source(response, url, payload, test_config):
if response:
responses.add(response, url, json=payload)
source = SourceLeverHiring()
logger_mock = MagicMock()
assert source.check_connection(logger_mock, test_config) == (True, None)


@responses.activate
def test_streams(test_config):
setup_responses()
source = SourceLeverHiring()
streams = source.streams(test_config)
expected_streams_number = 7
assert len(streams) == expected_streams_number
assert len(source.streams(test_config)) == 7
1 change: 1 addition & 0 deletions docs/integrations/sources/lever-hiring.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The Lever Hiring connector should not run into Lever Hiring API limitations unde

| Version | Date | Pull Request | Subject |
| :--- | :--- | :--- | :--- |
| 0.1.3 | 2022-10-14 | [17996](https://github.com/airbytehq/airbyte/pull/17996) | Add Basic Auth management |
| 0.1.2 | 2021-12-30 | [9214](https://github.com/airbytehq/airbyte/pull/9214) | Update title and descriptions |
| 0.1.1 | 2021-12-16 | [7677](https://github.com/airbytehq/airbyte/pull/7677) | OAuth Automated Authentication |
| 0.1.0 | 2021-09-22 | [6141](https://github.com/airbytehq/airbyte/pull/6141) | Add Lever Hiring Source Connector |
Expand Down