atlassian-python-api 5.0.0__py3-none-any.whl → 5.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. atlassian/VERSION +1 -1
  2. atlassian/__init__.py +13 -2
  3. atlassian/assets.py +10 -3
  4. atlassian/bamboo.py +197 -4
  5. atlassian/bitbucket/__init__.py +87 -1
  6. atlassian/bitbucket/base.py +11 -14
  7. atlassian/bitbucket/cloud/repositories/__init__.py +33 -0
  8. atlassian/bitbucket/cloud/workspaces/__init__.py +15 -7
  9. atlassian/bitbucket/server/__init__.py +11 -0
  10. atlassian/cloud_admin.py +418 -0
  11. atlassian/confluence/__init__.py +13 -1
  12. atlassian/confluence/base.py +80 -14
  13. atlassian/confluence/cloud/__init__.py +233 -11
  14. atlassian/confluence/cloud/classification_levels.py +77 -0
  15. atlassian/confluence/cloud/cloud.py +79 -186
  16. atlassian/confluence/cloud/content_properties.py +71 -0
  17. atlassian/confluence/cloud/databases.py +59 -0
  18. atlassian/confluence/cloud/folders.py +48 -0
  19. atlassian/confluence/cloud/graphql.py +99 -0
  20. atlassian/confluence/cloud/tasks.py +86 -0
  21. atlassian/confluence/cloud/whiteboards.py +95 -0
  22. atlassian/confluence/server/__init__.py +603 -194
  23. atlassian/confluence_base.py +28 -3
  24. atlassian/crowd.py +78 -0
  25. atlassian/jira/__init__.py +21 -0
  26. atlassian/jira/core_methods.py +11698 -0
  27. atlassian/jira/jira_cloud.py +160 -0
  28. atlassian/{jira.py → jira/jira_server.py} +336 -8
  29. atlassian/jira/service_management_methods.py +1381 -0
  30. atlassian/jira/software_methods.py +2114 -0
  31. atlassian/rest_client.py +67 -8
  32. atlassian/service_desk.py +10 -3
  33. atlassian/yogi/__init__.py +17 -0
  34. atlassian/yogi/base.py +11 -0
  35. atlassian/yogi/cloud.py +2367 -0
  36. atlassian/yogi/yogi_confluence_cloud.py +10 -0
  37. atlassian/yogi/yogi_confluence_dc.py +94 -0
  38. atlassian/yogi/yogi_jira_cloud.py +10 -0
  39. atlassian/yogi/yogi_jira_dc.py +64 -0
  40. {atlassian_python_api-5.0.0.dist-info → atlassian_python_api-5.0.2.dist-info}/METADATA +80 -10
  41. {atlassian_python_api-5.0.0.dist-info → atlassian_python_api-5.0.2.dist-info}/RECORD +44 -25
  42. {atlassian_python_api-5.0.0.dist-info → atlassian_python_api-5.0.2.dist-info}/WHEEL +0 -0
  43. {atlassian_python_api-5.0.0.dist-info → atlassian_python_api-5.0.2.dist-info}/licenses/LICENSE +0 -0
  44. {atlassian_python_api-5.0.0.dist-info → atlassian_python_api-5.0.2.dist-info}/top_level.txt +0 -0
@@ -1,10 +1,16 @@
1
1
  # coding=utf-8
2
2
 
3
3
  import logging
4
+ import re
5
+ import time
6
+ import warnings
7
+ from urllib.parse import quote
4
8
  from .base import ConfluenceCloudBase
9
+ import requests
5
10
  from requests import HTTPError
6
11
  from atlassian.errors import (
7
12
  ApiError,
13
+ ApiNotFoundError,
8
14
  )
9
15
  from .cloud import ConfluenceCloud # noqa: F401
10
16
 
