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.
- atlassian/VERSION +1 -1
- atlassian/__init__.py +13 -2
- atlassian/assets.py +10 -3
- atlassian/bamboo.py +197 -4
- atlassian/bitbucket/__init__.py +87 -1
- atlassian/bitbucket/base.py +11 -14
- atlassian/bitbucket/cloud/repositories/__init__.py +33 -0
- atlassian/bitbucket/cloud/workspaces/__init__.py +15 -7
- atlassian/bitbucket/server/__init__.py +11 -0
- atlassian/cloud_admin.py +418 -0
- atlassian/confluence/__init__.py +13 -1
- atlassian/confluence/base.py +80 -14
- atlassian/confluence/cloud/__init__.py +233 -11
- atlassian/confluence/cloud/classification_levels.py +77 -0
- atlassian/confluence/cloud/cloud.py +79 -186
- atlassian/confluence/cloud/content_properties.py +71 -0
- atlassian/confluence/cloud/databases.py +59 -0
- atlassian/confluence/cloud/folders.py +48 -0
- atlassian/confluence/cloud/graphql.py +99 -0
- atlassian/confluence/cloud/tasks.py +86 -0
- atlassian/confluence/cloud/whiteboards.py +95 -0
- atlassian/confluence/server/__init__.py +603 -194
- atlassian/confluence_base.py +28 -3
- 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} +336 -8
- atlassian/jira/service_management_methods.py +1381 -0
- atlassian/jira/software_methods.py +2114 -0
- atlassian/rest_client.py +67 -8
- 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.0.dist-info → atlassian_python_api-5.0.2.dist-info}/METADATA +80 -10
- {atlassian_python_api-5.0.0.dist-info → atlassian_python_api-5.0.2.dist-info}/RECORD +44 -25
- {atlassian_python_api-5.0.0.dist-info → atlassian_python_api-5.0.2.dist-info}/WHEEL +0 -0
- {atlassian_python_api-5.0.0.dist-info → atlassian_python_api-5.0.2.dist-info}/licenses/LICENSE +0 -0
- {atlassian_python_api-5.0.0.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
|
|
@@ -19,7 +20,10 @@ class Confluence(LegacyConfluenceBase):
|
|
|
19
20
|
|
|
20
21
|
def __new__(cls, url, *args, **kwargs):
|
|
21
22
|
api_version = kwargs.get("api_version")
|
|
22
|
-
|
|
23
|
+
# Scoped API tokens use the Atlassian API gateway and only support the
|
|
24
|
+
# Cloud v2 endpoints. Route gateway URLs there automatically so callers
|
|
25
|
+
# do not have to know the internal client split.
|
|
26
|
+
if api_version in (1, 2) or ConfluenceBase._is_api_gateway_url(url):
|
|
23
27
|
from .cloud.cloud import ConfluenceCloud as VersionedConfluenceCloud
|
|
24
28
|
|
|
25
29
|
return VersionedConfluenceCloud(url, *args, **kwargs)
|
|
@@ -28,6 +32,14 @@ class Confluence(LegacyConfluenceBase):
|
|
|
28
32
|
def __init__(self, url, *args, **kwargs):
|
|
29
33
|
if type(self) is not Confluence:
|
|
30
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
|
|
31
43
|
# Detect which implementation to use
|
|
32
44
|
# Priority: explicit cloud= kwarg > URL-based heuristic
|
|
33
45
|
is_cloud = kwargs.get("cloud")
|
atlassian/confluence/base.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
2
|
|
|
3
3
|
import copy
|
|
4
|
-
|
|
4
|
+
import re
|
|
5
|
+
from urllib.parse import urljoin, urlparse
|
|
5
6
|
import logging
|
|
6
7
|
from requests import HTTPError
|
|
7
8
|
from ..rest_client import AtlassianRestAPI
|
|
9
|
+
from ..errors import ApiValueError
|
|
8
10
|
|
|
9
11
|
log = logging.getLogger(__name__)
|
|
10
12
|
|
|
@@ -47,6 +49,42 @@ class ConfluenceBase(AtlassianRestAPI):
|
|
|
47
49
|
"""
|
|
48
50
|
return self.url_joiner(self.url, url)
|
|
49
51
|
|
|
52
|
+
def get_page_id_by_url(self, page_url):
|
|
53
|
+
"""Resolve a Confluence page URL to its page ID.
|
|
54
|
+
|
|
55
|
+
``viewpage.action?pageId=...`` URLs are resolved without a request.
|
|
56
|
+
Display and short ``/x/...`` URLs are requested through the configured
|
|
57
|
+
authenticated session, which follows the Confluence redirect and reads
|
|
58
|
+
the page ID from the resulting URL or HTML metadata.
|
|
59
|
+
"""
|
|
60
|
+
parsed_url = urlparse(page_url)
|
|
61
|
+
page_id_match = re.search(r"(?:[?&]pageId=)([^&#]+)", page_url, re.IGNORECASE)
|
|
62
|
+
if page_id_match:
|
|
63
|
+
return page_id_match.group(1)
|
|
64
|
+
|
|
65
|
+
client_host = urlparse(self.url).hostname
|
|
66
|
+
if not parsed_url.scheme or not parsed_url.hostname:
|
|
67
|
+
raise ApiValueError("page_url must be an absolute Confluence page URL")
|
|
68
|
+
if client_host and parsed_url.hostname != client_host:
|
|
69
|
+
raise ApiValueError("page_url must belong to the configured Confluence instance")
|
|
70
|
+
|
|
71
|
+
response = self.get(page_url, absolute=True, advanced_mode=True)
|
|
72
|
+
resolved_url = response.url
|
|
73
|
+
page_id_match = re.search(r"(?:[?&]pageId=)([^&#]+)", resolved_url, re.IGNORECASE)
|
|
74
|
+
if page_id_match:
|
|
75
|
+
return page_id_match.group(1)
|
|
76
|
+
|
|
77
|
+
content = response.content.decode("utf-8", errors="ignore")
|
|
78
|
+
page_id_match = re.search(
|
|
79
|
+
r'<meta[^>]+name=["\']ajs-page-id["\'][^>]+content=["\']([^"\']+)["\']',
|
|
80
|
+
content,
|
|
81
|
+
re.IGNORECASE,
|
|
82
|
+
)
|
|
83
|
+
if page_id_match:
|
|
84
|
+
return page_id_match.group(1)
|
|
85
|
+
|
|
86
|
+
raise ApiValueError("Could not determine a page ID from page_url")
|
|
87
|
+
|
|
50
88
|
@property
|
|
51
89
|
def _new_session_args(self):
|
|
52
90
|
"""
|
|
@@ -152,10 +190,16 @@ class ConfluenceBase(AtlassianRestAPI):
|
|
|
152
190
|
if url is None:
|
|
153
191
|
break
|
|
154
192
|
|
|
155
|
-
if url.
|
|
156
|
-
#
|
|
193
|
+
if not urlparse(url).scheme:
|
|
194
|
+
# Confluence returns both ``/rest/api/...`` and
|
|
195
|
+
# ``rest/api/...`` forms for next links. Neither is an
|
|
196
|
+
# absolute URL, despite the latter lacking a leading slash.
|
|
157
197
|
parsed = urlparse(self.url)
|
|
158
|
-
|
|
198
|
+
site_url = f"{parsed.scheme}://{parsed.netloc}"
|
|
199
|
+
if url.startswith("/") or url.startswith(("rest/", "wiki/")):
|
|
200
|
+
url = f"{site_url}/{url.lstrip('/')}"
|
|
201
|
+
else:
|
|
202
|
+
url = urljoin(f"{self.url.rstrip('/')}/", url)
|
|
159
203
|
|
|
160
204
|
# From now on we have absolute URLs with parameters
|
|
161
205
|
absolute = True
|
|
@@ -180,16 +224,38 @@ class ConfluenceBase(AtlassianRestAPI):
|
|
|
180
224
|
if 400 <= response.status_code < 600:
|
|
181
225
|
try:
|
|
182
226
|
j = response.json()
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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])
|
|
187
256
|
else:
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
response.raise_for_status()
|
|
192
|
-
else:
|
|
193
|
-
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)
|
|
194
260
|
else:
|
|
195
261
|
response.raise_for_status()
|