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

feat[confluence]: Permit passing params to Confluence client #16961

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -68,7 +68,11 @@ base_url = "https://yoursite.atlassian.com/wiki"
page_ids = ["<page_id_1>", "<page_id_2>", "<page_id_3"]
space_key = "<space_key>"

reader = ConfluenceReader(base_url=base_url, oauth2=oauth2_dict)
reader = ConfluenceReader(
base_url=base_url,
oauth2=oauth2_dict,
client_args={"backoff_and_retry": True},
)
documents = reader.load_data(
space_key=space_key, include_attachments=True, page_status="current"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ConfluenceReader(BaseReader):
api_token (str): Confluence API token, see https://confluence.atlassian.com/cloud/api-tokens-938839638.html
user_name (str): Confluence username, used for basic auth. Must be used with `password`.
password (str): Confluence password, used for basic auth. Must be used with `user_name`.
client_args (dict): Additional keyword arguments to pass directly to the Atlassian Confluence client constructor, for example `{'backoff_and_retry': True}`.

"""

Expand All @@ -44,6 +45,7 @@ def __init__(
api_token: Optional[str] = None,
user_name: Optional[str] = None,
password: Optional[str] = None,
client_args: Optional[dict] = None,
) -> None:
if base_url is None:
raise ValueError("Must provide `base_url`")
Expand All @@ -58,20 +60,30 @@ def __init__(
" atlassian-python-api`"
)
self.confluence: Confluence = None
if client_args is None:
client_args = {}
if oauth2:
self.confluence = Confluence(url=base_url, oauth2=oauth2, cloud=cloud)
self.confluence = Confluence(
url=base_url, oauth2=oauth2, cloud=cloud, **client_args
)
else:
if api_token is not None:
self.confluence = Confluence(url=base_url, token=api_token, cloud=cloud)
self.confluence = Confluence(
url=base_url, token=api_token, cloud=cloud, **client_args
)
elif user_name is not None and password is not None:
self.confluence = Confluence(
url=base_url, username=user_name, password=password, cloud=cloud
url=base_url,
username=user_name,
password=password,
cloud=cloud,
**client_args,
)
else:
api_token = os.getenv(CONFLUENCE_API_TOKEN)
if api_token is not None:
self.confluence = Confluence(
url=base_url, token=api_token, cloud=cloud
url=base_url, token=api_token, cloud=cloud, **client_args
)
else:
user_name = os.getenv(CONFLUENCE_USERNAME)
Expand All @@ -82,6 +94,7 @@ def __init__(
username=user_name,
password=password,
cloud=cloud,
**client_args,
)
else:
raise ValueError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ license = "MIT"
maintainers = ["zywilliamli"]
name = "llama-index-readers-confluence"
readme = "README.md"
version = "0.2.1"
version = "0.2.2"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest.mock import patch

import pytest
from llama_index.readers.confluence import ConfluenceReader

Expand Down Expand Up @@ -31,6 +33,22 @@ def test_confluence_reader_with_api_token():
assert reader.confluence is not None


def test_confluence_reader_with_client_args():
with patch("atlassian.Confluence") as MockConstructor:
reader = ConfluenceReader(
base_url="https://example.atlassian.net/wiki",
api_token="example_api_token",
client_args={"backoff_and_retry": True},
)
assert reader.confluence is not None
MockConstructor.assert_called_once_with(
url="https://example.atlassian.net/wiki",
token="example_api_token",
cloud=True,
backoff_and_retry=True,
)


def test_confluence_reader_with_basic_auth():
reader = ConfluenceReader(
base_url="https://example.atlassian.net/wiki",
Expand Down
Loading