atlassian-python-api 5.0.1__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.
- atlassian/VERSION +1 -1
- atlassian/__init__.py +13 -2
- atlassian/assets.py +10 -3
- atlassian/bamboo.py +178 -2
- atlassian/bitbucket/__init__.py +87 -1
- atlassian/bitbucket/base.py +9 -2
- atlassian/bitbucket/server/__init__.py +11 -0
- atlassian/cloud_admin.py +418 -0
- atlassian/confluence/__init__.py +9 -0
- atlassian/confluence/base.py +32 -10
- atlassian/confluence/cloud/__init__.py +19 -0
- atlassian/confluence/cloud/classification_levels.py +77 -0
- atlassian/confluence/cloud/cloud.py +43 -5
- atlassian/confluence/cloud/content_properties.py +71 -0
- atlassian/confluence/cloud/graphql.py +99 -0
- atlassian/confluence/server/__init__.py +274 -74
- atlassian/crowd.py +78 -0
- atlassian/jira/__init__.py +21 -0
- atlassian/jira/core_methods.py +11698 -0
- atlassian/jira/jira_cloud.py +160 -0
- atlassian/{jira.py → jira/jira_server.py} +333 -6
- atlassian/jira/service_management_methods.py +1381 -0
- atlassian/jira/software_methods.py +2114 -0
- atlassian/rest_client.py +26 -1
- atlassian/service_desk.py +10 -3
- atlassian/yogi/__init__.py +17 -0
- atlassian/yogi/base.py +11 -0
- atlassian/yogi/cloud.py +2367 -0
- atlassian/yogi/yogi_confluence_cloud.py +10 -0
- atlassian/yogi/yogi_confluence_dc.py +94 -0
- atlassian/yogi/yogi_jira_cloud.py +10 -0
- atlassian/yogi/yogi_jira_dc.py +64 -0
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/METADATA +80 -10
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/RECORD +37 -22
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/WHEEL +0 -0
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/licenses/LICENSE +0 -0
- {atlassian_python_api-5.0.1.dist-info → atlassian_python_api-5.0.2.dist-info}/top_level.txt +0 -0
atlassian/cloud_admin.py
CHANGED
|
@@ -8,6 +8,424 @@ log = logging.getLogger(__name__)
|
|
|
8
8
|
ADMIN_URL = "https://api.atlassian.com"
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
class CloudAdmin(AtlassianRestAPI):
|
|
12
|
+
"""Client for Atlassian Administration's organization APIs.
|
|
13
|
+
|
|
14
|
+
This client is separate from product clients because it uses organization
|
|
15
|
+
admin API keys and the ``api.atlassian.com/admin`` API surface. API keys
|
|
16
|
+
need the scopes required by each operation, such as ``read:orgs:admin``.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, admin_api_key, *args, **kwargs):
|
|
20
|
+
kwargs["token"] = admin_api_key
|
|
21
|
+
kwargs["api_root"] = "admin"
|
|
22
|
+
kwargs["api_version"] = "v2"
|
|
23
|
+
super(CloudAdmin, self).__init__(url=ADMIN_URL, *args, **kwargs)
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def _params(**kwargs):
|
|
27
|
+
return {key: value for key, value in kwargs.items() if value is not None}
|
|
28
|
+
|
|
29
|
+
def get_organizations(self, cursor=None):
|
|
30
|
+
"""Return organizations accessible to the admin API key."""
|
|
31
|
+
return self.get("admin/v1/orgs", params=self._params(cursor=cursor))
|
|
32
|
+
|
|
33
|
+
def get_organization(self, org_id):
|
|
34
|
+
"""Return one organization (requires ``read:orgs:admin``)."""
|
|
35
|
+
return self.get(f"admin/v1/orgs/{org_id}")
|
|
36
|
+
|
|
37
|
+
def get_directories(self, org_id, account_id=None, directory_ids=None, search_term=None, cursor=None, limit=None):
|
|
38
|
+
"""Return organization directories, optionally filtered or cursor-paged."""
|
|
39
|
+
return self.get(
|
|
40
|
+
f"admin/v2/orgs/{org_id}/directories",
|
|
41
|
+
params=self._params(
|
|
42
|
+
accountId=account_id, directoryIds=directory_ids, searchTerm=search_term, cursor=cursor, limit=limit
|
|
43
|
+
),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def search_directory_users(self, org_id, directory_id, data=None):
|
|
47
|
+
"""Search directory users with the V2 request body (for example ``searchTerm`` or ``emails``)."""
|
|
48
|
+
return self.post(f"admin/v2/orgs/{org_id}/directories/{directory_id}/users/search", data=data or {})
|
|
49
|
+
|
|
50
|
+
def get_directory_user(self, org_id, directory_id, user_id):
|
|
51
|
+
"""Return details for one directory user."""
|
|
52
|
+
return self.get(f"admin/v2/orgs/{org_id}/directories/{directory_id}/users/{user_id}")
|
|
53
|
+
|
|
54
|
+
def get_directory_users_count(self, org_id, directory_id):
|
|
55
|
+
"""Return the number of users in a directory."""
|
|
56
|
+
return self.get(f"admin/v2/orgs/{org_id}/directories/{directory_id}/users/count")
|
|
57
|
+
|
|
58
|
+
def get_groups(self, org_id, directory_id, cursor=None, limit=None, search_term=None):
|
|
59
|
+
"""Return groups in a directory."""
|
|
60
|
+
return self.get(
|
|
61
|
+
f"admin/v2/orgs/{org_id}/directories/{directory_id}/groups",
|
|
62
|
+
params=self._params(cursor=cursor, limit=limit, searchTerm=search_term),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
def search_directory_groups(self, org_id, directory_id, data=None):
|
|
66
|
+
"""Search groups in a directory using the V2 request-body filters."""
|
|
67
|
+
return self.post(f"admin/v2/orgs/{org_id}/directories/{directory_id}/groups/search", data=data or {})
|
|
68
|
+
|
|
69
|
+
def get_group(self, org_id, directory_id, group_id):
|
|
70
|
+
"""Return one directory group."""
|
|
71
|
+
return self.get(f"admin/v2/orgs/{org_id}/directories/{directory_id}/groups/{group_id}")
|
|
72
|
+
|
|
73
|
+
def get_domains(self, org_id, cursor=None, limit=None):
|
|
74
|
+
"""Return verified domains for an organization."""
|
|
75
|
+
return self.get(f"admin/v2/orgs/{org_id}/domains", params=self._params(cursor=cursor, limit=limit))
|
|
76
|
+
|
|
77
|
+
def get_domain(self, org_id, domain_id):
|
|
78
|
+
"""Return one verified domain."""
|
|
79
|
+
return self.get(f"admin/v2/orgs/{org_id}/domains/{domain_id}")
|
|
80
|
+
|
|
81
|
+
def get_events(self, org_id, cursor=None, limit=None):
|
|
82
|
+
"""Return organization audit events."""
|
|
83
|
+
return self.get(f"admin/v2/orgs/{org_id}/events", params=self._params(cursor=cursor, limit=limit))
|
|
84
|
+
|
|
85
|
+
def get_event(self, org_id, event_id):
|
|
86
|
+
"""Return one organization audit event."""
|
|
87
|
+
return self.get(f"admin/v2/orgs/{org_id}/events/{event_id}")
|
|
88
|
+
|
|
89
|
+
@staticmethod
|
|
90
|
+
def _user_management_url(account_id, suffix=""):
|
|
91
|
+
return f"{ADMIN_URL}/users/{account_id}/manage{suffix}"
|
|
92
|
+
|
|
93
|
+
def get_user_management_permissions(self, account_id, privileges=None):
|
|
94
|
+
"""Return privileges the API key has for managing an account."""
|
|
95
|
+
return self.get(
|
|
96
|
+
self._user_management_url(account_id), absolute=True, params=self._params(privileges=privileges)
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
def get_user_profile(self, account_id):
|
|
100
|
+
"""Return an account profile through the User Management API."""
|
|
101
|
+
return self.get(self._user_management_url(account_id, "/profile"), absolute=True)
|
|
102
|
+
|
|
103
|
+
def update_user_profile(self, account_id, data):
|
|
104
|
+
"""Patch profile fields permitted by the account's ``profile.write`` privilege."""
|
|
105
|
+
return self.patch(self._user_management_url(account_id, "/profile"), data=data, absolute=True)
|
|
106
|
+
|
|
107
|
+
def set_user_email(self, account_id, email):
|
|
108
|
+
"""Set a managed user's verified email address and invalidate active sessions."""
|
|
109
|
+
return self.put(self._user_management_url(account_id, "/email"), data={"email": email}, absolute=True)
|
|
110
|
+
|
|
111
|
+
def get_user_api_tokens(self, account_id):
|
|
112
|
+
"""Return API tokens for a user when the API key has the required privilege."""
|
|
113
|
+
return self.get(self._user_management_url(account_id, "/api-tokens"), absolute=True)
|
|
114
|
+
|
|
115
|
+
def delete_user_api_token(self, account_id, token_id):
|
|
116
|
+
"""Revoke one user API token."""
|
|
117
|
+
return self.delete(self._user_management_url(account_id, f"/api-tokens/{token_id}"), absolute=True)
|
|
118
|
+
|
|
119
|
+
def deactivate_user(self, account_id, message=None):
|
|
120
|
+
"""Deactivate a managed account; an optional message is shown to the user."""
|
|
121
|
+
data = self._params(message=message)
|
|
122
|
+
return self.post(self._user_management_url(account_id, "/lifecycle/disable"), data=data, absolute=True)
|
|
123
|
+
|
|
124
|
+
def activate_user(self, account_id):
|
|
125
|
+
"""Reactivate a deactivated managed account."""
|
|
126
|
+
return self.post(self._user_management_url(account_id, "/lifecycle/enable"), data={}, absolute=True)
|
|
127
|
+
|
|
128
|
+
def delete_user(self, account_id):
|
|
129
|
+
"""Schedule permanent deletion of a managed account after its grace period."""
|
|
130
|
+
return self.post(self._user_management_url(account_id, "/lifecycle/delete"), data={}, absolute=True)
|
|
131
|
+
|
|
132
|
+
def cancel_user_deletion(self, account_id):
|
|
133
|
+
"""Cancel deletion during its grace period and reactivate the account."""
|
|
134
|
+
return self.post(self._user_management_url(account_id, "/lifecycle/cancel-delete"), data={}, absolute=True)
|
|
135
|
+
|
|
136
|
+
@staticmethod
|
|
137
|
+
def _scim_url(directory_id, resource=""):
|
|
138
|
+
return f"{ADMIN_URL}/scim/directory/{directory_id}{resource}"
|
|
139
|
+
|
|
140
|
+
def get_scim_users(self, directory_id, **params):
|
|
141
|
+
"""List SCIM users; pass SCIM filters such as ``filter`` or ``startIndex`` as keywords."""
|
|
142
|
+
return self.get(self._scim_url(directory_id, "/Users"), absolute=True, params=self._params(**params))
|
|
143
|
+
|
|
144
|
+
def get_scim_user(self, directory_id, user_id):
|
|
145
|
+
"""Return one SCIM user."""
|
|
146
|
+
return self.get(self._scim_url(directory_id, f"/Users/{user_id}"), absolute=True)
|
|
147
|
+
|
|
148
|
+
def create_scim_user(self, directory_id, data):
|
|
149
|
+
"""Create a SCIM user from a SCIM 2.0 User resource."""
|
|
150
|
+
return self.post(self._scim_url(directory_id, "/Users"), data=data, absolute=True)
|
|
151
|
+
|
|
152
|
+
def replace_scim_user(self, directory_id, user_id, data):
|
|
153
|
+
"""Replace a SCIM user with a complete User resource."""
|
|
154
|
+
return self.put(self._scim_url(directory_id, f"/Users/{user_id}"), data=data, absolute=True)
|
|
155
|
+
|
|
156
|
+
def patch_scim_user(self, directory_id, user_id, operations):
|
|
157
|
+
"""Apply SCIM PATCH operations to a user."""
|
|
158
|
+
return self.patch(
|
|
159
|
+
self._scim_url(directory_id, f"/Users/{user_id}"), data={"Operations": operations}, absolute=True
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
def delete_scim_user(self, directory_id, user_id):
|
|
163
|
+
"""Delete a user from the SCIM directory."""
|
|
164
|
+
return self.delete(self._scim_url(directory_id, f"/Users/{user_id}"), absolute=True)
|
|
165
|
+
|
|
166
|
+
def get_scim_groups(self, directory_id, **params):
|
|
167
|
+
"""List SCIM groups; pass SCIM filters as keyword arguments."""
|
|
168
|
+
return self.get(self._scim_url(directory_id, "/Groups"), absolute=True, params=self._params(**params))
|
|
169
|
+
|
|
170
|
+
def get_scim_group(self, directory_id, group_id):
|
|
171
|
+
"""Return one SCIM group."""
|
|
172
|
+
return self.get(self._scim_url(directory_id, f"/Groups/{group_id}"), absolute=True)
|
|
173
|
+
|
|
174
|
+
def create_scim_group(self, directory_id, data):
|
|
175
|
+
"""Create a SCIM group resource."""
|
|
176
|
+
return self.post(self._scim_url(directory_id, "/Groups"), data=data, absolute=True)
|
|
177
|
+
|
|
178
|
+
def replace_scim_group(self, directory_id, group_id, data):
|
|
179
|
+
"""Replace a SCIM group with a complete Group resource."""
|
|
180
|
+
return self.put(self._scim_url(directory_id, f"/Groups/{group_id}"), data=data, absolute=True)
|
|
181
|
+
|
|
182
|
+
def patch_scim_group(self, directory_id, group_id, operations):
|
|
183
|
+
"""Apply SCIM PATCH operations to a group, including membership changes."""
|
|
184
|
+
return self.patch(
|
|
185
|
+
self._scim_url(directory_id, f"/Groups/{group_id}"), data={"Operations": operations}, absolute=True
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
def delete_scim_group(self, directory_id, group_id):
|
|
189
|
+
"""Delete a SCIM group."""
|
|
190
|
+
return self.delete(self._scim_url(directory_id, f"/Groups/{group_id}"), absolute=True)
|
|
191
|
+
|
|
192
|
+
def get_scim_schemas(self, directory_id, schema_id=None):
|
|
193
|
+
"""Return all SCIM schemas or one schema by URN."""
|
|
194
|
+
suffix = "/Schemas" if schema_id is None else f"/Schemas/{schema_id}"
|
|
195
|
+
return self.get(self._scim_url(directory_id, suffix), absolute=True)
|
|
196
|
+
|
|
197
|
+
def get_scim_service_provider_config(self, directory_id):
|
|
198
|
+
"""Return supported SCIM features for a directory."""
|
|
199
|
+
return self.get(self._scim_url(directory_id, "/ServiceProviderConfig"), absolute=True)
|
|
200
|
+
|
|
201
|
+
def get_scim_resource_types(self, directory_id, resource_type=None):
|
|
202
|
+
"""Return SCIM resource types, or a single User/Group resource type."""
|
|
203
|
+
suffix = "/ResourceTypes" if resource_type is None else f"/ResourceTypes/{resource_type}"
|
|
204
|
+
return self.get(self._scim_url(directory_id, suffix), absolute=True)
|
|
205
|
+
|
|
206
|
+
def get_scim_links(self, org_id, account_id):
|
|
207
|
+
"""Return SCIM links for an Atlassian account."""
|
|
208
|
+
return self.get(
|
|
209
|
+
f"{ADMIN_URL}/admin/user-provisioning/v1/org/{org_id}/user/{account_id}/get-scim-links", absolute=True
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
def get_scim_links_for_email(self, org_id, email):
|
|
213
|
+
"""Return SCIM links associated with an email address."""
|
|
214
|
+
return self.post(
|
|
215
|
+
f"{ADMIN_URL}/admin/user-provisioning/v1/org/{org_id}/get-scim-links-for-email",
|
|
216
|
+
data={"email": email},
|
|
217
|
+
absolute=True,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
def unlink_scim_user(self, org_id, directory_id, user_id):
|
|
221
|
+
"""Unlink a SCIM user from an Atlassian account without deleting either resource."""
|
|
222
|
+
return self.patch(
|
|
223
|
+
f"{ADMIN_URL}/admin/user-provisioning/v1/org/{org_id}/scimDirectoryId/{directory_id}/scimUserId/{user_id}/unlink",
|
|
224
|
+
data={},
|
|
225
|
+
absolute=True,
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
def delete_scim_user_from_database(self, org_id, account_id):
|
|
229
|
+
"""Delete only the SCIM database record; use only for repair workflows."""
|
|
230
|
+
return self.delete(
|
|
231
|
+
f"{ADMIN_URL}/admin/user-provisioning/v1/org/{org_id}/user/{account_id}/onlyDeleteUserInDB", absolute=True
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
@staticmethod
|
|
235
|
+
def _dlp_url(org_id, suffix=""):
|
|
236
|
+
return f"{ADMIN_URL}/admin/dlp/v1/orgs/{org_id}/classification-levels{suffix}"
|
|
237
|
+
|
|
238
|
+
def get_classification_levels(self, org_id):
|
|
239
|
+
"""List DLP classification levels (``read:classification-levels:admin``)."""
|
|
240
|
+
return self.get(self._dlp_url(org_id), absolute=True)
|
|
241
|
+
|
|
242
|
+
def get_classification_level(self, org_id, level_id):
|
|
243
|
+
"""Return one DLP classification level."""
|
|
244
|
+
return self.get(self._dlp_url(org_id, f"/{level_id}"), absolute=True)
|
|
245
|
+
|
|
246
|
+
def create_classification_level(self, org_id, data):
|
|
247
|
+
"""Create a draft DLP classification level."""
|
|
248
|
+
return self.post(self._dlp_url(org_id), data=data, absolute=True)
|
|
249
|
+
|
|
250
|
+
def update_classification_level(self, org_id, level_id, data):
|
|
251
|
+
"""Replace/edit a DLP classification level."""
|
|
252
|
+
return self.put(self._dlp_url(org_id, f"/{level_id}"), data=data, absolute=True)
|
|
253
|
+
|
|
254
|
+
def publish_classification_levels(self, org_id, level_ids):
|
|
255
|
+
"""Publish one or more draft classification levels."""
|
|
256
|
+
return self.post(self._dlp_url(org_id, "/publish"), data={"levelIds": level_ids}, absolute=True)
|
|
257
|
+
|
|
258
|
+
def archive_classification_level(self, org_id, level_id):
|
|
259
|
+
"""Archive one classification level; published content becomes unclassified."""
|
|
260
|
+
return self.post(self._dlp_url(org_id, "/archive"), data={"levelId": level_id}, absolute=True)
|
|
261
|
+
|
|
262
|
+
def restore_classification_level(self, org_id, level_id):
|
|
263
|
+
"""Restore an archived classification level as a draft."""
|
|
264
|
+
return self.post(self._dlp_url(org_id, "/restore"), data={"levelId": level_id}, absolute=True)
|
|
265
|
+
|
|
266
|
+
def reorder_classification_levels(self, org_id, level_ids):
|
|
267
|
+
"""Set classification-level order; the most sensitive level ranks first."""
|
|
268
|
+
return self.post(self._dlp_url(org_id, "/reorder"), data={"levelIds": level_ids}, absolute=True)
|
|
269
|
+
|
|
270
|
+
@staticmethod
|
|
271
|
+
def _control_url(org_id, suffix="", version="v2"):
|
|
272
|
+
if version not in {"v1", "v2"}:
|
|
273
|
+
raise ValueError("Control API version must be 'v1' or 'v2'")
|
|
274
|
+
return f"{ADMIN_URL}/admin/control/{version}/orgs/{org_id}{suffix}"
|
|
275
|
+
|
|
276
|
+
def get_control_policies(self, org_id, version="v2", **params):
|
|
277
|
+
"""List Admin Control policies (V2 by default)."""
|
|
278
|
+
return self.get(self._control_url(org_id, "/policies", version), absolute=True, params=self._params(**params))
|
|
279
|
+
|
|
280
|
+
def get_control_policy(self, org_id, policy_id, version="v2"):
|
|
281
|
+
"""Return one Admin Control policy."""
|
|
282
|
+
return self.get(self._control_url(org_id, f"/policies/{policy_id}", version), absolute=True)
|
|
283
|
+
|
|
284
|
+
def create_control_policy(self, org_id, data, version="v2"):
|
|
285
|
+
"""Create an Admin Control policy."""
|
|
286
|
+
return self.post(self._control_url(org_id, "/policies", version), data=data, absolute=True)
|
|
287
|
+
|
|
288
|
+
def update_control_policy(self, org_id, policy_id, data, version="v2"):
|
|
289
|
+
"""Replace an Admin Control policy."""
|
|
290
|
+
return self.put(self._control_url(org_id, f"/policies/{policy_id}", version), data=data, absolute=True)
|
|
291
|
+
|
|
292
|
+
def delete_control_policy(self, org_id, policy_id, version="v2"):
|
|
293
|
+
"""Delete an Admin Control policy."""
|
|
294
|
+
return self.delete(self._control_url(org_id, f"/policies/{policy_id}", version), absolute=True)
|
|
295
|
+
|
|
296
|
+
def publish_control_draft_policies(self, org_id, data=None):
|
|
297
|
+
"""Publish V2 draft policies; this applies pending organization controls."""
|
|
298
|
+
return self.post(self._control_url(org_id, "/policies/publishDraftPolicies"), data=data or {}, absolute=True)
|
|
299
|
+
|
|
300
|
+
def validate_control_policy(self, org_id, policy_id):
|
|
301
|
+
"""Validate a V1 policy without changing it."""
|
|
302
|
+
return self.get(self._control_url(org_id, f"/policies/{policy_id}/validate", "v1"), absolute=True)
|
|
303
|
+
|
|
304
|
+
def get_control_policy_resources(self, org_id, policy_id, version="v2"):
|
|
305
|
+
"""List resources associated with a policy."""
|
|
306
|
+
return self.get(self._control_url(org_id, f"/policies/{policy_id}/resources", version), absolute=True)
|
|
307
|
+
|
|
308
|
+
def add_control_policy_resource(self, org_id, policy_id, data, version="v2"):
|
|
309
|
+
"""Associate a resource with a policy."""
|
|
310
|
+
return self.post(
|
|
311
|
+
self._control_url(org_id, f"/policies/{policy_id}/resources", version), data=data, absolute=True
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
def delete_control_policy_resources(self, org_id, policy_id, version="v2"):
|
|
315
|
+
"""Remove all resources associated with a policy."""
|
|
316
|
+
return self.delete(self._control_url(org_id, f"/policies/{policy_id}/resources", version), absolute=True)
|
|
317
|
+
|
|
318
|
+
def update_control_policy_resource(self, org_id, policy_id, resource_id, data):
|
|
319
|
+
"""Update one V1 policy resource."""
|
|
320
|
+
return self.put(
|
|
321
|
+
self._control_url(org_id, f"/policies/{policy_id}/resources/{resource_id}", "v1"), data=data, absolute=True
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
def delete_control_policy_resource(self, org_id, policy_id, resource_id):
|
|
325
|
+
"""Remove one V1 policy resource."""
|
|
326
|
+
return self.delete(
|
|
327
|
+
self._control_url(org_id, f"/policies/{policy_id}/resources/{resource_id}", "v1"), absolute=True
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
def add_users_to_auth_policy(self, org_id, policy_id, data):
|
|
331
|
+
"""Start a V1 task assigning users to an authentication policy."""
|
|
332
|
+
return self.post(
|
|
333
|
+
self._control_url(org_id, f"/auth-policy/{policy_id}/add-users", "v1"), data=data, absolute=True
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
def get_auth_policy_task(self, org_id, task_id):
|
|
337
|
+
"""Return status for an asynchronous authentication-policy task."""
|
|
338
|
+
return self.get(self._control_url(org_id, f"/auth-policy/task/{task_id}", "v1"), absolute=True)
|
|
339
|
+
|
|
340
|
+
def get_users_auth_policies(self, org_id, data):
|
|
341
|
+
"""Return authentication-policy information for managed users in bulk."""
|
|
342
|
+
return self.post(self._control_url(org_id, "/users/auth-policies/bulk-fetch", "v1"), data=data, absolute=True)
|
|
343
|
+
|
|
344
|
+
@staticmethod
|
|
345
|
+
def _api_access_url(org_id, suffix=""):
|
|
346
|
+
return f"{ADMIN_URL}/admin/api-access/v1/orgs/{org_id}{suffix}"
|
|
347
|
+
|
|
348
|
+
def get_org_api_tokens(self, org_id, **params):
|
|
349
|
+
"""List organization API tokens."""
|
|
350
|
+
return self.get(self._api_access_url(org_id, "/api-tokens"), absolute=True, params=self._params(**params))
|
|
351
|
+
|
|
352
|
+
def delete_org_api_tokens(self, org_id, data):
|
|
353
|
+
"""Delete organization API tokens selected by the API Access request body."""
|
|
354
|
+
return self.delete(self._api_access_url(org_id, "/api-tokens"), data=data, absolute=True)
|
|
355
|
+
|
|
356
|
+
def get_org_api_token_count(self, org_id):
|
|
357
|
+
"""Return API-token count for an organization."""
|
|
358
|
+
return self.get(self._api_access_url(org_id, "/api-tokens/count"), absolute=True)
|
|
359
|
+
|
|
360
|
+
def get_service_account_api_token_count(self, org_id, data):
|
|
361
|
+
"""Return service-account API-token count using the supplied filter body."""
|
|
362
|
+
return self.post(self._api_access_url(org_id, "/service-accounts/count"), data=data, absolute=True)
|
|
363
|
+
|
|
364
|
+
def get_service_account_api_tokens(self, org_id, account_id, **params):
|
|
365
|
+
"""List API tokens belonging to a service account."""
|
|
366
|
+
return self.get(
|
|
367
|
+
self._api_access_url(org_id, f"/service-accounts/{account_id}/api-tokens"),
|
|
368
|
+
absolute=True,
|
|
369
|
+
params=self._params(**params),
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
def delete_service_account_api_tokens(self, org_id, account_id, data):
|
|
373
|
+
"""Delete selected service-account API tokens."""
|
|
374
|
+
return self.delete(
|
|
375
|
+
self._api_access_url(org_id, f"/service-accounts/{account_id}/api-tokens"), data=data, absolute=True
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
def get_org_api_key_count(self, org_id):
|
|
379
|
+
"""Return API-key count for an organization."""
|
|
380
|
+
return self.get(self._api_access_url(org_id, "/api-keys/count"), absolute=True)
|
|
381
|
+
|
|
382
|
+
def get_org_api_keys(self, org_id, **params):
|
|
383
|
+
"""List API keys in an organization."""
|
|
384
|
+
return self.get(self._api_access_url(org_id, "/api-keys"), absolute=True, params=self._params(**params))
|
|
385
|
+
|
|
386
|
+
def revoke_org_api_key(self, org_id, api_key_id, data=None):
|
|
387
|
+
"""Revoke an organization API key."""
|
|
388
|
+
return self.patch(
|
|
389
|
+
self._api_access_url(org_id, f"/api-keys/revoke/{api_key_id}"), data=data or {}, absolute=True
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
def get_oauth_clients(self, org_id, **params):
|
|
393
|
+
"""List organization OAuth clients."""
|
|
394
|
+
return self.get(self._api_access_url(org_id, "/oauth-clients"), absolute=True, params=self._params(**params))
|
|
395
|
+
|
|
396
|
+
def create_oauth_client(self, org_id, data):
|
|
397
|
+
"""Create an OAuth client."""
|
|
398
|
+
return self.post(self._api_access_url(org_id, "/oauth-clients"), data=data, absolute=True)
|
|
399
|
+
|
|
400
|
+
def get_oauth_client_count(self, org_id, data=None):
|
|
401
|
+
"""Return OAuth-client count, optionally using API Access filters."""
|
|
402
|
+
return self.post(self._api_access_url(org_id, "/oauth-clients/count"), data=data or {}, absolute=True)
|
|
403
|
+
|
|
404
|
+
def get_oauth_client(self, org_id, client_id):
|
|
405
|
+
"""Return one OAuth client."""
|
|
406
|
+
return self.get(self._api_access_url(org_id, f"/oauth-clients/{client_id}"), absolute=True)
|
|
407
|
+
|
|
408
|
+
def delete_oauth_client(self, org_id, client_id):
|
|
409
|
+
"""Delete an OAuth client."""
|
|
410
|
+
return self.delete(self._api_access_url(org_id, f"/oauth-clients/{client_id}"), absolute=True)
|
|
411
|
+
|
|
412
|
+
def get_service_accounts(self, org_id, **params):
|
|
413
|
+
"""List organization service accounts."""
|
|
414
|
+
return self.get(self._api_access_url(org_id, "/service-accounts"), absolute=True, params=self._params(**params))
|
|
415
|
+
|
|
416
|
+
def create_service_account(self, org_id, data):
|
|
417
|
+
"""Create a service account."""
|
|
418
|
+
return self.post(self._api_access_url(org_id, "/service-accounts"), data=data, absolute=True)
|
|
419
|
+
|
|
420
|
+
def update_service_account(self, org_id, data):
|
|
421
|
+
"""Patch a service account using the API Access request body."""
|
|
422
|
+
return self.patch(self._api_access_url(org_id, "/service-accounts"), data=data, absolute=True)
|
|
423
|
+
|
|
424
|
+
def delete_service_account(self, org_id, service_account_id):
|
|
425
|
+
"""Delete a service account."""
|
|
426
|
+
return self.delete(self._api_access_url(org_id, f"/service-accounts/{service_account_id}"), absolute=True)
|
|
427
|
+
|
|
428
|
+
|
|
11
429
|
class CloudAdminOrgs(AtlassianRestAPI):
|
|
12
430
|
def __init__(self, admin_api_key, *args, **kwargs):
|
|
13
431
|
kwargs["token"] = admin_api_key
|
atlassian/confluence/__init__.py
CHANGED
|
@@ -6,6 +6,7 @@ This package provides both Cloud and Server implementations of the Confluence AP
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
from urllib.parse import urlparse
|
|
9
|
+
import warnings
|
|
9
10
|
|
|
10
11
|
from ..confluence_base import ConfluenceBase
|
|
11
12
|
from .cloud import Cloud as LegacyConfluenceCloud
|
|
@@ -31,6 +32,14 @@ class Confluence(LegacyConfluenceBase):
|
|
|
31
32
|
def __init__(self, url, *args, **kwargs):
|
|
32
33
|
if type(self) is not Confluence:
|
|
33
34
|
return
|
|
35
|
+
if kwargs.get("api_version") == "cloud":
|
|
36
|
+
warnings.warn(
|
|
37
|
+
"api_version='cloud' is deprecated; use cloud=True, or " "ConfluenceV2 for the Cloud V2 API.",
|
|
38
|
+
DeprecationWarning,
|
|
39
|
+
stacklevel=2,
|
|
40
|
+
)
|
|
41
|
+
kwargs.pop("api_version")
|
|
42
|
+
kwargs["cloud"] = True
|
|
34
43
|
# Detect which implementation to use
|
|
35
44
|
# Priority: explicit cloud= kwarg > URL-based heuristic
|
|
36
45
|
is_cloud = kwargs.get("cloud")
|
atlassian/confluence/base.py
CHANGED
|
@@ -224,16 +224,38 @@ class ConfluenceBase(AtlassianRestAPI):
|
|
|
224
224
|
if 400 <= response.status_code < 600:
|
|
225
225
|
try:
|
|
226
226
|
j = response.json()
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
except (TypeError, ValueError):
|
|
228
|
+
j = None
|
|
229
|
+
|
|
230
|
+
messages = []
|
|
231
|
+
if isinstance(j, dict):
|
|
232
|
+
for key in ("message", "detail", "reason"):
|
|
233
|
+
value = j.get(key)
|
|
234
|
+
if value:
|
|
235
|
+
messages.append(str(value))
|
|
236
|
+
errors = j.get("errors")
|
|
237
|
+
if isinstance(errors, dict):
|
|
238
|
+
messages.extend(str(value) for value in errors.values() if value)
|
|
239
|
+
elif isinstance(errors, list):
|
|
240
|
+
messages.extend(
|
|
241
|
+
str(item.get("message", item)) if isinstance(item, dict) else str(item)
|
|
242
|
+
for item in errors
|
|
243
|
+
if item
|
|
244
|
+
)
|
|
245
|
+
error_messages = j.get("errorMessages")
|
|
246
|
+
if isinstance(error_messages, list):
|
|
247
|
+
messages.extend(str(value) for value in error_messages if value)
|
|
248
|
+
|
|
249
|
+
if not messages:
|
|
250
|
+
# Some Confluence proxy and HTML-validation failures are not
|
|
251
|
+
# JSON. Include only a bounded, whitespace-normalized server
|
|
252
|
+
# response; never include the submitted page body.
|
|
253
|
+
response_text = " ".join((getattr(response, "text", "") or "").split())
|
|
254
|
+
if response_text:
|
|
255
|
+
messages.append(response_text[:1000])
|
|
231
256
|
else:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
response.raise_for_status()
|
|
236
|
-
else:
|
|
237
|
-
raise HTTPError(error_msg, response=response)
|
|
257
|
+
messages.append(f"HTTP {response.status_code}: {response.reason}")
|
|
258
|
+
|
|
259
|
+
raise HTTPError("\n".join(dict.fromkeys(messages)), response=response)
|
|
238
260
|
else:
|
|
239
261
|
response.raise_for_status()
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
import re
|
|
5
5
|
import time
|
|
6
|
+
import warnings
|
|
6
7
|
from urllib.parse import quote
|
|
7
8
|
from .base import ConfluenceCloudBase
|
|
8
9
|
import requests
|
|
@@ -22,6 +23,13 @@ class Cloud(ConfluenceCloudBase):
|
|
|
22
23
|
"""
|
|
23
24
|
|
|
24
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")
|
|
25
33
|
# Set default values only if not provided
|
|
26
34
|
if "cloud" not in kwargs:
|
|
27
35
|
kwargs["cloud"] = True
|
|
@@ -136,6 +144,17 @@ class Cloud(ConfluenceCloudBase):
|
|
|
136
144
|
"""Get content by ID."""
|
|
137
145
|
return self.get(f"content/{content_id}", **kwargs)
|
|
138
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
|
+
|
|
139
158
|
def get_content_by_type(self, content_type, **kwargs):
|
|
140
159
|
"""Get content by type (page, blogpost, etc.)."""
|
|
141
160
|
return self.get("content", params={"type": content_type, **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")
|