atlassian-python-api 3.41.13__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 (54) hide show
  1. atlassian/VERSION +1 -0
  2. atlassian/__init__.py +32 -0
  3. atlassian/bamboo.py +1343 -0
  4. atlassian/bitbucket/__init__.py +3572 -0
  5. atlassian/bitbucket/base.py +198 -0
  6. atlassian/bitbucket/cloud/__init__.py +24 -0
  7. atlassian/bitbucket/cloud/base.py +123 -0
  8. atlassian/bitbucket/cloud/common/__init__.py +1 -0
  9. atlassian/bitbucket/cloud/common/builds.py +85 -0
  10. atlassian/bitbucket/cloud/common/comments.py +50 -0
  11. atlassian/bitbucket/cloud/common/users.py +79 -0
  12. atlassian/bitbucket/cloud/repositories/__init__.py +437 -0
  13. atlassian/bitbucket/cloud/repositories/branchRestrictions.py +175 -0
  14. atlassian/bitbucket/cloud/repositories/commits.py +188 -0
  15. atlassian/bitbucket/cloud/repositories/defaultReviewers.py +94 -0
  16. atlassian/bitbucket/cloud/repositories/deploymentEnvironments.py +264 -0
  17. atlassian/bitbucket/cloud/repositories/diffstat.py +92 -0
  18. atlassian/bitbucket/cloud/repositories/groupPermissions.py +81 -0
  19. atlassian/bitbucket/cloud/repositories/hooks.py +117 -0
  20. atlassian/bitbucket/cloud/repositories/issues.py +164 -0
  21. atlassian/bitbucket/cloud/repositories/pipelines.py +274 -0
  22. atlassian/bitbucket/cloud/repositories/pullRequests.py +483 -0
  23. atlassian/bitbucket/cloud/repositories/refs.py +136 -0
  24. atlassian/bitbucket/cloud/repositories/repositoryVariables.py +146 -0
  25. atlassian/bitbucket/cloud/workspaces/__init__.py +146 -0
  26. atlassian/bitbucket/cloud/workspaces/members.py +62 -0
  27. atlassian/bitbucket/cloud/workspaces/permissions.py +125 -0
  28. atlassian/bitbucket/cloud/workspaces/projects.py +215 -0
  29. atlassian/bitbucket/server/__init__.py +46 -0
  30. atlassian/bitbucket/server/base.py +63 -0
  31. atlassian/bitbucket/server/common/__init__.py +1 -0
  32. atlassian/bitbucket/server/common/permissions.py +220 -0
  33. atlassian/bitbucket/server/globalPermissions.py +198 -0
  34. atlassian/bitbucket/server/projects/__init__.py +244 -0
  35. atlassian/bitbucket/server/projects/repos/__init__.py +327 -0
  36. atlassian/cloud_admin.py +32 -0
  37. atlassian/confluence.py +3336 -0
  38. atlassian/crowd.py +266 -0
  39. atlassian/errors.py +27 -0
  40. atlassian/insight.py +678 -0
  41. atlassian/jira.py +5324 -0
  42. atlassian/marketplace.py +84 -0
  43. atlassian/portfolio.py +108 -0
  44. atlassian/request_utils.py +39 -0
  45. atlassian/rest_client.py +558 -0
  46. atlassian/service_desk.py +911 -0
  47. atlassian/statuspage.py +3133 -0
  48. atlassian/utils.py +327 -0
  49. atlassian/xray.py +632 -0
  50. atlassian_python_api-3.41.13.dist-info/LICENSE +201 -0
  51. atlassian_python_api-3.41.13.dist-info/METADATA +261 -0
  52. atlassian_python_api-3.41.13.dist-info/RECORD +54 -0
  53. atlassian_python_api-3.41.13.dist-info/WHEEL +5 -0
  54. atlassian_python_api-3.41.13.dist-info/top_level.txt +1 -0
