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

Commit ead6707

Browse files
CinojoseCino Jose
andauthored
Confluence storage and document plugin (#2940)
* Confluence storage and document plugin initial commit * Removed some debug code and fixed typo * Fixed PR comments for confluence plugin * Fix pr comments for confluence plugin --------- Co-authored-by: Cino Jose <[email protected]>
1 parent 48d15e0 commit ead6707

File tree

11 files changed

+254
-10
lines changed

11 files changed

+254
-10
lines changed

requirements-base.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ h11
1616
httpx
1717
jinja2
1818
jira==2.0.0
19+
atlassian-python-api==3.32.0
1920
joblib
2021
numpy
2122
oauth2client

requirements-base.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ anyio==3.6.2
2020
# starlette
2121
async-timeout==4.0.2
2222
# via aiohttp
23+
atlassian-python-api==3.32.0
24+
# via -r requirements-base.in
2325
attrs==22.1.0
2426
# via
2527
# aiohttp
@@ -91,6 +93,8 @@ decorator==5.1.1
9193
# via validators
9294
defusedxml==0.7.1
9395
# via jira
96+
deprecated==1.2.13
97+
# via atlassian-python-api
9498
dnspython==2.2.1
9599
# via email-validator
96100
ecdsa==0.18.0
@@ -99,6 +103,10 @@ email-validator==1.3.1
99103
# via -r requirements-base.in
100104
emails==0.6
101105
# via -r requirements-base.in
106+
exceptiongroup==1.1.0
107+
# via
108+
# hypothesis
109+
# pytest
102110
fastapi==0.89.1
103111
# via -r requirements-base.in
104112
frozenlist==1.3.3
@@ -207,6 +215,7 @@ oauth2client==4.1.3
207215
# via -r requirements-base.in
208216
oauthlib[signedtoken]==3.2.2
209217
# via
218+
# atlassian-python-api
210219
# jira
211220
# requests-oauthlib
212221
packaging==21.3
@@ -295,6 +304,7 @@ pyyaml==6.0
295304
requests==2.28.1
296305
# via
297306
# -r requirements-base.in
307+
# atlassian-python-api
298308
# curlify
299309
# emails
300310
# google-api-core
@@ -308,6 +318,7 @@ requests==2.28.1
308318
# starlette-testclient
309319
requests-oauthlib==1.3.1
310320
# via
321+
# atlassian-python-api
311322
# google-auth-oauthlib
312323
# jira
313324
requests-toolbelt==0.10.1
@@ -335,6 +346,7 @@ sh==1.14.3
335346
# via -r requirements-base.in
336347
six==1.16.0
337348
# via
349+
# atlassian-python-api
338350
# ecdsa
339351
# google-auth
340352
# google-auth-httplib2
@@ -402,7 +414,9 @@ text-unidecode==1.3
402414
thinc==8.1.5
403415
# via spacy
404416
tomli==2.0.1
405-
# via schemathesis
417+
# via
418+
# pytest
419+
# schemathesis
406420
tomli-w==1.0.0
407421
# via schemathesis
408422
tqdm==4.64.1
@@ -415,6 +429,7 @@ typing-extensions==4.4.0
415429
# via
416430
# pydantic
417431
# schemathesis
432+
# starlette
418433
uritemplate==4.1.1
419434
# via google-api-python-client
420435
urllib3==1.26.13
@@ -435,6 +450,8 @@ wasabi==0.10.1
435450
# thinc
436451
werkzeug==2.2.2
437452
# via schemathesis
453+
wrapt==1.14.1
454+
# via deprecated
438455
yarl==1.8.1
439456
# via
440457
# aiohttp

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ def run(self):
423423
"slack_contact = dispatch.plugins.dispatch_slack.plugin:SlackContactPlugin",
424424
"slack_conversation = dispatch.plugins.dispatch_slack.plugin:SlackConversationPlugin",
425425
"zoom_conference = dispatch.plugins.dispatch_zoom.plugin:ZoomConferencePlugin",
426+
"dispatch_atlassian_confluence = dispatch.plugins.dispatch_atlassian_confluence.plugin:ConfluencePagePlugin",
427+
"dispatch_atlassian_confluence_document = dispatch.plugins.dispatch_atlassian_confluence.docs.plugin:ConfluencePageDocPlugin",
426428
],
427429
},
428430
)