@@ -17,6 +23,13 @@ class Cloud(ConfluenceCloudBase):
17
23
  """
18
24
 
19
25
  def __init__(self, url="https://api.atlassian.com/", *args, **kwargs):
26
+ if kwargs.get("api_version") == "cloud":
27
+ warnings.warn(
28
+ "api_version='cloud' is deprecated; ConfluenceCloud already " "selects Cloud endpoints.",
29
+ DeprecationWarning,
30
+ stacklevel=2,
31
+ )
32
+ kwargs.pop("api_version")
20
33
  # Set default values only if not provided
21
34
  if "cloud" not in kwargs:
22
35
  kwargs["cloud"] = True
@@ -27,11 +40,121 @@ class Cloud(ConfluenceCloudBase):
27
40
  url = url.strip("/")
28
41
  super(Cloud, self).__init__(url, *args, **kwargs)
29
42
 
43
+ def _cloud_wiki_url(self, path):
44
+ """Return an absolute Cloud URL under the site's ``/wiki`` context."""
45
+ base_url = self.url.rstrip("/")
46
+ if not base_url.endswith("/wiki"):
47
+ base_url += "/wiki"
48
+ return self.url_joiner(base_url, path)
49
+
50
+ def create_or_update_template(
51
+ self,
52
+ name,
53
+ body,
54
+ template_type="page",
55
+ template_id=None,
56
+ description=None,
57
+ labels=None,
58
+ space=None,
59
+ ):
60
+ """Create or update a legacy Confluence Cloud content template.
61
+
62
+ The template API remains a V1 endpoint in Confluence Cloud. It is
63
+ therefore addressed explicitly rather than through this client's V2
64
+ root. ``body`` must be the body object returned by
65
+ :meth:`get_content_template`, or a storage body such as
66
+ ``{"storage": {"value": "...", "representation": "storage"}}``.
67
+ """
68
+ data = {"name": name, "templateType": template_type, "body": body}
69
+ if description:
70
+ data["description"] = description
71
+ if labels:
72
+ data["labels"] = labels
73
+ if space:
74
+ data["space"] = {"key": space}
75
+
76
+ endpoint = self._cloud_wiki_url("rest/api/template")
77
+ if template_id:
78
+ data["templateId"] = template_id
79
+ return self.put(endpoint, data=data, absolute=True)
80
+ return self.post(endpoint, json=data, absolute=True)
81
+
82
+ def get_content_template(self, template_id):
83
+ """Return a legacy Confluence Cloud content template by ID."""
84
+ endpoint = self._cloud_wiki_url(f"rest/api/template/{template_id}")
85
+ return self.get(endpoint, absolute=True)
86
+
87
+ def get_pdf_download_url_for_confluence_cloud(self, url):
88
+ """Start a Cloud PDF export and return its signed download URL.
89
+
90
+ Confluence Cloud creates PDF exports asynchronously. The legacy task
91
+ endpoint was removed; the current task state is available from the V2
92
+ ``pdfexporttask`` endpoint.
93
+ """
94
+ try:
95
+ response = self.get(url, headers=self.form_token_headers, not_json_response=True, absolute=True)
96
+ task_match = re.search(rb'name="ajs-taskId"\s+content="([^"]+)"', response)
97
+ if not task_match:
98
+ log.error("Could not find the PDF export task ID in the response")
99
+ return None
100
+
101
+ task_id = task_match.group(1).decode("utf-8", errors="ignore")
102
+ poll_url = self._cloud_wiki_url(f"api/v2/pdfexporttask/progress/{task_id}")
103
+
104
+ while True:
105
+ log.info("Check if PDF export task has completed.")
106
+ progress_response = self.get(poll_url, absolute=True) or {}
107
+ task_state = progress_response.get("state")
108
+ if task_state == "FAILED" or progress_response.get("status") == "failed":
109
+ log.error("PDF conversion was not successful.")
110
+ return None
111
+
112
+ download_url = progress_response.get("result")
113
+ if isinstance(download_url, str) and download_url:
114
+ return self._cloud_wiki_url(download_url) if download_url.startswith("/") else download_url
115
+
116
+ percentage_complete = int(progress_response.get("progress", 0))
117
+ log.info("%s%% - %s", percentage_complete, task_state)
118
+ time.sleep(3)
119
+ except (AttributeError, TypeError, ValueError) as error:
120
+ log.error("Could not initiate or poll the PDF export: %s", error)
121
+ return None
122
+
123
+ def get_page_as_pdf(self, page_id):
124
+ """Export a Cloud page as PDF using Confluence's asynchronous exporter."""
125
+ export_url = self._cloud_wiki_url(f"spaces/flyingpdf/pdfpageexport.action?pageId={page_id}")
126
+ download_url = self.get_pdf_download_url_for_confluence_cloud(export_url)
127
+ if not download_url:
128
+ raise ApiNotFoundError("Failed to export page as PDF", reason="Failed to get download PDF URL")
129
+ response = requests.get(download_url, timeout=75)
130
+ response.raise_for_status()
131
+ if not response.content.startswith(b"%PDF-"):
132
+ raise ApiError(
133
+ "Confluence returned non-PDF content while exporting the page. "
134
+ "Check the page permissions and authentication configuration."
135
+ )
136
+ return response.content
137
+
138
+ def export_page(self, page_id):
139
+ """Alias for :meth:`get_page_as_pdf`."""
140
+ return self.get_page_as_pdf(page_id)
141
+
30
142
  # Content Management
