From 961b5675412c667b9ed0069e959058bec46d59f3 Mon Sep 17 00:00:00 2001 From: Timothy Carambat Date: Thu, 26 Sep 2024 08:49:05 -0700 Subject: [PATCH] Add dropdown for confluence connector deployment (#2376) --- .../Confluence/ConfluenceLoader/index.js | 8 +++++- .../utils/extensions/Confluence/index.js | 18 ++++++++++--- .../Connectors/Confluence/index.jsx | 26 +++++++++++++++++++ frontend/src/models/dataConnector.js | 9 ++++++- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/collector/utils/extensions/Confluence/ConfluenceLoader/index.js b/collector/utils/extensions/Confluence/ConfluenceLoader/index.js index 2afb95273..d84a64fbe 100644 --- a/collector/utils/extensions/Confluence/ConfluenceLoader/index.js +++ b/collector/utils/extensions/Confluence/ConfluenceLoader/index.js @@ -13,6 +13,7 @@ class ConfluencePagesLoader { limit = 25, expand = "body.storage,version", personalAccessToken, + cloud = true, }) { this.baseUrl = baseUrl; this.spaceKey = spaceKey; @@ -21,6 +22,7 @@ class ConfluencePagesLoader { this.limit = limit; this.expand = expand; this.personalAccessToken = personalAccessToken; + this.cloud = cloud; } get authorizationHeader() { @@ -74,7 +76,11 @@ class ConfluencePagesLoader { // https://developer.atlassian.com/cloud/confluence/rest/v2/intro/#auth async fetchAllPagesInSpace(start = 0, limit = this.limit) { - const url = `${this.baseUrl}/wiki/rest/api/content?spaceKey=${this.spaceKey}&limit=${limit}&start=${start}&expand=${this.expand}`; + const url = `${this.baseUrl}${ + this.cloud ? "/wiki" : "" + }/rest/api/content?spaceKey=${ + this.spaceKey + }&limit=${limit}&start=${start}&expand=${this.expand}`; const data = await this.fetchConfluenceData(url); if (data.size === 0) { return []; diff --git a/collector/utils/extensions/Confluence/index.js b/collector/utils/extensions/Confluence/index.js index 819176712..c8ab9b03c 100644 --- a/collector/utils/extensions/Confluence/index.js +++ b/collector/utils/extensions/Confluence/index.js @@ -13,7 +13,13 @@ const { ConfluencePagesLoader } = require("./ConfluenceLoader"); * @returns */ async function loadConfluence( - { baseUrl = null, spaceKey = null, username = null, accessToken = null }, + { + baseUrl = null, + spaceKey = null, + username = null, + accessToken = null, + cloud = true, + }, response ) { if (!baseUrl || !spaceKey || !username || !accessToken) { @@ -45,6 +51,7 @@ async function loadConfluence( spaceKey, username, accessToken, + cloud, }); const { docs, error } = await loader @@ -66,7 +73,7 @@ async function loadConfluence( }; } const outFolder = slugify( - `confluence-${origin}-${v4().slice(0, 4)}` + `confluence-${hostname}-${v4().slice(0, 4)}` ).toLowerCase(); const outFolderPath = @@ -91,7 +98,7 @@ async function loadConfluence( description: doc.metadata.title, docSource: `${origin} Confluence`, chunkSource: generateChunkSource( - { doc, baseUrl: origin, spaceKey, accessToken, username }, + { doc, baseUrl: origin, spaceKey, accessToken, username, cloud }, response.locals.encryptionWorker ), published: new Date().toLocaleString(), @@ -130,6 +137,7 @@ async function fetchConfluencePage({ spaceKey, username, accessToken, + cloud = true, }) { if (!pageUrl || !baseUrl || !spaceKey || !username || !accessToken) { return { @@ -162,6 +170,7 @@ async function fetchConfluencePage({ spaceKey, username, accessToken, + cloud, }); const { docs, error } = await loader @@ -225,7 +234,7 @@ function validBaseUrl(baseUrl) { * @returns {string} */ function generateChunkSource( - { doc, baseUrl, spaceKey, accessToken, username }, + { doc, baseUrl, spaceKey, accessToken, username, cloud }, encryptionWorker ) { const payload = { @@ -233,6 +242,7 @@ function generateChunkSource( spaceKey, token: accessToken, username, + cloud, }; return `confluence://${doc.metadata.url}?payload=${encryptionWorker.encrypt( JSON.stringify(payload) diff --git a/frontend/src/components/Modals/ManageWorkspace/DataConnectors/Connectors/Confluence/index.jsx b/frontend/src/components/Modals/ManageWorkspace/DataConnectors/Connectors/Confluence/index.jsx index b9a1c9059..4bd589fef 100644 --- a/frontend/src/components/Modals/ManageWorkspace/DataConnectors/Connectors/Confluence/index.jsx +++ b/frontend/src/components/Modals/ManageWorkspace/DataConnectors/Connectors/Confluence/index.jsx @@ -26,6 +26,7 @@ export default function ConfluenceOptions() { spaceKey: form.get("spaceKey"), username: form.get("username"), accessToken: form.get("accessToken"), + cloud: form.get("isCloud") === "true", }); if (!!error) { @@ -54,6 +55,31 @@ export default function ConfluenceOptions() {
+
+
+ +

+ Determine if your Confluence instance is hosted on Atlassian + cloud or self-hosted. +

+
+ +
+