src/dispatch/incident/flows.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,17 @@ def create_incident_documents(incident: Incident, db_session: SessionLocal):
361361
incident.storage.resource_id, incident_sheet_name, file_type="sheet"
362362
)
363363

364-
sheet.update(
365-
{
366-
"name": incident_sheet_name,
367-
"description": incident_sheet_description,
368-
"resource_type": DocumentResourceTypes.tracking,
369-
"resource_id": sheet["id"],
370-
}
371-
)
364+
if sheet:
365+
sheet.update(
366+
{
367+
"name": incident_sheet_name,
368+
"description": incident_sheet_description,
369+
"resource_type": DocumentResourceTypes.tracking,
370+
"resource_id": sheet["id"],
371+
}
372+
)
372373

373-
incident_documents.append(sheet)
374+
incident_documents.append(sheet)
374375

375376
event_service.log_incident_event(
376377
db_session=db_session,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from ._version import __version__ # noqa
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.0.1"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from pydantic import Field, SecretStr, HttpUrl
2+
3+
from enum import Enum
4+
from dispatch.config import BaseConfigurationModel
5+
6+
7+
class HostingType(str, Enum):
8+
"""Type of Atlassian Confluence deployment."""
9+
10+
cloud = "cloud"
11+
server = "server"
12+
13+
14+
class ConfluenceConfigurationBase(BaseConfigurationModel):
15+
"""Atlassian Confluence configuration description."""
16+
17+
api_url: HttpUrl = Field(
18+
title="API URL", description="This URL is used for communication with API."
19+
)
20+
hosting_type: HostingType = Field(
21+
"cloud", title="Hosting Type", description="Defines the type of deployment."
22+
)
23+
username: str = Field(
24+
title="Username", description="Username to use to authenticate to Confluence API."
25+
)
26+
password: SecretStr = Field(
27+
title="Password", description="Password to use to authenticate to Confluence API."
28+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from ._version import __version__ # noqa
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.0.1"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from dispatch.plugins.dispatch_atlassian_confluence import docs as confluence_doc_plugin
2+
from dispatch.plugins.bases import DocumentPlugin
3+
from dispatch.plugins.dispatch_atlassian_confluence.config import ConfluenceConfigurationBase
4+
from atlassian import Confluence
5+
from typing import List
6+
7+
8+
def replace_content(client: Confluence, document_id: str, replacements: List[str]) -> dict():
9+
# read content based on document_id
10+
current_content = client.get_page_by_id(
11+
document_id, expand="body.storage", status=None, version=None
12+
)
13+
current_content_body = current_content["body"]["storage"]["value"]
14+
for k, v in replacements.items():
15+
if v:
16+
current_content_body = current_content_body.replace(k, v)
17+
18+
updated_content = client.update_page(
19+
page_id=document_id,
20+
title=current_content["title"],
21+
body=current_content_body,
22+
representation="storage",
23+
type="page",
24+
parent_id=None,
25+
minor_edit=False,
26+
full_width=False,
27+
)
28+
return updated_content
29+
30+
31+
class ConfluencePageDocPlugin(DocumentPlugin):
32+
title = "Confluence pages plugin - Document Management"
33+
slug = "confluence-docs-document"
34+
description = "Use Confluence to update the contents."
35+
version = confluence_doc_plugin.__version__
36+
37+
author = "Cino Jose"
38+
author_url = "https://github.com/Netflix/dispatch"
39+
40+
def __init__(self):
41+
self.configuration_schema = ConfluenceConfigurationBase
42+
43+
def update(self, document_id: str, **kwargs):
44+
"""Replaces text in document."""
45+
kwargs = {"{{" + k + "}}": v for k, v in kwargs.items()}
46+
confluence_client = Confluence(
47+
url=self.configuration.api_url,
48+
username=self.configuration.username,
49+
password=self.configuration.password.get_secret_value(),
50+
cloud=self.configuration.hosting_type,
51+
)
52+
return replace_content(confluence_client, document_id, kwargs)

0 commit comments

Comments
 (0)