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 9 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",
alexchouraki marked this conversation as resolved.
Show resolved Hide resolved
"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 @@ -14,6 +14,27 @@
"description": "Choose how to authenticate to Lever Hiring.",
"type": "object",
"oneOf": [
{
"type": "object",
"title": "Authenticate via Lever (Api Key)",
"required": ["api_key"],
"properties": {
"auth_type": {
"type": "string",
"const": "Api Key",
"enum": ["Api Key"],
"default": "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
}
}
},
{
"type": "object",
"title": "Authenticate via Lever (OAuth)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@

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 Oauth2Authenticator, BasicHttpAuthenticator

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 @@ -14,6 +14,27 @@
"description": "Choose how to authenticate to Lever Hiring.",
"type": "object",
"oneOf": [
{
"type": "object",
"title": "Authenticate via Lever (Api Key)",
"required": ["api_key"],
"properties": {
"auth_type": {
"type": "string",
"const": "Api Key",
"enum": ["Api Key"],
"default": "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
}
}
},
{
"type": "object",
"title": "Authenticate via Lever (OAuth)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

from pytest import fixture


@fixture
def test_config():
def test_config_client():
return {
"credentials": {
"client_id": "test_client_id",
Expand All @@ -18,6 +17,16 @@ def test_config():
"environment": "Sandbox",
"start_date": "2021-05-07T00:00:00Z",
}

@fixture
def test_config_key():
return {
"credentials": {
"api_key": "test_api_key",
},
"environment": "Sandbox",
"start_date": "2021-05-07T00:00:00Z",
}


@fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@
#

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", json={"access_token": "fake_access_token", "expires_in": 3600}), test_config_client()
(responses.GET, "https://api.lever.co/v1/opportunities", json={"api_key": "fake_api_key", "expires_in": 3600}), test_config_key(),
],
)

@responses.activate
def test_check_connection(test_config):
setup_responses()
def test_check_connection(response, url, payload, test_config):
responses.add(response, url, 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()
def test_streams(response, url, payload, test_config):
responses.add(response, url, payload)
source = SourceLeverHiring()
streams = source.streams(test_config)
expected_streams_number = 7
Expand Down
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