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 handling of Personal Access Token in Confluence data connector #2705

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 13 additions & 7 deletions collector/utils/extensions/Confluence/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ async function loadConfluence(
spaceKey = null,
username = null,
accessToken = null,
personalAccessToken = null,
cloud = true,
},
response
) {
if (!baseUrl || !spaceKey || !username || !accessToken) {
if (!accessToken && !personalAccessToken || accessToken && !username || personalAccessToken && username) {
return {
success: false,
reason:
"You need either a username and access token, or a personal access token (PAT), to use the Confluence connector.",
"You need either a username and access token, or only a personal access token (PAT), to use the Confluence connector.",
};
}

Expand All @@ -51,6 +52,7 @@ async function loadConfluence(
spaceKey,
username,
accessToken,
personalAccessToken,
cloud,
});

Expand Down Expand Up @@ -98,7 +100,7 @@ async function loadConfluence(
description: doc.metadata.title,
docSource: `${origin} Confluence`,
chunkSource: generateChunkSource(
{ doc, baseUrl: origin, spaceKey, accessToken, username, cloud },
{ doc, baseUrl: origin, spaceKey, accessToken, personalAccessToken, username, cloud },
response.locals.encryptionWorker
),
published: new Date().toLocaleString(),
Expand Down Expand Up @@ -137,14 +139,14 @@ async function fetchConfluencePage({
spaceKey,
username,
accessToken,
personalAccessToken,
cloud = true,
}) {
if (!pageUrl || !baseUrl || !spaceKey || !username || !accessToken) {
if (!accessToken && !personalAccessToken || accessToken && !username || personalAccessToken && username) {
return {
success: false,
content: null,
reason:
"You need either a username and access token, or a personal access token (PAT), to use the Confluence connector.",
"You need either a username and access token, or only a personal access token (PAT), to use the Confluence connector.",
};
}

Expand All @@ -170,6 +172,7 @@ async function fetchConfluencePage({
spaceKey,
username,
accessToken,
personalAccessToken,
cloud,
});

Expand Down Expand Up @@ -234,9 +237,12 @@ function validBaseUrl(baseUrl) {
* @returns {string}
*/
function generateChunkSource(
{ doc, baseUrl, spaceKey, accessToken, username, cloud },
{ doc, baseUrl, spaceKey, accessToken, personalAccessToken, username, cloud },
encryptionWorker
) {
if (personalAccessToken) {
accessToken = personalAccessToken;
}
const payload = {
baseUrl,
spaceKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function ConfluenceOptions() {
spaceKey: form.get("spaceKey"),
username: form.get("username"),
accessToken: form.get("accessToken"),
personalAccessToken: form.get("personalAccessToken"),
cloud: form.get("isCloud") === "true",
});

Expand Down Expand Up @@ -133,7 +134,7 @@ export default function ConfluenceOptions() {
name="username"
className="bg-theme-settings-input-bg text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"
placeholder="[email protected]"
required={true}
required={false}
autoComplete="off"
spellCheck={false}
/>
Expand All @@ -157,7 +158,7 @@ export default function ConfluenceOptions() {
clickable={true}
>
<p className="text-sm">
You need to provide an access token for authentication.
You need to provide a username and access token or a personal access token for authentication.
You can generate an access token{" "}
<a
href="https://id.atlassian.com/manage-profile/security/api-tokens"
Expand All @@ -181,7 +182,45 @@ export default function ConfluenceOptions() {
name="accessToken"
className="bg-theme-settings-input-bg text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"
placeholder="abcd1234"
required={true}
required={false}
autoComplete="off"
spellCheck={false}
/>
</div>
<div className="flex flex-col pr-10">
<div className="flex flex-col gap-y-1 mb-4">
<label className="text-white text-sm font-bold flex gap-x-2 items-center">
<p className="font-bold text-white">
Confluence Personal Access Token
</p>
<Warning
size={14}
className="ml-1 text-orange-500 cursor-pointer"
data-tooltip-id="personal-access-token-tooltip"
data-tooltip-place="right"
/>
<Tooltip
delayHide={300}
id="personal-access-token-tooltip"
className="max-w-xs z-99"
clickable={true}
>
<p className="text-sm">
You need to either provide a personal access token or a username and password for authentication.
You can create a personal access token in your confluence user settings
</p>
</Tooltip>
</label>
<p className="text-xs font-normal text-theme-text-secondary">
Personal access token for authentication.
</p>
</div>
<input
type="password"
name="personalAccessToken"
className="bg-theme-settings-input-bg text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5"
placeholder="abcd1234"
required={false}
autoComplete="off"
spellCheck={false}
/>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/models/dataConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const DataConnector = {
spaceKey,
username,
accessToken,
personalAccessToken,
cloud,
}) {
return await fetch(`${API_BASE}/ext/confluence`, {
Expand All @@ -146,6 +147,7 @@ const DataConnector = {
spaceKey,
username,
accessToken,
personalAccessToken,
cloud,
}),
})
Expand Down