atlassian/bamboo.py ADDED
@@ -0,0 +1,1343 @@
1
+ # coding=utf-8
2
+ import logging
3
+
4
+ from requests.exceptions import HTTPError
5
+ from .rest_client import AtlassianRestAPI
6
+
7
+ log = logging.getLogger(__name__)
8
+
9
+
10
+ class Bamboo(AtlassianRestAPI):
11
+ """Private methods"""
12
+
13
+ def _get_generator(
14
+ self,
15
+ path,
16
+ elements_key="results",
17
+ element_key="result",
18
+ data=None,
19
+ flags=None,
20
+ params=None,
21
+ headers=None,
22
+ max_results=None,
23
+ ):
24
+ """
25
+ Generic method to return a generator with the results returned from Bamboo. It is intended to work for
26
+ responses in the form:
27
+ {
28
+ 'results':
29
+ {
30
+ 'size': 5,
31
+ 'start-index': 0,
32
+ 'max-result': 5,
33
+ 'result': []
34
+ },
35
+ ...
36
+ }
37
+ In this case we would have elements_key='results' element_key='result'.
38
+ The only reason to use this generator is to abstract dealing with response pagination from the client
39
+
40
+ :param path: URI for the resource
41
+ :return: generator with the contents of response[elements_key][element_key]
42
+ """
43
+ response = self.get(path, data, flags, params, headers)
44
+ if self.advanced_mode:
45
+ try:
46
+ response.raise_for_status()
47
+ response = response.json()
48
+ except HTTPError as e:
49
+ logging.error("Broken response: {}".format(e))
50
+ yield e
51
+ try:
52
+ results = response[elements_key]
53
+ size = 0
54
+ # Check if we still can get results
55
+ if size > max_results or results["size"] == 0:
56
+ return
57
+ for r in results[element_key]:
58
+ size += 1
59
+ yield r
60
+ except TypeError:
61
+ logging.error("Broken response: {}".format(response))
62
+ yield response
63
+
64
+ def base_list_call(
65
+ self,
66
+ resource,
67
+ expand,
68
+ favourite,
69
+ clover_enabled,
70
+ max_results,
71
+ label=None,
72
+ start_index=0,
73
+ **kwargs
74
+ ): # fmt: skip
75
+ flags = []
76
+ params = {"max-results": max_results}
77
+ if expand:
78
+ params["expand"] = expand
79
+ if favourite:
80
+ flags.append("favourite")
81
+ if clover_enabled:
82
+ flags.append("cloverEnabled")
83
+ if label:
84
+ params["label"] = label
85
+ params.update(kwargs)
86
+ if "elements_key" in kwargs and "element_key" in kwargs:
87
+ return self._get_generator(
88
+ self.resource_url(resource),
89
+ flags=flags,
90
+ params=params,
91
+ elements_key=kwargs["elements_key"],
92
+ element_key=kwargs["element_key"],
93
+ max_results=max_results,
94
+ )
95
+ params["start-index"] = start_index
96
+ return self.get(self.resource_url(resource), flags=flags, params=params)
97
+
98
+ """ Projects & Plans """
99
+
100
+ def projects(
101
+ self,
102
+ expand=None,
103
+ favourite=False,
104
+ clover_enabled=False,
105
+ max_results=25,
106
+ ):
107
+ return self.base_list_call(
108
+ "project",
109
+ expand=expand,
110
+ favourite=favourite,
111
+ clover_enabled=clover_enabled,
112
+ max_results=max_results,
113
+ elements_key="projects",
114
+ element_key="project",
115
+ )
116
+
117
+ def project(self, project_key, expand=None, favourite=False, clover_enabled=False):
118
+ resource = "project/{}".format(project_key)
119
+ return self.base_list_call(
120
+ resource=resource,
121
+ expand=expand,
122
+ favourite=favourite,
123
+ clover_enabled=clover_enabled,
124
+ start_index=0,
125
+ max_results=25,
126
+ )
127
+
128
+ def project_plans(self, project_key, start_index=0, max_results=25):
129
+ """
130
+ Returns a generator with the plans in a given project.
131
+ :param project_key: project key
132
+ :param start_index:
133
+ :param max_results:
134
+ :return: Generator with plans
135
+ """
136
+ resource = "project/{}".format(project_key)
137
+ return self.base_list_call(
138
+ resource,
139
+ expand="plans",
140
+ favourite=False,
141
+ clover_enabled=False,
142
+ start_index=start_index,
143
+ max_results=max_results,
144
+ elements_key="plans",
145
+ element_key="plan",
146
+ )
147
+
148
+ def plans(
149
+ self,
150
+ expand=None,
151
+ favourite=False,
152
+ clover_enabled=False,
153
+ start_index=0,
154
+ max_results=25,
155
+ ):
156
+ return self.base_list_call(
157
+ "plan",
158
+ expand=expand,
159
+ favourite=favourite,
160
+ clover_enabled=clover_enabled,
161
+ start_index=start_index,
162
+ max_results=max_results,
163
+ elements_key="plans",
164
+ element_key="plan",
165
+ )
166
+
167
+ def plan_directory_info(self, plan_key):
168
+ """
169
+ Returns information about the directories where artifacts, build logs, and build results will be stored.
170
+ Disabled by default.
171
+ See https://confluence.atlassian.com/display/BAMBOO/Plan+directory+information+REST+API for more information.
172
+ :param plan_key:
173
+ :return:
174
+ """
175
+ resource = "planDirectoryInfo/{}".format(plan_key)
176
+ return self.get(self.resource_url(resource))
177
+
178
+ def get_plan(self, plan_key, expand=None):
179
+ """
180
+ Get plan information.
181
+ :param plan_key:
182
+ :param expand: optional
183
+ :return:
184
+ """
185
+ params = {}
186
+ if expand:
187
+ params["expand"] = expand
188
+ resource = "rest/api/latest/plan/{}".format(plan_key)
189
+ return self.get(resource, params=params)
190
+
191
+ def search_plans(self, search_term, fuzzy=True, start_index=0, max_results=25):
192
+ """
193
+ Search plans by name
194
+ :param search_term: str
195
+ :param fuzzy: bool optional
196
+ :param start_index: optional
197
+ :param max_results: optional
198
+ :return: GET request
199
+ """
200
+
201
+ resource = "rest/api/latest/search/plans"
202
+ return self.get(
203
+ resource,
204
+ params={"fuzzy": fuzzy, "searchTerm": search_term, "max-results": max_results, "start-index": start_index},
205
+ )
206
+
207
+ def delete_plan(self, plan_key):
208
+ """
209
+ Marks plan for deletion. Plan will be deleted by a batch job.
210
+ :param plan_key:
211
+ :return:
212
+ """
213
+ resource = "rest/api/latest/plan/{}".format(plan_key)
214
+ return self.delete(resource)
215
+
216
+ def disable_plan(self, plan_key):
217
+ """
218
+ Disable plan.
219
+ :param plan_key: str TST-BLD
220
+ :return: DELETE request
221
+ """
222
+ resource = "plan/{plan_key}/enable".format(plan_key=plan_key)
223
+ return self.delete(self.resource_url(resource))
224
+
225
+ def enable_plan(self, plan_key):
226
+ """
227
+ Enable plan.
228
+ :param plan_key: str TST-BLD
229
+ :return: POST request
230
+ """
231
+ resource = "plan/{plan_key}/enable".format(plan_key=plan_key)
232
+ return self.post(self.resource_url(resource))
233
+
234
+ """ Branches """
235
+
236
+ def search_branches(self, plan_key, include_default_branch=True, max_results=25, start=0):
237
+ params = {
238
+ "max-result": max_results,
239
+ "start-index": start,
240
+ "masterPlanKey": plan_key,
241
+ "includeMasterBranch": include_default_branch,
242
+ }
243
+ size = 1
244
+ while params["start-index"] < size:
245
+ results = self.get(self.resource_url("search/branches"), params=params)
246
+ size = results["size"]
247
+ for r in results["searchResults"]:
248
+ yield r
249
+ params["start-index"] += results["max-result"]
250
+
251
+ def plan_branches(
252
+ self,
253
+ plan_key,
254
+ expand=None,
255
+ favourite=False,
256
+ clover_enabled=False,
257
+ max_results=25,
258
+ ):
259
+ """api/1.0/plan/{projectKey}-{buildKey}/branch"""
260
+ resource = "plan/{}/branch".format(plan_key)
261
+ return self.base_list_call(
262
+ resource,
263
+ expand,
264
+ favourite,
265
+ clover_enabled,
266
+ max_results,
267
+ elements_key="branches",
268
+ element_key="branch",
269
+ )
270
+
271
+ def get_branch_info(self, plan_key, branch_name):
272
+ """
273
+ Get information about a plan branch
274
+ :param plan_key:
275
+ :param branch_name:
276
+ :return:
277
+ """
278
+ resource = "plan/{plan_key}/branch/{branch_name}".format(plan_key=plan_key, branch_name=branch_name)
279
+ return self.get(self.resource_url(resource))
280
+
281
+ def create_branch(
282
+ self,
283
+ plan_key,
284
+ branch_name,
285
+ vcs_branch=None,
286
+ enabled=False,
287
+ cleanup_enabled=False,
288
+ ):
289
+ """
290
+ Method for creating branch for a specified plan.
291
+ You can use vcsBranch query param to define which vcsBranch should newly created branch use.
292
+ If not specified it will not override vcsBranch from the main plan.
293
+
294
+ :param plan_key: str TST-BLD
295
+ :param branch_name: str new-shiny-branch
296
+ :param vcs_branch: str feature/new-shiny-branch, /refs/heads/new-shiny-branch
297
+ :param enabled: bool
298
+ :param cleanup_enabled: bool - enable/disable automatic cleanup of branch
299
+ :return: PUT request
300
+ """
301
+ resource = "plan/{plan_key}/branch/{branch_name}".format(plan_key=plan_key, branch_name=branch_name)
302
+ params = {}
303
+ if vcs_branch:
304
+ params = dict(
305
+ vcsBranch=vcs_branch,
306
+ enabled="true" if enabled else "false",
307
+ cleanupEnabled="true" if cleanup_enabled else "false",
308
+ )
309
+ return self.put(self.resource_url(resource), params=params)
310
+
311
+ def get_vcs_branches(self, plan_key, max_results=25):
312
+ """
313
+ Get all vcs names for the current plan
314
+ :param plan_key: str TST-BLD
315
+ :param max_results
316
+ :return:
317
+ """
318
+ resource = "plan/{plan_key}/vcsBranches".format(plan_key=plan_key)
319
+ return self.base_list_call(
320
+ resource,
321
+ start_index=0,
322
+ max_results=max_results,
323
+ clover_enabled=None,
324
+ expand=None,
325
+ favourite=None,
326
+ )
327
+
328
+ """ Build results """
329
+
330
+ def results(
331
+ self,
332
+ project_key=None,
333
+ plan_key=None,
334
+ job_key=None,
335
+ build_number=None,
336
+ expand=None,
337
+ favourite=False,
338
+ clover_enabled=False,
339
+ issue_key=None,
340
+ label=None,
341
+ start_index=0,
342
+ max_results=25,
343
+ include_all_states=False,
344
+ ):
345
+ """
346
+ Get results as generic method
347
+ :param project_key:
348
+ :param plan_key:
349
+ :param job_key:
350
+ :param build_number:
351
+ :param expand:
352
+ :param favourite:
353
+ :param clover_enabled:
354
+ :param issue_key:
355
+ :param label:
356
+ :param start_index:
357
+ :param max_results:
358
+ :param include_all_states:
359
+ :return:
360
+ """
361
+ resource = "result"
362
+ if project_key and plan_key and job_key and build_number:
363
+ resource += "/{}-{}-{}/{}".format(project_key, plan_key, job_key, build_number)
364
+ elif project_key and plan_key and build_number:
365
+ resource += "/{}-{}/{}".format(project_key, plan_key, build_number)
366
+ elif project_key and plan_key:
367
+ resource += "/{}-{}".format(project_key, plan_key)
368
+ elif project_key:
369
+ resource += "/" + project_key
370
+
371
+ params = {}
372
+ if issue_key:
373
+ params["issueKey"] = issue_key
374
+ if include_all_states:
375
+ params["includeAllStates"] = include_all_states
376
+ return self.base_list_call(
377
+ resource,
378
+ expand=expand,
379
+ favourite=favourite,
380
+ clover_enabled=clover_enabled,
381
+ start_index=start_index,
382
+ max_results=max_results,
383
+ elements_key="results",
384
+ element_key="result",
385
+ label=label,
386
+ **params
387
+ ) # fmt: skip
388
+
389
+ def latest_results(
390
+ self,
391
+ expand=None,
392
+ favourite=False,
393
+ clover_enabled=False,
394
+ label=None,
395
+ issue_key=None,
396
+ start_index=0,
397
+ max_results=25,
398
+ include_all_states=False,
399
+ ):
400
+ """
401
+ Get the latest Results
402
+ :param expand:
403
+ :param favourite:
404
+ :param clover_enabled:
405
+ :param label:
406
+ :param issue_key:
407
+ :param start_index:
408
+ :param max_results:
409
+ :param include_all_states:
410
+ :return:
411
+ """
412
+ return self.results(
413
+ expand=expand,
414
+ favourite=favourite,
415
+ clover_enabled=clover_enabled,
416
+ label=label,
417
+ issue_key=issue_key,
418
+ start_index=start_index,
419
+ max_results=max_results,
420
+ include_all_states=include_all_states,
421
+ )
422
+
423
+ def project_latest_results(
424
+ self,
425
+ project_key,
426
+ expand=None,
427
+ favourite=False,
428
+ clover_enabled=False,
429
+ label=None,
430
+ issue_key=None,
431
+ start_index=0,
432
+ max_results=25,
433
+ include_all_states=False,
434
+ ):
435
+ """
436
+ Get the latest Project Results
437
+ :param project_key:
438
+ :param expand:
439
+ :param favourite:
440
+ :param clover_enabled:
441
+ :param label:
442
+ :param issue_key:
443
+ :param start_index:
444
+ :param max_results:
445
+ :param include_all_states:
446
+ :return:
447
+ """
448
+ return self.results(
449
+ project_key,
450
+ expand=expand,
451
+ favourite=favourite,
452
+ clover_enabled=clover_enabled,
453
+ label=label,
454
+ issue_key=issue_key,
455
+ start_index=start_index,
456
+ max_results=max_results,
457
+ include_all_states=include_all_states,
458
+ )
459
+
460
+ def plan_results(
461
+ self,
462
+ project_key,
463
+ plan_key,
464
+ expand=None,
465
+ favourite=False,
466
+ clover_enabled=False,
467
+ label=None,
468
+ issue_key=None,
469
+ start_index=0,
470
+ max_results=25,
471
+ include_all_states=False,
472
+ ):
473
+ """
474
+ Get Plan results
475
+ :param project_key:
476
+ :param plan_key:
477
+ :param expand:
478
+ :param favourite:
479
+ :param clover_enabled:
480
+ :param label:
481
+ :param issue_key:
482
+ :param start_index:
483
+ :param max_results:
484
+ :param include_all_states:
485
+ :return:
486
+ """
487
+ return self.results(
488
+ project_key,
489
+ plan_key,
490
+ expand=expand,
491
+ favourite=favourite,
492
+ clover_enabled=clover_enabled,
493
+ label=label,
494
+ issue_key=issue_key,
495
+ start_index=start_index,
496
+ max_results=max_results,
497
+ include_all_states=include_all_states,
498
+ )
499
+
500
+ def build_result(
501
+ self,
502
+ build_key,
503
+ expand=None,
504
+ include_all_states=False,
505
+ start=0,
506
+ max_results=25,
507
+ ):
508
+ """
509
+ Returns details of a specific build result
510
+ :param expand: expands build result details on request. Possible values are: artifacts, comments, labels,
511
+ Jira Issues, stages. stages expand is available only for top level plans. It allows to drill down to job results
512
+ using stages.stage.results.result. All expand parameters should contain results. Result prefix.
513
+ :param build_key: Should be in the form XX-YY[-ZZ]-99, that is, the last token should be an integer representing
514
+ the build number
515
+ :param include_all_states
516
+ :param start:
517
+ :param max_results:
518
+ """
519
+ try:
520
+ int(build_key.split("-")[-1])
521
+ resource = "result/{}".format(build_key)
522
+ return self.base_list_call(
523
+ resource,
524
+ expand,
525
+ favourite=False,
526
+ clover_enabled=False,
527
+ start_index=start,
528
+ max_results=max_results,
529
+ include_all_states=include_all_states,
530
+ )
531
+ except ValueError:
532
+ raise ValueError('The key "{}" does not correspond to a build result'.format(build_key))
533
+
534
+ def build_latest_result(self, plan_key, expand=None, include_all_states=False):
535
+ """
536
+ Returns details of the latest build result
537
+ :param expand: expands build result details on request. Possible values are: artifacts, comments, labels,
538
+ Jira Issues, stages. stages expand is available only for top level plans. It allows to drill down to job results
539
+ using stages.stage.results.result. All expand parameters should contain results. Result prefix.
540
+ :param plan_key: Should be in the form XX-YY[-ZZ]
541
+ :param include_all_states:
542
+ """
543
+ try:
544
+ resource = "result/{}/latest.json".format(plan_key)
545
+ return self.base_list_call(
546
+ resource,
547
+ expand,
548
+ favourite=False,
549
+ clover_enabled=False,
550
+ start_index=0,
551
+ max_results=25,
552
+ include_all_states=include_all_states,
553
+ )
554
+ except ValueError:
555
+ raise ValueError('The key "{}" does not correspond to the latest build result'.format(plan_key))
556
+
557
+ def delete_build_result(self, build_key):
558
+ """
559
+ Deleting result for specific build
560
+ :param build_key: Take full build key, example: PROJECT-PLAN-8
561
+ """
562
+ custom_resource = "/build/admin/deletePlanResults.action"
563
+ build_key = build_key.split("-")
564
+ plan_key = "{}-{}".format(build_key[0], build_key[1])
565
+ build_number = build_key[2]
566
+ params = {"buildKey": plan_key, "buildNumber": build_number}
567
+ return self.post(custom_resource, params=params, headers=self.form_token_headers)
568
+
569
+ def execute_build(
570
+ self,
571
+ plan_key,
572
+ stage=None,
573
+ execute_all_stages=True,
574
+ custom_revision=None,
575
+ **bamboo_variables
576
+ ): # fmt: skip
577
+ """
578
+ Fire build execution for specified plan.
579
+ !IMPORTANT! NOTE: for some reason, this method always execute all stages
580
+ :param plan_key: str TST-BLD
581
+ :param stage: str stage-name
582
+ :param execute_all_stages: bool
583
+ :param custom_revision: str revisionName
584
+ :param bamboo_variables: dict {variable=value}
585
+ :return: POST request
586
+ """
587
+ resource = "queue/{plan_key}".format(plan_key=plan_key)
588
+ params = {}
589
+ if stage:
590
+ execute_all_stages = False
591
+ params["stage"] = stage
592
+ if custom_revision:
593
+ params["customRevision"] = custom_revision
594
+ params["executeAllStages"] = "true" if execute_all_stages else "false"
595
+ if bamboo_variables:
596
+ for key, value in bamboo_variables.items():
597
+ params["bamboo.variable.{}".format(key)] = value
598
+
599
+ return self.post(self.resource_url(resource), params=params)
600
+
601
+ def stop_build(self, plan_key):
602
+ """
603
+ Stop the build which is in progress at the moment.
604
+ :param plan_key: str TST-BLD
605
+ :return: GET request
606
+ """
607
+ resource = "/build/admin/stopPlan.action?planKey={}".format(plan_key)
608
+ return self.post(path=resource, headers=self.no_check_headers)
609
+
610
+ """ Comments & Labels """
611
+
612
+ def comments(
613
+ self,
614
+ project_key,
615
+ plan_key,
616
+ build_number,
617
+ start_index=0,
618
+ max_results=25,
619
+ ):
620
+ resource = "result/{}-{}-{}/comment".format(project_key, plan_key, build_number)
621
+ params = {"start-index": start_index, "max-results": max_results}
622
+ return self.get(self.resource_url(resource), params=params)
623
+
624
+ def create_comment(self, project_key, plan_key, build_number, comment, author=None):
625
+ resource = "result/{}-{}-{}/comment".format(project_key, plan_key, build_number)
626
+ comment_data = {
627
+ "author": author if author else self.username,
628
+ "content": comment,
629
+ }
630
+ return self.post(self.resource_url(resource), data=comment_data)
631
+
632
+ def labels(
633
+ self,
634
+ project_key,
635
+ plan_key,
636
+ build_number,
637
+ start_index=0,
638
+ max_results=25,
639
+ ):
640
+ resource = "result/{}-{}-{}/label".format(project_key, plan_key, build_number)
641
+ params = {"start-index": start_index, "max-results": max_results}
642
+ return self.get(self.resource_url(resource), params=params)
643
+
644
+ def create_label(self, project_key, plan_key, build_number, label):
645
+ resource = "result/{}-{}-{}/label".format(project_key, plan_key, build_number)
646
+ return self.post(self.resource_url(resource), data={"name": label})
647
+
648
+ def delete_label(self, project_key, plan_key, build_number, label):
649
+ resource = "result/{}-{}-{}/label/{}".format(project_key, plan_key, build_number, label)
650
+ return self.delete(self.resource_url(resource))
651
+
652
+ def get_projects(self):
653
+ """Method used to list all projects defined in Bamboo.
654
+ Projects without any plan are not listed."""
655
+ start_idx = 0
656
+ max_results = 25
657
+
658
+ while True:
659
+ resource = "project?start-index={}&max-result={}".format(start_idx, max_results)
660
+
661
+ r = self.get(self.resource_url(resource))
662
+
663
+ if r is None:
664
+ break
665
+
666
+ if start_idx > r["projects"]["size"]:
667
+ break
668
+
669
+ start_idx += max_results
670
+
671
+ for project in r["projects"]["project"]:
672
+ yield project
673
+
674
+ def get_project(self, project_key):
675
+ """Method used to retrieve information for project specified as project key.
676
+ Possible expand parameters: plans, list of plans for project. plans.plan, list of plans with plan details
677
+ (only plans visible - READ permission for user)"""
678
+ resource = "project/{}?showEmpty".format(project_key)
679
+ return self.get(self.resource_url(resource))
680
+
681
+ def delete_project(self, project_key):
682
+ """Marks project for deletion. Project will be deleted by a batch job."""
683
+ resource = "project/{}".format(project_key)
684
+ return self.delete(self.resource_url(resource))
685
+
686
+ """ Deployments """
687
+
688
+ def deployment_projects(self):
689
+ resource = "deploy/project/all"
690
+ for project in self.get(self.resource_url(resource)):
691
+ yield project
692
+
693
+ def deployment_project(self, project_id):
694
+ resource = "deploy/project/{}".format(project_id)
695
+ return self.get(self.resource_url(resource))
696
+
697
+ def delete_deployment_project(self, project_id):
698
+ resource = "deploy/project/{}".format(project_id)
699
+ return self.delete(self.resource_url(resource))
700
+
701
+ def deployment_environment_results(self, env_id, expand=None, max_results=25):
702
+ resource = "deploy/environment/{environmentId}/results".format(environmentId=env_id)
703
+ params = {"max-result": max_results, "start-index": 0}
704
+ size = 1
705
+ if expand:
706
+ params["expand"] = expand
707
+ while params["start-index"] < size:
708
+ results = self.get(self.resource_url(resource), params=params)
709
+ size = results["size"]
710
+ for r in results["results"]:
711
+ yield r
712
+ params["start-index"] += results["max-result"]
713
+
714
+ def deployment_dashboard(self, project_id=None):
715
+ """
716
+ Returns the current status of each deployment environment
717
+ If no project id is provided, returns all projects.
718
+ """
719
+ resource = "deploy/dashboard/{}".format(project_id) if project_id else "deploy/dashboard"
720
+ return self.get(self.resource_url(resource))
721
+
722
+ def get_deployment_projects_for_plan(self, plan_key):
723
+ """
724
+ Returns deployment projects associated with a build plan.
725
+ :param plan_key: The key of the plan.
726
+ """
727
+ resource = "deploy/project/forPlan"
728
+ params = {"planKey": plan_key}
729
+ for deployment_project in self.get(self.resource_url(resource), params=params):
730
+ yield deployment_project
731
+
732
+ def trigger_deployment_for_version_on_environment(self, version_id, environment_id):
733
+ """
734
+ Triggers a deployment for a release version on the given environment.
735
+ Example: trigger_deployment_for_version_on_environment(version_id='3702785', environment_id='3637249')
736
+ :param version_id: str or int id of the release version.
737
+ :param environment_id: str or int id of the deployment environment.
738
+ :return:
739
+ """
740
+ resource = "queue/deployment"
741
+ params = {"versionId": version_id, "environmentId": environment_id}
742
+ return self.post(self.resource_url(resource), params=params)
743
+
744
+ """ Users & Groups """
745
+
746
+ def get_users_in_global_permissions(self, start=0, limit=25):
747
+ """
748
+ Provide users in global permissions configuration
749
+ :param start:
750
+ :param limit:
751
+ :return:
752
+ """
753
+ params = {"limit": limit, "start": start}
754
+ url = "rest/api/latest/permissions/global/users"
755
+ return self.get(url, params=params)
756
+
757
+ def get_groups(self, start=0, limit=25):
758
+ """
759
+ Retrieve a paginated list of groups.
760
+ The authenticated user must have restricted administrative permission or higher to use this resource.
761
+ :param start:
762
+ :param limit:
763
+ :return:
764
+ """
765
+ params = {"limit": limit, "start": start}
766
+ url = "rest/api/latest/admin/groups"
767
+ return self.get(url, params=params)
768
+
769
+ def create_group(self, group_name):
770
+ """
771
+ Create a new group.
772
+ The authenticated user must have restricted administrative permission or higher to use this resource.
773
+ :param group_name:
774
+ :return:
775
+ """
776
+ url = "rest/api/latest/admin/groups"
777
+ data = {"name": group_name}
778
+ return self.post(url, data=data)
779
+
780
+ def delete_group(self, group_name):
781
+ """
782
+ Deletes the specified group, removing it from the system.
783
+ The authenticated user must have restricted administrative permission or higher to use this resource.
784
+ :param group_name:
785
+ :return:
786
+ """
787
+ url = "rest/api/latest/admin/groups/{}".format(group_name)
788
+ return self.delete(url)
789
+
790
+ def add_users_into_group(self, group_name, users):
791
+ """
792
+ Add multiple users to a group.
793
+ The list of usernames should be passed as request body.
794
+ The authenticated user must have restricted administrative permission or higher to use this resource.
795
+ :param group_name:
796
+ :param users: list
797
+ :return:
798
+ """
799
+ url = "rest/api/latest/admin/groups/{}/add-users".format(group_name)
800
+ return self.post(url, data=users)
801
+
802
+ def remove_users_from_group(self, group_name, users):
803
+ """
804
+ Remove multiple users from a group.
805
+ The list of usernames should be passed as request body.
806
+ The authenticated user must have restricted administrative permission or higher to use this resource.
807
+ :param group_name:
808
+ :param users: list
809
+ :return:
810
+ """
811
+ url = "rest/api/latest/admin/groups/{}/remove-users".format(group_name)
812
+ return self.delete(url, data=users)
813
+
814
+ def get_users_from_group(self, group_name, filter_users=None, start=0, limit=25):
815
+ """
816
+ Retrieves a list of users that are members of a specified group.
817
+ The authenticated user must have restricted administrative permission or higher to use this resource.
818
+ :param filter_users:
819
+ :param group_name:
820
+ :param start:
821
+ :param limit:
822
+ :return:
823
+ """
824
+ params = {"limit": limit, "start": start}
825
+ if filter_users:
826
+ params = {"filter": filter_users}
827
+ url = "rest/api/latest/admin/groups/{}/more-members".format(group_name)
828
+ return self.get(url, params=params)
829
+
830
+ def get_users_not_in_group(self, group_name, filter_users="", start=0, limit=25):
831
+ """
832
+ Retrieves a list of users that are not members of a specified group.
833
+ The authenticated user must have restricted administrative permission or higher to use this resource.
834
+ :param filter_users:
835
+ :param group_name:
836
+ :param start:
837
+ :param limit:
838
+ :return:
839
+ """
840
+ params = {"limit": limit, "start": start}
841
+ if filter_users:
842
+ params = {"filter": filter_users}
843
+
844
+ url = "rest/api/latest/admin/groups/{}/more-non-members".format(group_name)
845
+ return self.get(url, params=params)
846
+
847
+ def get_build_queue(self, expand="queuedBuilds"):
848
+ """
849
+ Lists all the builds waiting in the build queue, adds or removes a build from the build queue.
850
+ May be used also to resume build on manual stage or rerun failed jobs.
851
+ :return:
852
+ """
853
+ params = {"expand": expand}
854
+ return self.get("rest/api/latest/queue", params=params)
855
+
856
+ def get_deployment_queue(self, expand="queuedDeployments"):
857
+ """
858
+ Provide list of deployment results scheduled for execution and waiting in queue.
859
+ :return:
860
+ """
861
+ params = {"expand": expand}
862
+ return self.get("rest/api/latest/queue/deployment", params=params)
863
+
864
+ def get_deployment_users(self, deployment_id, filter_name=None, start=0, limit=25):
865
+ """
866
+ Retrieve a list of users with their explicit permissions to given resource.
867
+ The list can be filtered by some attributes.
868
+ This resource is paged and returns a single page of results.
869
+ :param deployment_id:
870
+ :param filter_name:
871
+ :param start:
872
+ :param limit:
873
+ :return:
874
+ """
875
+ params = {"limit": limit, "start": start}
876
+ if filter_name:
877
+ params = {"name": filter_name}
878
+ resource = "permissions/deployment/{}/users".format(deployment_id)
879
+ return self.get(self.resource_url(resource), params=params)
880
+
881
+ def revoke_user_from_deployment(self, deployment_id, user, permissions=["READ", "WRITE", "BUILD"]):
882
+ """
883
+ Revokes deployment project permissions from a given user.
884
+ :param deployment_id:
885
+ :param user:
886
+ :param permissions:
887
+ :return:
888
+ """
889
+ resource = "permissions/deployment/{}/users/{}".format(deployment_id, user)
890
+ return self.delete(self.resource_url(resource), data=permissions)
891
+
892
+ def grant_user_to_deployment(self, deployment_id, user, permissions):
893
+ """
894
+ Grants deployment project permissions to a given user.
895
+ :param deployment_id:
896
+ :param user:
897
+ :param permissions:
898
+ :return:
899
+ """
900
+ resource = "permissions/deployment/{}/users/{}".format(deployment_id, user)
901
+ return self.put(self.resource_url(resource), data=permissions)
902
+
903
+ def get_deployment_groups(self, deployment_id, filter_name=None, start=0, limit=25):
904
+ """
905
+ Retrieve a list of groups with their deployment project permissions.
906
+ The list can be filtered by some attributes.
907
+ This resource is paged returns a single page of results.
908
+ :param deployment_id:
909
+ :param filter_name:
910
+ :param start:
911
+ :param limit:
912
+ :return:
913
+ """
914
+ params = {"limit": limit, "start": start}
915
+ if filter_name:
916
+ params = {"name": filter_name}
917
+ resource = "permissions/deployment/{}/groups".format(deployment_id)
918
+ return self.get(self.resource_url(resource), params=params)
919
+
920
+ def revoke_group_from_deployment(self, deployment_id, group, permissions=["READ", "WRITE", "BUILD"]):
921
+ """
922
+ Revokes deployment project permissions from a given group.
923
+ :param deployment_id:
924
+ :param group:
925
+ :param permissions:
926
+ :return:
927
+ """
928
+ resource = "permissions/deployment/{}/groups/{}".format(deployment_id, group)
929
+ return self.delete(self.resource_url(resource), data=permissions)
930
+
931
+ def grant_group_to_deployment(self, deployment_id, group, permissions):
932
+ """
933
+ Grants deployment project permissions to a given group.
934
+ :param deployment_id:
935
+ :param group:
936
+ :param permissions:
937
+ :return:
938
+ """
939
+ resource = "permissions/deployment/{}/groups/{}".format(deployment_id, group)
940
+ return self.put(self.resource_url(resource), data=permissions)
941
+
942
+ def get_environment_users(self, environment_id, filter_name=None, start=0, limit=25):
943
+ """
944
+ Retrieve a list of users with their explicit permissions to given resource.
945
+ The list can be filtered by some attributes.
946
+ This resource is paged and returns a single page of results.
947
+ :param environment_id:
948
+ :param filter_name:
949
+ :param start:
950
+ :param limit:
951
+ :return:
952
+ """
953
+ params = {"limit": limit, "start": start}
954
+ if filter_name:
955
+ params = {"name": filter_name}
956
+ resource = "permissions/environment/{}/users".format(environment_id)
957
+ return self.get(self.resource_url(resource), params=params)
958
+
959
+ def revoke_user_from_environment(self, environment_id, user, permissions=["READ", "WRITE", "BUILD"]):
960
+ """
961
+ Revokes deployment environment permissions from a given user.
962
+ :param environment_id:
963
+ :param user:
964
+ :param permissions:
965
+ :return:
966
+ """
967
+ resource = "permissions/environment/{}/users/{}".format(environment_id, user)
968
+ return self.delete(self.resource_url(resource), data=permissions)
969
+
970
+ def grant_user_to_environment(self, environment_id, user, permissions):
971
+ """
972
+ Grants deployment environment permissions to a given user.
973
+ :param environment_id:
974
+ :param user:
975
+ :param permissions:
976
+ :return:
977
+ """
978
+ resource = "permissions/environment/{}/users/{}".format(environment_id, user)
979
+ return self.put(self.resource_url(resource), data=permissions)
980
+
981
+ def get_environment_groups(self, environment_id, filter_name=None, start=0, limit=25):
982
+ """
983
+ Retrieve a list of groups with their deployment environment permissions.
984
+ The list can be filtered by some attributes.
985
+ This resource is paged returns a single page of results.
986
+ :param environment_id:
987
+ :param filter_name:
988
+ :param start:
989
+ :param limit:
990
+ :return:
991
+ """
992
+ params = {"limit": limit, "start": start}
993
+ if filter_name:
994
+ params = {"name": filter_name}
995
+ resource = "permissions/environment/{}/groups".format(environment_id)
996
+ return self.get(self.resource_url(resource), params=params)
997
+
998
+ def revoke_group_from_environment(self, environment_id, group, permissions=["READ", "WRITE", "BUILD"]):
999
+ """
1000
+ Revokes deployment environment permissions from a given group.
1001
+ :param environment_id:
1002
+ :param group:
1003
+ :param permissions:
1004
+ :return:
1005
+ """
1006
+ resource = "permissions/environment/{}/groups/{}".format(environment_id, group)
1007
+ return self.delete(self.resource_url(resource), data=permissions)
1008
+
1009
+ def grant_group_to_environment(self, environment_id, group, permissions):
1010
+ """
1011
+ Grants deployment environment permissions to a given group.
1012
+ :param environment_id:
1013
+ :param group:
1014
+ :param permissions:
1015
+ :return:
1016
+ """
1017
+ resource = "permissions/environment/{}/groups/{}".format(environment_id, group)
1018
+ return self.put(self.resource_url(resource), data=permissions)
1019
+
1020
+ """Other actions"""
1021
+
1022
+ def server_info(self):
1023
+ return self.get(self.resource_url("info"))
1024
+
1025
+ def agent_status(self, online=False):
1026
+ """
1027
+ Provides a list of all agents.
1028
+
1029
+ :param online: filter only online agents (default False = all)
1030
+ :return:
1031
+ """
1032
+ return self.get(self.resource_url("agent"), params={"online": online})
1033
+
1034
+ def agent_is_online(self, agent_id):
1035
+ """
1036
+ Get agent online status.
1037
+
1038
+ :param agent_id: Bamboo agent ID (integer number)
1039
+ :return: True/False
1040
+ """
1041
+ response = self.get(self.resource_url("agent/{}/status".format(agent_id)))
1042
+ return response["online"]
1043
+
1044
+ def agent_enable(self, agent_id):
1045
+ """
1046
+ Enable agent
1047
+
1048
+ :param agent_id: Bamboo agent ID (integer number)
1049
+ :return: None
1050
+ """
1051
+ self.put(self.resource_url("agent/{}/enable".format(agent_id)))
1052
+
1053
+ def agent_disable(self, agent_id):
1054
+ """
1055
+ Disable agent
1056
+
1057
+ :param agent_id: Bamboo agent ID (integer number)
1058
+ :return: None
1059
+ """
1060
+ self.put(self.resource_url("agent/{}/disable".format(agent_id)))
1061
+
1062
+ def agent_remote(self, online=False):
1063
+ """
1064
+ Provides a list of all agent authentication statuses.
1065
+
1066
+ :param online: list only online agents (default False = all)
1067
+ :return: list of agent-describing dictionaries
1068
+ """
1069
+ return self.get(self.resource_url("agent/remote"), params={"online": online})
1070
+
1071
+ def agent_details(self, agent_id, expand=None):
1072
+ """
1073
+ Provides details of an agent with given id.
1074
+
1075
+ :param agent_id: Bamboo agent ID (integer number)
1076
+ :param expand: Expand fields (None, capabilities, executableEnvironments, executableJobs)
1077
+ :return:
1078
+ """
1079
+ params = None
1080
+ if expand:
1081
+ params = {"expand": expand}
1082
+ return self.get(self.resource_url("agent/{}".format(agent_id)), params=params)
1083
+
1084
+ def agent_capabilities(self, agent_id, include_shared=True):
1085
+ """
1086
+ List agent's capabilities.
1087
+
1088
+ :param agent_id: Bamboo agent ID (integer number)
1089
+ :param include_shared: Include shared capabilities
1090
+ :return: agents
1091
+ """
1092
+ return self.get(
1093
+ self.resource_url("agent/{}/capability".format(agent_id)),
1094
+ params={"includeShared": include_shared},
1095
+ )
1096
+
1097
+ def activity(self):
1098
+ return self.get("build/admin/ajax/getDashboardSummary.action")
1099
+
1100
+ def get_custom_expiry(self, limit=25):
1101
+ """
1102
+ Get list of all plans where user has admin permission and which override global expiry settings.
1103
+ If global expiry is not enabled it returns empty response.
1104
+ :param limit:
1105
+ """
1106
+ url = "rest/api/latest/admin/expiry/custom/plan?limit={}".format(limit)
1107
+ return self.get(url)
1108
+
1109
+ def reports(self, max_results=25):
1110
+ params = {"max-results": max_results}
1111
+ return self._get_generator(
1112
+ self.resource_url("chart/reports"),
1113
+ elements_key="reports",
1114
+ element_key="report",
1115
+ params=params,
1116
+ )
1117
+
1118
+ def chart(
1119
+ self,
1120
+ report_key,
1121
+ build_keys,
1122
+ group_by_period,
1123
+ date_filter=None,
1124
+ date_from=None,
1125
+ date_to=None,
1126
+ width=None,
1127
+ height=None,
1128
+ start_index=9,
1129
+ max_results=25,
1130
+ ):
1131
+ params = {
1132
+ "reportKey": report_key,
1133
+ "buildKeys": build_keys,
1134
+ "groupByPeriod": group_by_period,
1135
+ "start-index": start_index,
1136
+ "max-results": max_results,
1137
+ }
1138
+ if date_filter:
1139
+ params["dateFilter"] = date_filter
1140
+ if date_filter == "RANGE":
1141
+ params["dateFrom"] = date_from
1142
+ params["dateTo"] = date_to
1143
+ if width:
1144
+ params["width"] = width
1145
+ if height:
1146
+ params["height"] = height
1147
+ return self.get(self.resource_url("chart"), params=params)
1148
+
1149
+ def reindex(self):
1150
+ """
1151
+ Returns status of the current indexing operation.
1152
+ reindexInProgress - reindex is currently performed in background reindexPending - reindex is required
1153
+ (i.e. it failed before or some upgrade task asked for it)
1154
+ """
1155
+ return self.get(self.resource_url("reindex"))
1156
+
1157
+ def stop_reindex(self):
1158
+ """
1159
+ Kicks off a reindex. Requires system admin permissions to perform this reindex.
1160
+ """
1161
+ return self.post(self.resource_url("reindex"))
1162
+
1163
+ def health_check(self):
1164
+ """
1165
+ Get health status
1166
+ https://confluence.atlassian.com/jirakb/how-to-retrieve-health-check-results-using-rest-api-867195158.html
1167
+ :return:
1168
+ """
1169
+ # check as Troubleshooting & Support Tools Plugin
1170
+ response = self.get("rest/troubleshooting/1.0/check/")
1171
+ if not response:
1172
+ # check as support tools
1173
+ response = self.get("rest/supportHealthCheck/1.0/check/")
1174
+ return response
1175
+
1176
+ def get_elastic_instance_logs(self, instance_id):
1177
+ """
1178
+ Get logs from an EC2 instance
1179
+ :param instance_id:
1180
+ :return:
1181
+ """
1182
+ resource = "/elasticInstances/instance/{instance_id}/logs".format(instance_id=instance_id)
1183
+ return self.get(self.resource_url(resource))
1184
+
1185
+ def get_elastic_configurations(self):
1186
+ """
1187
+ Get list of all elastic configurations
1188
+ :return:
1189
+ """
1190
+ resource = "elasticConfiguration"
1191
+ return self.get(self.resource_url(resource))
1192
+
1193
+ def create_elastic_configuration(self, json):
1194
+ """
1195
+ Create an elastic configuration
1196
+ :param json:
1197
+ :return:
1198
+ """
1199
+ resource = "elasticConfiguration"
1200
+ return self.post(self.resource_url(resource), json=json)
1201
+
1202
+ def get_elastic_configuration(self, configuration_id):
1203
+ """
1204
+ Get informatin of an elastic configuration
1205
+ :param configuration_id:
1206
+ :return:
1207
+ """
1208
+
1209
+ resource = "elasticConfiguration/{configuration_id}".format(configuration_id=configuration_id)
1210
+ return self.get(self.resource_url(resource))
1211
+
1212
+ def update_elastic_configuration(self, configuration_id, data):
1213
+ """
1214
+ Update an elastic configuration
1215
+ :param configuration_id:
1216
+ :param data:
1217
+ :return:
1218
+ """
1219
+
1220
+ resource = "elasticConfiguration/{configuration_id}".format(configuration_id=configuration_id)
1221
+ return self.put(self.resource_url(resource), data=data)
1222
+
1223
+ def delete_elastic_configuration(self, configuration_id):
1224
+ """
1225
+ Delete an elastic configuration
1226
+ :param configuration_id:
1227
+ :return:
1228
+ """
1229
+
1230
+ resource = "elasticConfiguration/{configuration_id}".format(configuration_id=configuration_id)
1231
+ return self.delete(self.resource_url(resource))
1232
+
1233
+ def get_elastic_bamboo(self):
1234
+ """
1235
+ Get elastic bamboo configuration
1236
+ :return:
1237
+ """
1238
+ response = self.get("rest/admin/latest/elastic/config")
1239
+ return response
1240
+
1241
+ def set_elastic_bamboo(self, data):
1242
+ """
1243
+ Set elastic bamboo configuration
1244
+ :return:
1245
+ """
1246
+ response = self.put("rest/admin/latest/elastic/config", data=data)
1247
+ return response
1248
+
1249
+ def get_plugins_info(self):
1250
+ """
1251
+ Provide plugins info
1252
+ :return a json of installed plugins
1253
+ """
1254
+ url = "rest/plugins/1.0/"
1255
+ return self.get(url, headers=self.no_check_headers, trailing=True)
1256
+
1257
+ def get_plugin_info(self, plugin_key):
1258
+ """
1259
+ Provide plugin info
1260
+ :return a json of installed plugins
1261
+ """
1262
+ url = "rest/plugins/1.0/{plugin_key}-key".format(plugin_key=plugin_key)
1263
+ return self.get(url, headers=self.no_check_headers, trailing=True)
1264
+
1265
+ def get_plugin_license_info(self, plugin_key):
1266
+ """
1267
+ Provide plugin license info
1268
+ :return a json specific License query
1269
+ """
1270
+ url = "rest/plugins/1.0/{plugin_key}-key/license".format(plugin_key=plugin_key)
1271
+ return self.get(url, headers=self.no_check_headers, trailing=True)
1272
+
1273
+ def upload_plugin(self, plugin_path):
1274
+ """
1275
+ Provide plugin path for upload into Jira e.g. useful for auto deploy
1276
+ :param plugin_path:
1277
+ :return:
1278
+ """
1279
+ files = {"plugin": open(plugin_path, "rb")}
1280
+ upm_token = self.request(
1281
+ method="GET",
1282
+ path="rest/plugins/1.0/",
1283
+ headers=self.no_check_headers,
1284
+ trailing=True,
1285
+ ).headers["upm-token"]
1286
+ url = "rest/plugins/1.0/?token={upm_token}".format(upm_token=upm_token)
1287
+ return self.post(url, files=files, headers=self.no_check_headers)
1288
+
1289
+ def disable_plugin(self, plugin_key):
1290
+ """
1291
+ Disable a plugin
1292
+ :param plugin_key:
1293
+ :return:
1294
+ """
1295
+ app_headers = {
1296
+ "X-Atlassian-Token": "nocheck",
1297
+ "Content-Type": "application/vnd.atl.plugins+json",
1298
+ }
1299
+ url = "rest/plugins/1.0/{plugin_key}-key".format(plugin_key=plugin_key)
1300
+ data = {"status": "disabled"}
1301
+ return self.put(url, data=data, headers=app_headers)
1302
+
1303
+ def enable_plugin(self, plugin_key):
1304
+ """
1305
+ Enable a plugin
1306
+ :param plugin_key:
1307
+ :return:
1308
+ """
1309
+ app_headers = {
1310
+ "X-Atlassian-Token": "nocheck",
1311
+ "Content-Type": "application/vnd.atl.plugins+json",
1312
+ }
1313
+ url = "rest/plugins/1.0/{plugin_key}-key".format(plugin_key=plugin_key)
1314
+ data = {"status": "enabled"}
1315
+ return self.put(url, data=data, headers=app_headers)
1316
+
1317
+ def delete_plugin(self, plugin_key):
1318
+ """
1319
+ Delete plugin
1320
+ :param plugin_key:
1321
+ :return:
1322
+ """
1323
+ url = "rest/plugins/1.0/{}-key".format(plugin_key)
1324
+ return self.delete(url)
1325
+
1326
+ def check_plugin_manager_status(self):
1327
+ url = "rest/plugins/latest/safe-mode"
1328
+ return self.request(method="GET", path=url, headers=self.safe_mode_headers)
1329
+
1330
+ def update_plugin_license(self, plugin_key, raw_license):
1331
+ """
1332
+ Update license for plugin
1333
+ :param plugin_key:
1334
+ :param raw_license:
1335
+ :return:
1336
+ """
1337
+ app_headers = {
1338
+ "X-Atlassian-Token": "nocheck",
1339
+ "Content-Type": "application/vnd.atl.plugins+json",
1340
+ }
1341
+ url = "/plugins/1.0/{plugin_key}/license".format(plugin_key=plugin_key)
1342
+ data = {"rawLicense": raw_license}
1343
+ return self.put(url, data=data, headers=app_headers)