forked from atlassian-api/atlassian-python-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbamboo.py
executable file
·1315 lines (1189 loc) · 44.2 KB
/
bamboo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# coding=utf-8
import logging
from requests.exceptions import HTTPError
from .rest_client import AtlassianRestAPI
log = logging.getLogger(__name__)
class Bamboo(AtlassianRestAPI):
"""Private methods"""
def _get_generator(
self,
path,
elements_key="results",
element_key="result",
data=None,
flags=None,
params=None,
headers=None,
max_results=None,
):
"""
Generic method to return a generator with the results returned from Bamboo. It is intended to work for
responses in the form:
{
'results':
{
'size': 5,
'start-index': 0,
'max-result': 5,
'result': []
},
...
}
In this case we would have elements_key='results' element_key='result'.
The only reason to use this generator is to abstract dealing with response pagination from the client
:param path: URI for the resource
:return: generator with the contents of response[elements_key][element_key]
"""
response = self.get(path, data, flags, params, headers)
if self.advanced_mode:
try:
response.raise_for_status()
response = response.json()
except HTTPError as e:
logging.error("Broken response: {}".format(e))
yield e
try:
results = response[elements_key]
size = 0
# Check if we still can get results
if size > max_results or results["size"] == 0:
return
for r in results[element_key]:
size += 1
yield r
except TypeError:
logging.error("Broken response: {}".format(response))
yield response
def base_list_call(
self,
resource,
expand,
favourite,
clover_enabled,
max_results,
label=None,
start_index=0,
**kwargs
): # fmt: skip
flags = []
params = {"max-results": max_results}
if expand:
params["expand"] = expand
if favourite:
flags.append("favourite")
if clover_enabled:
flags.append("cloverEnabled")
if label:
params["label"] = label
params.update(kwargs)
if "elements_key" in kwargs and "element_key" in kwargs:
return self._get_generator(
self.resource_url(resource),
flags=flags,
params=params,
elements_key=kwargs["elements_key"],
element_key=kwargs["element_key"],
max_results=max_results,
)
params["start-index"] = start_index
return self.get(self.resource_url(resource), flags=flags, params=params)
""" Projects & Plans """
def projects(
self,
expand=None,
favourite=False,
clover_enabled=False,
max_results=25,
):
return self.base_list_call(
"project",
expand=expand,
favourite=favourite,
clover_enabled=clover_enabled,
max_results=max_results,
elements_key="projects",
element_key="project",
)
def project(self, project_key, expand=None, favourite=False, clover_enabled=False):
resource = "project/{}".format(project_key)
return self.base_list_call(
resource=resource,
expand=expand,
favourite=favourite,
clover_enabled=clover_enabled,
start_index=0,
max_results=25,
)
def project_plans(self, project_key, start_index=0, max_results=25):
"""
Returns a generator with the plans in a given project.
:param project_key: project key
:param start_index:
:param max_results:
:return: Generator with plans
"""
resource = "project/{}".format(project_key)
return self.base_list_call(
resource,
expand="plans",
favourite=False,
clover_enabled=False,
start_index=start_index,
max_results=max_results,
elements_key="plans",
element_key="plan",
)
def plans(
self,
expand=None,
favourite=False,
clover_enabled=False,
start_index=0,
max_results=25,
):
return self.base_list_call(
"plan",
expand=expand,
favourite=favourite,
clover_enabled=clover_enabled,
start_index=start_index,
max_results=max_results,
elements_key="plans",
element_key="plan",
)
def plan_directory_info(self, plan_key):
"""
Returns information about the directories where artifacts, build logs, and build results will be stored.
Disabled by default.
See https://confluence.atlassian.com/display/BAMBOO/Plan+directory+information+REST+API for more information.
:param plan_key:
:return:
"""
resource = "planDirectoryInfo/{}".format(plan_key)
return self.get(self.resource_url(resource))
def get_plan(self, plan_key, expand=None):
"""
Get plan information.
:param plan_key:
:param expand: optional
:return:
"""
params = {}
if expand:
params["expand"] = expand
resource = "rest/api/latest/plan/{}".format(plan_key)
return self.get(resource, params=params)
def search_plans(self, search_term, fuzzy=True, start_index=0, max_results=25):
"""
Search plans by name
:param search_term: str
:param fuzzy: bool optional
:param start_index: optional
:param max_results: optional
:return: GET request
"""
resource = "rest/api/latest/search/plans"
return self.get(
resource,
params={"fuzzy": fuzzy, "searchTerm": search_term, "max-results": max_results, "start-index": start_index},
)
def delete_plan(self, plan_key):
"""
Marks plan for deletion. Plan will be deleted by a batch job.
:param plan_key:
:return:
"""
resource = "rest/api/latest/plan/{}".format(plan_key)
return self.delete(resource)
def disable_plan(self, plan_key):
"""
Disable plan.
:param plan_key: str TST-BLD
:return: DELETE request
"""
resource = "plan/{plan_key}/enable".format(plan_key=plan_key)
return self.delete(self.resource_url(resource))
def enable_plan(self, plan_key):
"""
Enable plan.
:param plan_key: str TST-BLD
:return: POST request
"""
resource = "plan/{plan_key}/enable".format(plan_key=plan_key)
return self.post(self.resource_url(resource))
""" Branches """
def search_branches(self, plan_key, include_default_branch=True, max_results=25, start=0):
params = {
"max-result": max_results,
"start-index": start,
"masterPlanKey": plan_key,
"includeMasterBranch": include_default_branch,
}
size = 1
while params["start-index"] < size:
results = self.get(self.resource_url("search/branches"), params=params)
size = results["size"]
for r in results["searchResults"]:
yield r
params["start-index"] += results["max-result"]
def plan_branches(
self,
plan_key,
expand=None,
favourite=False,
clover_enabled=False,
max_results=25,
):
"""api/1.0/plan/{projectKey}-{buildKey}/branch"""
resource = "plan/{}/branch".format(plan_key)
return self.base_list_call(
resource,
expand,
favourite,
clover_enabled,
max_results,
elements_key="branches",
element_key="branch",
)
def get_branch_info(self, plan_key, branch_name):
"""
Get information about a plan branch
:param plan_key:
:param branch_name:
:return:
"""
resource = "plan/{plan_key}/branch/{branch_name}".format(plan_key=plan_key, branch_name=branch_name)
return self.get(self.resource_url(resource))
def create_branch(
self,
plan_key,
branch_name,
vcs_branch=None,
enabled=False,
cleanup_enabled=False,
):
"""
Method for creating branch for a specified plan.
You can use vcsBranch query param to define which vcsBranch should newly created branch use.
If not specified it will not override vcsBranch from the main plan.
:param plan_key: str TST-BLD
:param branch_name: str new-shiny-branch
:param vcs_branch: str feature/new-shiny-branch, /refs/heads/new-shiny-branch
:param enabled: bool
:param cleanup_enabled: bool - enable/disable automatic cleanup of branch
:return: PUT request
"""
resource = "plan/{plan_key}/branch/{branch_name}".format(plan_key=plan_key, branch_name=branch_name)
params = {}
if vcs_branch:
params = dict(
vcsBranch=vcs_branch,
enabled="true" if enabled else "false",
cleanupEnabled="true" if cleanup_enabled else "false",
)
return self.put(self.resource_url(resource), params=params)
def get_vcs_branches(self, plan_key, max_results=25):
"""
Get all vcs names for the current plan
:param plan_key: str TST-BLD
:param max_results
:return:
"""
resource = "plan/{plan_key}/vcsBranches".format(plan_key=plan_key)
return self.base_list_call(
resource,
start_index=0,
max_results=max_results,
clover_enabled=None,
expand=None,
favourite=None,
)
""" Build results """
def results(
self,
project_key=None,
plan_key=None,
job_key=None,
build_number=None,
expand=None,
favourite=False,
clover_enabled=False,
issue_key=None,
label=None,
start_index=0,
max_results=25,
include_all_states=False,
):
"""
Get results as generic method
:param project_key:
:param plan_key:
:param job_key:
:param build_number:
:param expand:
:param favourite:
:param clover_enabled:
:param issue_key:
:param label:
:param start_index:
:param max_results:
:param include_all_states:
:return:
"""
resource = "result"
if project_key and plan_key and job_key and build_number:
resource += "/{}-{}-{}/{}".format(project_key, plan_key, job_key, build_number)
elif project_key and plan_key and build_number:
resource += "/{}-{}/{}".format(project_key, plan_key, build_number)
elif project_key and plan_key:
resource += "/{}-{}".format(project_key, plan_key)
elif project_key:
resource += "/" + project_key
params = {}
if issue_key:
params["issueKey"] = issue_key
if include_all_states:
params["includeAllStates"] = include_all_states
return self.base_list_call(
resource,
expand=expand,
favourite=favourite,
clover_enabled=clover_enabled,
start_index=start_index,
max_results=max_results,
elements_key="results",
element_key="result",
label=label,
**params
) # fmt: skip
def latest_results(
self,
expand=None,
favourite=False,
clover_enabled=False,
label=None,
issue_key=None,
start_index=0,
max_results=25,
include_all_states=False,
):
"""
Get the latest Results
:param expand:
:param favourite:
:param clover_enabled:
:param label:
:param issue_key:
:param start_index:
:param max_results:
:param include_all_states:
:return:
"""
return self.results(
expand=expand,
favourite=favourite,
clover_enabled=clover_enabled,
label=label,
issue_key=issue_key,
start_index=start_index,
max_results=max_results,
include_all_states=include_all_states,
)
def project_latest_results(
self,
project_key,
expand=None,
favourite=False,
clover_enabled=False,
label=None,
issue_key=None,
start_index=0,
max_results=25,
include_all_states=False,
):
"""
Get the latest Project Results
:param project_key:
:param expand:
:param favourite:
:param clover_enabled:
:param label:
:param issue_key:
:param start_index:
:param max_results:
:param include_all_states:
:return:
"""
return self.results(
project_key,
expand=expand,
favourite=favourite,
clover_enabled=clover_enabled,
label=label,
issue_key=issue_key,
start_index=start_index,
max_results=max_results,
include_all_states=include_all_states,
)
def plan_results(
self,
project_key,
plan_key,
expand=None,
favourite=False,
clover_enabled=False,
label=None,
issue_key=None,
start_index=0,
max_results=25,
include_all_states=False,
):
"""
Get Plan results
:param project_key:
:param plan_key:
:param expand:
:param favourite:
:param clover_enabled:
:param label:
:param issue_key:
:param start_index:
:param max_results:
:param include_all_states:
:return:
"""
return self.results(
project_key,
plan_key,
expand=expand,
favourite=favourite,
clover_enabled=clover_enabled,
label=label,
issue_key=issue_key,
start_index=start_index,
max_results=max_results,
include_all_states=include_all_states,
)
def build_result(
self,
build_key,
expand=None,
include_all_states=False,
start=0,
max_results=25,
):
"""
Returns details of a specific build result
:param expand: expands build result details on request. Possible values are: artifacts, comments, labels,
Jira Issues, stages. stages expand is available only for top level plans. It allows to drill down to job results
using stages.stage.results.result. All expand parameters should contain results. Result prefix.
:param build_key: Should be in the form XX-YY[-ZZ]-99, that is, the last token should be an integer representing
the build number
:param include_all_states
:param start:
:param max_results:
"""
try:
int(build_key.split("-")[-1])
resource = "result/{}".format(build_key)
return self.base_list_call(
resource,
expand,
favourite=False,
clover_enabled=False,
start_index=start,
max_results=max_results,
include_all_states=include_all_states,
)
except ValueError:
raise ValueError('The key "{}" does not correspond to a build result'.format(build_key))
def build_latest_result(self, plan_key, expand=None, include_all_states=False):
"""
Returns details of the latest build result
:param expand: expands build result details on request. Possible values are: artifacts, comments, labels,
Jira Issues, stages. stages expand is available only for top level plans. It allows to drill down to job results
using stages.stage.results.result. All expand parameters should contain results. Result prefix.
:param plan_key: Should be in the form XX-YY[-ZZ]
:param include_all_states:
"""
try:
resource = "result/{}/latest.json".format(plan_key)
return self.base_list_call(
resource,
expand,
favourite=False,
clover_enabled=False,
start_index=0,
max_results=25,
include_all_states=include_all_states,
)
except ValueError:
raise ValueError('The key "{}" does not correspond to the latest build result'.format(plan_key))
def delete_build_result(self, build_key):
"""
Deleting result for specific build
:param build_key: Take full build key, example: PROJECT-PLAN-8
"""
custom_resource = "/build/admin/deletePlanResults.action"
build_key = build_key.split("-")
plan_key = "{}-{}".format(build_key[0], build_key[1])
build_number = build_key[2]
params = {"buildKey": plan_key, "buildNumber": build_number}
return self.post(custom_resource, params=params, headers=self.form_token_headers)
def execute_build(
self,
plan_key,
stage=None,
execute_all_stages=True,
custom_revision=None,
**bamboo_variables
): # fmt: skip
"""
Fire build execution for specified plan.
!IMPORTANT! NOTE: for some reason, this method always execute all stages
:param plan_key: str TST-BLD
:param stage: str stage-name
:param execute_all_stages: bool
:param custom_revision: str revisionName
:param bamboo_variables: dict {variable=value}
:return: POST request
"""
resource = "queue/{plan_key}".format(plan_key=plan_key)
params = {}
if stage:
execute_all_stages = False
params["stage"] = stage
if custom_revision:
params["customRevision"] = custom_revision
params["executeAllStages"] = "true" if execute_all_stages else "false"
if bamboo_variables:
for key, value in bamboo_variables.items():
params["bamboo.variable.{}".format(key)] = value
return self.post(self.resource_url(resource), params=params)
def stop_build(self, plan_key):
"""
Stop the build which is in progress at the moment.
:param plan_key: str TST-BLD
:return: GET request
"""
resource = "/build/admin/stopPlan.action?planKey={}".format(plan_key)
return self.post(path=resource, headers=self.no_check_headers)
""" Comments & Labels """
def comments(
self,
project_key,
plan_key,
build_number,
start_index=0,
max_results=25,
):
resource = "result/{}-{}-{}/comment".format(project_key, plan_key, build_number)
params = {"start-index": start_index, "max-results": max_results}
return self.get(self.resource_url(resource), params=params)
def create_comment(self, project_key, plan_key, build_number, comment, author=None):
resource = "result/{}-{}-{}/comment".format(project_key, plan_key, build_number)
comment_data = {
"author": author if author else self.username,
"content": comment,
}
return self.post(self.resource_url(resource), data=comment_data)
def labels(
self,
project_key,
plan_key,
build_number,
start_index=0,
max_results=25,
):
resource = "result/{}-{}-{}/label".format(project_key, plan_key, build_number)
params = {"start-index": start_index, "max-results": max_results}
return self.get(self.resource_url(resource), params=params)
def create_label(self, project_key, plan_key, build_number, label):
resource = "result/{}-{}-{}/label".format(project_key, plan_key, build_number)
return self.post(self.resource_url(resource), data={"name": label})
def delete_label(self, project_key, plan_key, build_number, label):
resource = "result/{}-{}-{}/label/{}".format(project_key, plan_key, build_number, label)
return self.delete(self.resource_url(resource))
def get_projects(self):
"""Method used to list all projects defined in Bamboo.
Projects without any plan are not listed."""
start_idx = 0
max_results = 25
while True:
resource = "project?start-index={}&max-result={}".format(start_idx, max_results)
r = self.get(self.resource_url(resource))
if r is None:
break
if start_idx > r["projects"]["size"]:
break
start_idx += max_results
for project in r["projects"]["project"]:
yield project
def get_project(self, project_key):
"""Method used to retrieve information for project specified as project key.
Possible expand parameters: plans, list of plans for project. plans.plan, list of plans with plan details
(only plans visible - READ permission for user)"""
resource = "project/{}?showEmpty".format(project_key)
return self.get(self.resource_url(resource))
def delete_project(self, project_key):
"""Marks project for deletion. Project will be deleted by a batch job."""
resource = "project/{}".format(project_key)
return self.delete(self.resource_url(resource))
""" Deployments """
def deployment_projects(self):
resource = "deploy/project/all"
for project in self.get(self.resource_url(resource)):
yield project
def deployment_project(self, project_id):
resource = "deploy/project/{}".format(project_id)
return self.get(self.resource_url(resource))
def delete_deployment_project(self, project_id):
resource = "deploy/project/{}".format(project_id)
return self.delete(self.resource_url(resource))
def deployment_environment_results(self, env_id, expand=None, max_results=25):
resource = "deploy/environment/{environmentId}/results".format(environmentId=env_id)
params = {"max-result": max_results, "start-index": 0}
size = 1
if expand:
params["expand"] = expand
while params["start-index"] < size:
results = self.get(self.resource_url(resource), params=params)
size = results["size"]
for r in results["results"]:
yield r
params["start-index"] += results["max-result"]
def deployment_dashboard(self, project_id=None):
"""
Returns the current status of each deployment environment
If no project id is provided, returns all projects.
"""
resource = "deploy/dashboard/{}".format(project_id) if project_id else "deploy/dashboard"
return self.get(self.resource_url(resource))
def get_deployment_projects_for_plan(self, plan_key):
"""
Returns deployment projects associated with a build plan.
:param plan_key: The key of the plan.
"""
resource = "deploy/project/forPlan"
params = {"planKey": plan_key}
for deployment_project in self.get(self.resource_url(resource), params=params):
yield deployment_project
def trigger_deployment_for_version_on_environment(self, version_id, environment_id):
"""
Triggers a deployment for a release version on the given environment.
Example: trigger_deployment_for_version_on_environment(version_id='3702785', environment_id='3637249')
:param version_id: str or int id of the release version.
:param environment_id: str or int id of the deployment environment.
:return:
"""
resource = "queue/deployment"
params = {"versionId": version_id, "environmentId": environment_id}
return self.post(self.resource_url(resource), params=params)
""" Users & Groups """
def get_users_in_global_permissions(self, start=0, limit=25):
"""
Provide users in global permissions configuration
:param start:
:param limit:
:return:
"""
params = {"limit": limit, "start": start}
url = "rest/api/latest/permissions/global/users"
return self.get(url, params=params)
def get_groups(self, start=0, limit=25):
"""
Retrieve a paginated list of groups.
The authenticated user must have restricted administrative permission or higher to use this resource.
:param start:
:param limit:
:return:
"""
params = {"limit": limit, "start": start}
url = "rest/api/latest/admin/groups"
return self.get(url, params=params)
def create_group(self, group_name):
"""
Create a new group.
The authenticated user must have restricted administrative permission or higher to use this resource.
:param group_name:
:return:
"""
url = "rest/api/latest/admin/groups"
data = {"name": group_name}
return self.post(url, data=data)
def delete_group(self, group_name):
"""
Deletes the specified group, removing it from the system.
The authenticated user must have restricted administrative permission or higher to use this resource.
:param group_name:
:return:
"""
url = "rest/api/latest/admin/groups/{}".format(group_name)
return self.delete(url)
def add_users_into_group(self, group_name, users):
"""
Add multiple users to a group.
The list of usernames should be passed as request body.
The authenticated user must have restricted administrative permission or higher to use this resource.
:param group_name:
:param users: list
:return:
"""
url = "rest/api/latest/admin/groups/{}/add-users".format(group_name)
return self.post(url, data=users)
def remove_users_from_group(self, group_name, users):
"""
Remove multiple users from a group.
The list of usernames should be passed as request body.
The authenticated user must have restricted administrative permission or higher to use this resource.
:param group_name:
:param users: list
:return:
"""
url = "rest/api/latest/admin/groups/{}/remove-users".format(group_name)
return self.delete(url, data=users)
def get_users_from_group(self, group_name, filter_users=None, start=0, limit=25):
"""
Retrieves a list of users that are members of a specified group.
The authenticated user must have restricted administrative permission or higher to use this resource.
:param filter_users:
:param group_name:
:param start:
:param limit:
:return:
"""
params = {"limit": limit, "start": start}
if filter_users:
params = {"filter": filter_users}
url = "rest/api/latest/admin/groups/{}/more-members".format(group_name)
return self.get(url, params=params)
def get_users_not_in_group(self, group_name, filter_users="", start=0, limit=25):
"""
Retrieves a list of users that are not members of a specified group.
The authenticated user must have restricted administrative permission or higher to use this resource.
:param filter_users:
:param group_name:
:param start:
:param limit:
:return:
"""
params = {"limit": limit, "start": start}
if filter_users:
params = {"filter": filter_users}
url = "rest/api/latest/admin/groups/{}/more-non-members".format(group_name)
return self.get(url, params=params)
def get_build_queue(self, expand="queuedBuilds"):
"""
Lists all the builds waiting in the build queue, adds or removes a build from the build queue.
May be used also to resume build on manual stage or rerun failed jobs.
:return:
"""
params = {"expand": expand}
return self.get("rest/api/latest/queue", params=params)
def get_deployment_queue(self, expand="queuedDeployments"):
"""
Provide list of deployment results scheduled for execution and waiting in queue.
:return:
"""
params = {"expand": expand}
return self.get("rest/api/latest/queue/deployment", params=params)
def get_deployment_users(self, deployment_id, filter_name=None, start=0, limit=25):
"""
Retrieve a list of users with their explicit permissions to given resource.
The list can be filtered by some attributes.
This resource is paged and returns a single page of results.
:param deployment_id:
:param filter_name:
:param start:
:param limit:
:return:
"""
params = {"limit": limit, "start": start}
if filter_name:
params = {"name": filter_name}
resource = "permissions/deployment/{}/users".format(deployment_id)
return self.get(self.resource_url(resource), params=params)
def revoke_user_from_deployment(self, deployment_id, user, permissions=["READ", "WRITE", "BUILD"]):
"""
Revokes deployment project permissions from a given user.
:param deployment_id:
:param user:
:param permissions:
:return:
"""
resource = "permissions/deployment/{}/users/{}".format(deployment_id, user)
return self.delete(self.resource_url(resource), data=permissions)
def grant_user_to_deployment(self, deployment_id, user, permissions):
"""
Grants deployment project permissions to a given user.
:param deployment_id:
:param user:
:param permissions:
:return:
"""
resource = "permissions/deployment/{}/users/{}".format(deployment_id, user)
return self.put(self.resource_url(resource), data=permissions)
def get_deployment_groups(self, deployment_id, filter_name=None, start=0, limit=25):
"""
Retrieve a list of groups with their deployment project permissions.
The list can be filtered by some attributes.
This resource is paged returns a single page of results.
:param deployment_id:
:param filter_name:
:param start:
:param limit:
:return:
"""
params = {"limit": limit, "start": start}
if filter_name:
params = {"name": filter_name}
resource = "permissions/deployment/{}/groups".format(deployment_id)
return self.get(self.resource_url(resource), params=params)
def revoke_group_from_deployment(self, deployment_id, group, permissions=["READ", "WRITE", "BUILD"]):
"""
Revokes deployment project permissions from a given group.
:param deployment_id:
:param group:
:param permissions:
:return:
"""
resource = "permissions/deployment/{}/groups/{}".format(deployment_id, group)
return self.delete(self.resource_url(resource), data=permissions)
def grant_group_to_deployment(self, deployment_id, group, permissions):
"""
Grants deployment project permissions to a given group.
:param deployment_id:
:param group:
:param permissions:
:return:
"""
resource = "permissions/deployment/{}/groups/{}".format(deployment_id, group)
return self.put(self.resource_url(resource), data=permissions)
def get_environment_users(self, environment_id, filter_name=None, start=0, limit=25):
"""
Retrieve a list of users with their explicit permissions to given resource.
The list can be filtered by some attributes.
This resource is paged and returns a single page of results.
:param environment_id:
:param filter_name:
:param start:
:param limit:
:return:
"""
params = {"limit": limit, "start": start}
if filter_name:
params = {"name": filter_name}
resource = "permissions/environment/{}/users".format(environment_id)
return self.get(self.resource_url(resource), params=params)
def revoke_user_from_environment(self, environment_id, user, permissions=["READ", "WRITE", "BUILD"]):
"""
Revokes deployment environment permissions from a given user.
:param environment_id:
:param user:
:param permissions:
:return:
"""
resource = "permissions/environment/{}/users/{}".format(environment_id, user)
return self.delete(self.resource_url(resource), data=permissions)
def grant_user_to_environment(self, environment_id, user, permissions):
"""
Grants deployment environment permissions to a given user.
:param environment_id:
:param user:
:param permissions:
:return:
"""
resource = "permissions/environment/{}/users/{}".format(environment_id, user)
return self.put(self.resource_url(resource), data=permissions)
def get_environment_groups(self, environment_id, filter_name=None, start=0, limit=25):
"""
Retrieve a list of groups with their deployment environment permissions.
The list can be filtered by some attributes.
This resource is paged returns a single page of results.
:param environment_id:
:param filter_name:
:param start:
:param limit:
:return:
"""
params = {"limit": limit, "start": start}
if filter_name:
params = {"name": filter_name}
resource = "permissions/environment/{}/groups".format(environment_id)
return self.get(self.resource_url(resource), params=params)
def revoke_group_from_environment(self, environment_id, group, permissions=["READ", "WRITE", "BUILD"]):
"""
Revokes deployment environment permissions from a given group.