Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit 9708e4c

Browse files
sherifnadasabifranjoSabolc Franjo
authored
šŸ› bugfix Source Okta: Fix endless loop while syncing data from logs stream (airbytehq#4464)
Co-authored-by: sabifranjo <[email protected]> Co-authored-by: Sabolc Franjo <[email protected]>
1 parent 885da9b commit 9708e4c

File tree

7 files changed

+71
-19
lines changed

7 files changed

+71
-19
lines changed

ā€Žairbyte-config/init/src/main/resources/config/STANDARD_SOURCE_DEFINITION/1d4fdb25-64fc-4569-92da-fcdca79a8372.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"sourceDefinitionId": "1d4fdb25-64fc-4569-92da-fcdca79a8372",
33
"name": "Okta",
44
"dockerRepository": "airbyte/source-okta",
5-
"dockerImageTag": "0.1.1",
5+
"dockerImageTag": "0.1.2",
66
"documentationUrl": "https://docs.airbyte.io/integrations/sources/okta"
77
}

ā€Žairbyte-config/init/src/main/resources/seed/source_definitions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,5 +347,5 @@
347347
- sourceDefinitionId: 1d4fdb25-64fc-4569-92da-fcdca79a8372
348348
name: Okta
349349
dockerRepository: airbyte/source-okta
350-
dockerImageTag: 0.1.1
350+
dockerImageTag: 0.1.2
351351
documentationUrl: https://docs.airbyte.io/integrations/sources/okta
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
# Changelog
22

3-
## 0.1.0
4-
Initial Release
5-
Added the following incremental streams:
6-
- Groups
7-
- Logs
8-
- Users
3+
See the [docs](https://docs.airbyte.io/integrations/sources/okta#changelog)

ā€Žairbyte-integrations/connectors/source-okta/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ RUN pip install .
1212
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
1313
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]
1414

15-
LABEL io.airbyte.version=0.1.1
15+
LABEL io.airbyte.version=0.1.2
1616
LABEL io.airbyte.name=airbyte/source-okta

ā€Žairbyte-integrations/connectors/source-okta/source_okta/source.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#
2424

2525

26-
import re
2726
from abc import ABC, abstractmethod
2827
from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple
2928
from urllib import parse
@@ -51,13 +50,21 @@ def url_base(self) -> str:
5150
def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
5251
# Follow the next page cursor
5352
# https://developer.okta.com/docs/reference/api-overview/#pagination
54-
link_regex = r'<(.+?)>; rel="(.+?)"[,\s]*'
55-
raw_links = response.headers["link"]
56-
for link, cursor_type in re.findall(link_regex, raw_links):
57-
if cursor_type == "next":
58-
parsed_link = parse.urlparse(link)
59-
query_params = dict(parse.parse_qsl(parsed_link.query))
60-
return query_params
53+
links = response.links
54+
if "next" in links:
55+
next_url = links["next"]["url"]
56+
parsed_link = parse.urlparse(next_url)
57+
query_params = dict(parse.parse_qsl(parsed_link.query))
58+
59+
# Typically, the absence of the "next" link header indicates there are more pages to read
60+
# However, some streams contain the "next" link header even when there are no more pages to read
61+
# See https://developer.okta.com/docs/reference/api-overview/#link-header
62+
if "self" in links:
63+
if links["self"]["url"] == next_url:
64+
return None
65+
66+
return query_params
67+
6168
return None
6269

6370
def request_params(

ā€Žairbyte-integrations/connectors/source-okta/unit_tests/unit_test.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,45 @@
2323
#
2424

2525

26-
def test_example_method():
27-
assert True
26+
import pytest
27+
import requests
28+
from source_okta.source import OktaStream
29+
30+
31+
class MockStream(OktaStream):
32+
primary_key = "None"
33+
34+
def __init__(self):
35+
super().__init__("")
36+
37+
def path(self, **kwargs) -> str:
38+
return "path"
39+
40+
41+
class TestPagination:
42+
@pytest.mark.parametrize(
43+
("_self_header", "_next_header", "expected_npt", "assert_msg"),
44+
[
45+
(None, "XYZ", {"after": "XYZ"}, "Expected to receive a new page token if next header is set and self is not set"),
46+
("ABC", "XYZ", {"after": "XYZ"}, "Expected to receive a new page token if next and self headers have different values"),
47+
("ABC", "ABC", None, "Expected no new page token if next and self headers are the same"),
48+
("ABC", None, None, "Expected no new page token if next header is not set"),
49+
],
50+
)
51+
def test_pagination(self, _self_header, _next_header, expected_npt, assert_msg):
52+
stream = MockStream()
53+
54+
fake_response = requests.Response()
55+
link_header = ""
56+
57+
if _self_header:
58+
link_header += f'<https://somedomain.com/api/v1/users?after={_self_header}>; rel="self",'
59+
60+
if _next_header:
61+
link_header += f'<https://somedomain.com/api/v1/users?after={_next_header}>; rel="next"'
62+
63+
fake_response.headers = {"link": link_header}
64+
65+
actual_npt = stream.next_page_token(fake_response)
66+
67+
assert actual_npt == expected_npt, assert_msg

ā€Ždocs/integrations/sources/okta.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,13 @@ Different Okta APIs require different admin privilege levels. API tokens inherit
5454
5. Record the token value. This is the only opportunity to see it and record it.
5555
8. In Airbyte, create a Okta source.
5656
9. You can now pull data from your Okta instance!
57+
58+
59+
## Changelog
60+
61+
| Version | Date | Pull Request | Subject |
62+
| :------ | :-------- | :----- | :------ |
63+
| 0.1.2 | 2021-07-01 | [4456](https://github.com/airbytehq/airbyte/pull/4456)| Bugfix infinite pagination in logs stream |
64+
| 0.1.1 | 2021-06-09 | [3937](https://github.com/airbytehq/airbyte/pull/3973) | Add `AIRBYTE_ENTRYPOINT` env variable for kubernetes support|
65+
| 0.1.0 | 2021-05-30 | [3563](https://github.com/airbytehq/airbyte/pull/3563) | Initial Release |
66+

0 commit comments

Comments
Ā (0)