31
143
  def get_content(self, content_id, **kwargs):
32
144
  """Get content by ID."""
33
145
  return self.get(f"content/{content_id}", **kwargs)
34
146
 
147
+ def iter_page_versions(self, page_id, limit=200, expand=None):
148
+ """Yield every version of a legacy Confluence Cloud page lazily."""
149
+ params = {"limit": int(limit)}
150
+ if expand is not None:
151
+ params["expand"] = expand
152
+ return self._get_paged(f"rest/api/content/{page_id}/version", params=params)
153
+
154
+ def get_all_page_versions(self, page_id, limit=200, expand=None):
155
+ """Return every version of a legacy Confluence Cloud page as a list."""
156
+ return list(self.iter_page_versions(page_id, limit=limit, expand=expand))
157
+
35
158
  def get_content_by_type(self, content_type, **kwargs):
36
159
  """Get content by type (page, blogpost, etc.)."""
37
160
  return self.get("content", params={"type": content_type, **kwargs})
@@ -90,9 +213,39 @@ class Cloud(ConfluenceCloudBase):
90
213
  return len(result.get("results", [])) > 0
91
214
 
92
215
  def page_exists(self, space_key, title, **kwargs):
93
- """Check if page exists in Confluence Cloud."""
94
- result = self.get_page_by_title(space_key, title, **kwargs)
95
- return len(result.get("results", [])) > 0
216
+ """Check whether a page exists using the Cloud V2 page endpoint.
217
+
218
+ The retired V1 content lookup accepted a space key directly. V2 page
219
+ queries require a space ID, so resolve the key first and request only
220
+ one matching page.
221
+ """
222
+ try:
223
+ spaces = self.get("spaces", params={"keys": [space_key], "limit": 1})
224
+ except HTTPError as error:
225
+ if error.response is not None and error.response.status_code == 404:
226
+ return False
227
+ raise
228
+ space_results = spaces.get("results", [])
229
+ if not space_results:
230
+ return False
231
+
232
+ try:
233
+ result = self.get(
234
+ "pages",
235
+ params={
236
+ "space-id": space_results[0]["id"],
237
+ "title": title,
238
+ "status": "current",
239
+ "body-format": "none",
240
+ "limit": 1,
241
+ **kwargs,
242
+ },
243
+ )
244
+ except HTTPError as error:
245
+ if error.response is not None and error.response.status_code == 404:
246
+ return False
247
+ raise
248
+ return bool(result.get("results", []))
96
249
 
97
250
  def get_page_child_by_type(self, page_id, type="page", start=None, limit=None, expand=None):
98
251
  """
@@ -134,6 +287,19 @@ class Cloud(ConfluenceCloudBase):
134
287
 
135
288
  raise
136
289
 
290
+ def get_page_child_count(self, page_id, type="page"):
291
+ """Return the number of direct children of ``type`` without listing them."""
292
+ page = self.get_page_by_id(page_id, expand=f"children.{type}")
293
+ collection = page.get("children", {}).get(type, {})
294
+ size = collection.get("size")
295
+ if size is not None:
296
+ return int(size)
297
+ return len(collection.get("results", []))
298
+
299
+ def page_has_children(self, page_id, type="page"):
300
+ """Return whether a page has at least one direct child of ``type``."""
301
+ return self.get_page_child_count(page_id, type=type) > 0
302
+
137
303
  def get_child_title_list(self, page_id, type="page", start=None, limit=None):
138
304
  """
