-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathconfluence_document.py
More file actions
37 lines (31 loc) · 1.49 KB
/
confluence_document.py
File metadata and controls
37 lines (31 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright 2023-2025 Broadcom
# SPDX-License-Identifier: Apache-2.0
class ConfluenceDocument:
def __init__(self, metadata: dict, data: str, deleted=False):
"""
Initializes a ConfluenceDocument instance.
:param metadata: A dictionary containing metadata about the Confluence document.
Expected to contain 'title', 'id', and 'source'.
'deleted' key will be added to indicate if the document is considered deleted.
:param data: A string representing the content of the Confluence page.
"""
self.validate_metadata(metadata)
metadata["deleted"] = deleted
self.metadata = metadata
self.data = data
def serialize(self):
"""
Serializes the ConfluenceDocument instance into a dictionary.
"""
return {"metadata": self.metadata, "data": self.data}
@staticmethod
def validate_metadata(metadata):
"""
Validates the metadata dictionary to ensure it contains required keys plus checks for 'deleted'.
:param metadata: A dictionary containing metadata about the Confluence document.
:raises ValueError: If metadata does not contain the required keys ('title', 'id', 'source').
"""
required_keys = {"title", "id", "source"}
if not required_keys.issubset(metadata):
missing_keys = required_keys - metadata.keys()
raise ValueError(f"Metadata is missing required keys: {missing_keys}")