139
305
  Find a list of Child title
@@ -182,6 +348,10 @@ class Cloud(ConfluenceCloudBase):
182
348
  """
183
349
  return self._get_paged("spaces", params=kwargs)
184
350
 
351
+ def get_space_names(self, **kwargs):
352
+ """Return the names of every space without fetching page content."""
353
+ return [space["name"] for space in self.get_all_spaces(**kwargs) if space.get("name")]
354
+
185
355
  def get_space(self, space_id, **kwargs):
186
356
  """Get space by ID."""
187
357
  return self.get(f"spaces/{space_id}", **kwargs)
@@ -216,17 +386,54 @@ class Cloud(ConfluenceCloudBase):
216
386
  return self.get("user/current", **kwargs)
217
387
 
218
388
  # Group Management
219
- def get_groups(self, **kwargs):
220
- """Get all groups."""
221
- return self.get("group", **kwargs)
389
+ def get_groups(self, start=0, limit=1000, **kwargs):
390
+ """Get a page of Cloud groups from the supported V1 group API."""
391
+ params = {"start": start, "limit": limit, **kwargs}
392
+ return self.get(self._cloud_wiki_url("rest/api/group"), params=params, absolute=True)
222
393
 
223
394
  def get_group(self, group_id, **kwargs):
224
- """Get group by ID."""
225
- return self.get(f"group/{group_id}", **kwargs)
395
+ """Get a Cloud group by its ID."""
396
+ return self.get(
397
+ self._cloud_wiki_url("rest/api/group/by-id"),
398
+ params={"id": group_id, **kwargs},
399
+ absolute=True,
400
+ )
401
+
402
+ def get_all_groups(self, start=0, limit=1000):
403
+ """Return the groups from a Cloud group result page.
404
+
405
+ This retains the legacy return shape while using the supported Cloud
406
+ endpoint. Use each group's ``id`` with :meth:`get_group_members`.
407
+ """
408
+ return self.get_groups(start=start, limit=limit).get("results", [])
226
409
 
227
- def get_group_members(self, group_id, **kwargs):
228
- """Get group members."""
229
- return self.get(f"group/{group_id}/member", **kwargs)
410
+ def get_group_members(self, group_id, start=None, limit=None, expand=None, **kwargs):
411
+ """Get a paginated collection of members for a Cloud group ID."""
412
+ params = dict(kwargs)
413
+ if start is not None:
414
+ params["start"] = start
415
+ if limit is not None:
416
+ params["limit"] = limit
417
+ if expand is not None:
418
+ params["expand"] = expand
419
+ return self.get(
420
+ self._cloud_wiki_url(f"rest/api/group/{quote(str(group_id), safe='')}/membersByGroupId"),
421
+ params=params,
422
+ absolute=True,
423
+ )
424
+
425
+ def get_all_members(self, group_id, expand=None):
426
+ """Return all members of a Cloud group identified by its ID."""
427
+ members = []
428
+ start = 0
429
+ limit = 1000
430
+ while True:
431
+ response = self.get_group_members(group_id, start=start, limit=limit, expand=expand)
432
+ values = response.get("results", [])
433
+ members.extend(values)
434
+ if not values or len(values) < limit:
435
+ return members
436
+ start += len(values)
230
437
 
231
438
  # Label Management
232
439
  def get_labels(self, **kwargs):
@@ -292,6 +499,21 @@ class Cloud(ConfluenceCloudBase):
292
499
  """Search content."""
293
500
  return self.get("content/search", params={"cql": query, **kwargs})
294
501
 
502
+ def cql(self, cql, **kwargs):
503
+ """Return one page of Cloud CQL search results."""
504
+ return self.search_content(cql, **kwargs)
505
+
506
+ def iter_cql(self, cql, **kwargs):
507
+ """Yield every Cloud CQL result, following pagination links."""
508
+ return self._get_paged("content/search", params={"cql": cql, **kwargs})
509
+
510
+ def cql_all(self, cql, **kwargs):
511
+ """Return all paginated Cloud CQL results as a list.
512
+
513
+ Prefer :meth:`iter_cql` for large result sets.
514
+ """
515
+ return list(self.iter_cql(cql, **kwargs))
516
+
295
517
  def search_spaces(self, query, **kwargs):
296
518
  """Search spaces."""
297
519
  return self.get("space/search", params={"query": query, **kwargs})
@@ -0,0 +1,77 @@
1
+ """Confluence Cloud V2 data-classification operations."""
2
+
3
+ from typing import Any, Dict, List, Optional, cast
4
+
5
+ from ...confluence_base import ConfluenceBase
6
+
7
+
8
+ class ClassificationLevelOperations(ConfluenceBase):
9
+ """Operations for Confluence Cloud data-classification levels.
10
+
11
+ Classification levels are available only to Confluence Cloud sites with the
12
+ corresponding Atlassian Guard entitlement.
13
+ """
14
+
15
+ _CONTENT_RESOURCES = {
16
+ "blogpost": "blogposts",
17
+ "database": "databases",
18
+ "page": "pages",
19
+ "whiteboard": "whiteboards",
20
+ }
21
+
22
+ @classmethod
23
+ def _classification_resource(cls, content_type: str) -> str:
24
+ try:
25
+ return cls._CONTENT_RESOURCES[content_type]
26
+ except KeyError as error:
27
+ allowed = ", ".join(sorted(cls._CONTENT_RESOURCES))
28
+ raise ValueError(f"content_type must be one of: {allowed}") from error
29
+
30
+ def _classification_url(self, content_type: str, content_id: str) -> str:
31
+ resource = self._classification_resource(content_type)
32
+ return f"api/v2/{resource}/{content_id}/classification-level"
33
+
34
+ def get_classification_levels(self) -> Optional[List[Dict[str, Any]]]:
35
+ """Return the classification levels configured for the Confluence site."""
36
+ # The V2 schema defines this endpoint's JSON response as an array,
37
+ # while the base client's historical ``get`` annotation is a mapping.
38
+ return cast(Optional[List[Dict[str, Any]]], self.get("api/v2/classification-levels"))
39
+
40
+ def get_content_classification_level(
41
+ self, content_type: str, content_id: str, status: Optional[str] = None
42
+ ) -> Optional[Dict[str, Any]]:
43
+ """Return the classification level applied to a content item."""
44
+ params = {"status": status} if status is not None else None
45
+ return self.get(self._classification_url(content_type, content_id), params=params)
46
+
47
+ def update_content_classification_level(
48
+ self, content_type: str, content_id: str, classification_level_id: str, status: str = "current"
49
+ ) -> Optional[Dict[str, Any]]:
50
+ """Apply a classification level to a content item."""
51
+ if status not in ("current", "draft"):
52
+ raise ValueError("status must be 'current' or 'draft'")
53
+ data = {"id": classification_level_id, "status": status}
54
+ return self.put(self._classification_url(content_type, content_id), data=data)
55
+
56
+ def reset_content_classification_level(
57
+ self, content_type: str, content_id: str, status: str = "current"
58
+ ) -> Optional[Dict[str, Any]]:
59
+ """Reset a content item to its space's default classification level."""
60
+ if status not in ("current", "draft"):
61
+ raise ValueError("status must be 'current' or 'draft'")
62
+ url = f"{self._classification_url(content_type, content_id)}/reset"
63
+ return self.post(url, data={"status": status})
64
+
65
+ def get_space_default_classification_level(self, space_id: str) -> Optional[Dict[str, Any]]:
66
+ """Return a space's default classification level."""
67
+ return self.get(f"api/v2/spaces/{space_id}/classification-level/default")
68
+
69
+ def update_space_default_classification_level(
70
+ self, space_id: str, classification_level_id: str
71
+ ) -> Optional[Dict[str, Any]]:
72
+ """Set a space's default classification level."""
73
+ return self.put(f"api/v2/spaces/{space_id}/classification-level/default", data={"id": classification_level_id})
74
+
75
+ def delete_space_default_classification_level(self, space_id: str) -> Optional[Dict[str, Any]]:
76
+ """Remove a space's configured default classification level."""
77
+ return self.delete(f"api/v2/spaces/{space_id}/classification-level/default")