-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathapi.py
executable file
·1491 lines (1187 loc) · 49.3 KB
/
api.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
"""
This module provides python bindings for the Firecloud API.
For more details see https://software.broadinstitute.org/firecloud/
To see how the python bindings map to the RESTful endpoints view
the README at https://pypi.python.org/pypi/firecloud.
"""
from __future__ import print_function
import json
import sys
import os
import io
import logging
import subprocess
from collections import Iterable
from six.moves.urllib.parse import urlencode, urljoin
from six import string_types
import google.auth
from google.auth.exceptions import DefaultCredentialsError, RefreshError
from google.auth.transport.requests import AuthorizedSession, Request
from google.oauth2 import id_token
from firecloud.errors import FireCloudServerError
from firecloud.fccore import __fcconfig as fcconfig
from firecloud.__about__ import __version__
FISS_USER_AGENT = "FISS/" + __version__
# Set Global Authorized Session
__SESSION = None
__USER_ID = None
# Suppress warnings about project ID
logging.getLogger('google.auth').setLevel(logging.ERROR)
#################################################
# Utilities
#################################################
def _set_session():
""" Sets global __SESSION and __USER_ID if they haven't been set """
global __SESSION
global __USER_ID
if __SESSION is None:
try:
__SESSION = AuthorizedSession(google.auth.default(['https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'])[0])
health()
__USER_ID = id_token.verify_oauth2_token(__SESSION.credentials.id_token,
Request(session=__SESSION))['email']
except AttributeError:
__USER_ID = __SESSION.credentials.service_account_email
except (DefaultCredentialsError, RefreshError) as gae:
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
raise
logging.warning("Unable to determine/refresh application credentials")
try:
subprocess.check_call(['gcloud', 'auth', 'application-default',
'login', '--no-launch-browser'])
__SESSION = AuthorizedSession(google.auth.default(['https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'])[0])
except subprocess.CalledProcessError as cpe:
if cpe.returncode < 0:
logging.exception("%s was terminated by signal %d",
cpe.cmd, -cpe.returncode)
else:
logging.exception("%s returned %d", cpe.cmd,
cpe.returncode)
raise gae
def _fiss_agent_header(headers=None):
""" Return request headers for fiss.
Inserts FISS as the User-Agent.
Initializes __SESSION if it hasn't been set.
Args:
headers (dict): Include additional headers as key-value pairs
"""
_set_session()
fiss_headers = {"User-Agent" : FISS_USER_AGENT}
if headers is not None:
fiss_headers.update(headers)
return fiss_headers
def __get(methcall, headers=None, root_url=None, **kwargs):
if not headers:
headers = _fiss_agent_header()
if root_url is None:
root_url = fcconfig.root_url
r = __SESSION.get(urljoin(root_url, methcall), headers=headers, **kwargs)
if fcconfig.verbosity > 1:
print('FISSFC call: %s' % r.url, file=sys.stderr)
return r
def __post(methcall, headers=None, root_url=None, **kwargs):
if not headers:
headers = _fiss_agent_header({"Content-type": "application/json"})
if root_url is None:
root_url = fcconfig.root_url
r = __SESSION.post(urljoin(root_url, methcall), headers=headers, **kwargs)
if fcconfig.verbosity > 1:
info = r.url
json = kwargs.get("json", None)
if json:
info += " \n(json=%s) " % json
print('FISSFC call: POST %s' % info, file=sys.stderr)
return r
def __put(methcall, headers=None, root_url=None, **kwargs):
if not headers:
headers = _fiss_agent_header()
if root_url is None:
root_url = fcconfig.root_url
r = __SESSION.put(urljoin(root_url, methcall), headers=headers, **kwargs)
if fcconfig.verbosity > 1:
info = r.url
json = kwargs.get("json", None)
if json:
info += " \n(json=%s) " % json
print('FISSFC call: PUT %s' % info, file=sys.stderr)
return r
def __delete(methcall, headers=None, root_url=None):
if not headers:
headers = _fiss_agent_header()
if root_url is None:
root_url = fcconfig.root_url
r = __SESSION.delete(urljoin(root_url, methcall), headers=headers)
if fcconfig.verbosity > 1:
print('FISSFC call: DELETE %s' % r.url, file=sys.stderr)
return r
def _check_response_code(response, codes):
"""
Throws an exception if the http response is not expected. Can check single
integer or list of valid responses.
Example usage:
>>> r = api.get_workspace("broad-firecloud-testing", "Fake-Bucket")
>>> _check_response_code(r, 200)
... FireCloudServerError ...
"""
if type(codes) == int:
codes = [codes]
if response.status_code not in codes:
raise FireCloudServerError(response.status_code, response.content)
def whoami():
""" Return __USER_ID """
_set_session()
return __USER_ID
##############################################################
# 1. Orchestration API calls, see https://api.firecloud.org/
##############################################################
##################
### 1.1 Entities
##################
def get_entities_with_type(namespace, workspace):
"""List entities in a workspace.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
Swagger:
https://api.firecloud.org/#!/Entities/getEntitiesWithType
"""
uri = "workspaces/{0}/{1}/entities_with_type".format(namespace, workspace)
return __get(uri)
def list_entity_types(namespace, workspace):
"""List the entity types present in a workspace.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
Swagger:
https://api.firecloud.org/#!/Entities/getEntityTypes
"""
headers = _fiss_agent_header({"Content-type": "application/json"})
uri = "workspaces/{0}/{1}/entities".format(namespace, workspace)
return __get(uri, headers=headers)
def upload_entities(namespace, workspace, entity_data, model='firecloud'):
"""Upload entities from tab-delimited string.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
entity_data (str): TSV string describing entites
model (str): Data Model type. "firecloud" (default) or "flexible"
Swagger:
https://api.firecloud.org/#!/Entities/importEntities
https://api.firecloud.org/#!/Entities/flexibleImportEntities
"""
body = urlencode({"entities" : entity_data})
headers = _fiss_agent_header({
'Content-type': "application/x-www-form-urlencoded"
})
endpoint = 'importEntities'
if model == 'flexible':
endpoint = 'flexibleImportEntities'
uri = "workspaces/{0}/{1}/{2}".format(namespace, workspace, endpoint)
return __post(uri, headers=headers, data=body)
def upload_entities_tsv(namespace, workspace, entities_tsv, model='firecloud'):
"""Upload entities from a tsv loadfile.
File-based wrapper for api.upload_entities().
A loadfile is a tab-separated text file with a header row
describing entity type and attribute names, followed by
rows of entities and their attribute values.
Ex:
entity:participant_id age alive
participant_23 25 Y
participant_27 35 N
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
entities_tsv (file): FireCloud loadfile, see format above
model (str): Data Model type. "firecloud" (default) or "flexible"
"""
if isinstance(entities_tsv, string_types):
with open(entities_tsv, "r") as tsv:
entity_data = tsv.read()
elif isinstance(entities_tsv, io.StringIO):
entity_data = entities_tsv.getvalue()
else:
raise ValueError('Unsupported input type.')
return upload_entities(namespace, workspace, entity_data, model)
def copy_entities(from_namespace, from_workspace, to_namespace,
to_workspace, etype, enames, link_existing_entities=False):
"""Copy entities between workspaces
Args:
from_namespace (str): project (namespace) to which source workspace belongs
from_workspace (str): Source workspace name
to_namespace (str): project (namespace) to which target workspace belongs
to_workspace (str): Target workspace name
etype (str): Entity type
enames (list(str)): List of entity names to copy
link_existing_entities (boolean): Link all soft conflicts to the entities that already exist.
Swagger:
https://api.firecloud.org/#!/Entities/copyEntities
"""
uri = "workspaces/{0}/{1}/entities/copy".format(to_namespace, to_workspace)
body = {
"sourceWorkspace": {
"namespace": from_namespace,
"name": from_workspace
},
"entityType": etype,
"entityNames": enames
}
return __post(uri, json=body, params={'linkExistingEntities':
str(link_existing_entities).lower()})
def get_entities(namespace, workspace, etype):
"""List entities of given type in a workspace.
Response content will be in JSON format.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
etype (str): Entity type
Swagger:
https://api.firecloud.org/#!/Entities/getEntities
"""
uri = "workspaces/{0}/{1}/entities/{2}".format(namespace, workspace, etype)
return __get(uri)
def get_entities_tsv(namespace, workspace, etype, attrs=None, model="firecloud"):
"""List entities of given type in a workspace as a TSV.
Similar to get_entities(), but the response is a TSV.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
etype (str): Entity type
attrs (list): list of ordered attribute names to be in downloaded tsv
model (str): Data Model type. "firecloud" (default) or "flexible"
Swagger:
https://api.firecloud.org/#!/Entities/downloadEntitiesTSV
"""
params = {'model': model}
if attrs is not None:
params['attributeNames'] = ','.join(attrs)
uri = "workspaces/{0}/{1}/entities/{2}/tsv".format(namespace,
workspace, etype)
return __get(uri, params=params)
def get_entity(namespace, workspace, etype, ename):
"""Request entity information.
Gets entity metadata and attributes.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
etype (str): Entity type
ename (str): The entity's unique id
Swagger:
https://api.firecloud.org/#!/Entities/getEntity
"""
uri = "workspaces/{0}/{1}/entities/{2}/{3}".format(namespace,
workspace, etype, ename)
return __get(uri)
def delete_entities(namespace, workspace, json_body):
"""Delete entities in a workspace.
Note: This action is not reversible. Be careful!
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
json_body:
[
{
"entityType": "string",
"entityName": "string"
}
]
Swagger:
https://api.firecloud.org/#!/Entities/deleteEntities
"""
uri = "workspaces/{0}/{1}/entities/delete".format(namespace, workspace)
return __post(uri, json=json_body)
def delete_entity_type(namespace, workspace, etype, ename):
"""Delete entities in a workspace.
Note: This action is not reversible. Be careful!
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
etype (str): Entity type
ename (str, or iterable of str): unique entity id(s)
Swagger:
https://api.firecloud.org/#!/Entities/deleteEntities
"""
uri = "workspaces/{0}/{1}/entities/delete".format(namespace, workspace)
if isinstance(ename, string_types):
body = [{"entityType":etype, "entityName":ename}]
elif isinstance(ename, Iterable):
body = [{"entityType":etype, "entityName":i} for i in ename]
return __post(uri, json=body)
def delete_participant(namespace, workspace, name):
"""Delete participant in a workspace.
Convenience wrapper for api.delete_entity().
Note: This action is not reversible. Be careful!
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
name (str, or iterable of str): participant_id(s)
"""
return delete_entity_type(namespace, workspace, "participant", name)
def delete_participant_set(namespace, workspace, name):
"""Delete participant set in a workspace.
Convenience wrapper for api.delete_entity().
Note: This action is not reversible. Be careful!
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
name (str, or iterable of str): participant_set_id(s)
"""
return delete_entity_type(namespace, workspace, "participant_set", name)
def delete_sample(namespace, workspace, name):
"""Delete sample in a workspace.
Convenience wrapper for api.delete_entity().
Note: This action is not reversible. Be careful!
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
name (str, or iterable of str): sample_id(s)
"""
return delete_entity_type(namespace, workspace, "sample", name)
def delete_sample_set(namespace, workspace, name):
"""Delete sample set in a workspace.
Convenience wrapper for api.delete_entity().
Note: This action is not reversible. Be careful!
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
name (str, or iterable of str): sample_set_id(s)
"""
return delete_entity_type(namespace, workspace, "sample_set", name)
def delete_pair(namespace, workspace, name):
"""Delete pair in a workspace.
Convenience wrapper for api.delete_entity().
Note: This action is not reversible. Be careful!
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
name (str, or iterable of str): pair_id(s)
"""
return delete_entity_type(namespace, workspace, "pair", name)
def delete_pair_set(namespace, workspace, name):
"""Delete pair set in a workspace.
Convenience wrapper for api.delete_entity().
Note: This action is not reversible. Be careful!
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
name (str, or iterable of str): pair_set_id(s)
"""
return delete_entity_type(namespace, workspace, "pair_set", name)
def get_entities_query(namespace, workspace, etype, page=1,
page_size=100, sort_direction="asc",
filter_terms=None):
"""Paginated version of get_entities_with_type.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
Swagger:
https://api.firecloud.org/#!/Entities/entityQuery
"""
# Initial parameters for pagination
params = {
"page" : page,
"pageSize" : page_size,
"sortDirection" : sort_direction
}
if filter_terms:
params['filterTerms'] = filter_terms
uri = "workspaces/{0}/{1}/entityQuery/{2}".format(namespace,workspace,etype)
return __get(uri, params=params)
def update_entity(namespace, workspace, etype, ename, updates):
""" Update entity attributes in a workspace.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
etype (str): Entity type
ename (str): Entity name
updates (list(dict)): List of updates to entity from _attr_set, e.g.
Swagger:
https://api.firecloud.org/#!/Entities/update_entity
"""
headers = _fiss_agent_header({"Content-type": "application/json"})
uri = "{0}workspaces/{1}/{2}/entities/{3}/{4}".format(fcconfig.root_url,
namespace, workspace, etype, ename)
# FIXME: create __patch method, akin to __get, __delete etc
return __SESSION.patch(uri, headers=headers, json=updates)
###############################
### 1.2 Method Configurations
###############################
def list_workspace_configs(namespace, workspace, allRepos=False):
"""List method configurations in workspace.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
Swagger:
https://api.firecloud.org/#!/Method_Configurations/listWorkspaceMethodConfigs
DUPLICATE: https://api.firecloud.org/#!/Workspaces/listWorkspaceMethodConfigs
"""
uri = "workspaces/{0}/{1}/methodconfigs".format(namespace, workspace)
return __get(uri, params={'allRepos': allRepos})
def create_workspace_config(namespace, workspace, body):
"""Create method configuration in workspace.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
body (json) : a filled-in JSON object for the new method config
(e.g. see return value of get_workspace_config)
Swagger:
https://api.firecloud.org/#!/Method_Configurations/postWorkspaceMethodConfig
DUPLICATE: https://api.firecloud.org/#!/Workspaces/postWorkspaceMethodConfig
"""
#json_body = {
# "namespace" : mnamespace,
# "name" : method,
# "rootEntityType" : root_etype,
# "inputs" : {},
# "outputs" : {},
# "prerequisites" : {}
#}
uri = "workspaces/{0}/{1}/methodconfigs".format(namespace, workspace)
return __post(uri, json=body)
def delete_workspace_config(namespace, workspace, cnamespace, config):
"""Delete method configuration in workspace.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
mnamespace (str): Method namespace
method (str): Method name
Swagger:
https://api.firecloud.org/#!/Method_Configurations/deleteWorkspaceMethodConfig
"""
uri = "workspaces/{0}/{1}/method_configs/{2}/{3}".format(namespace,
workspace, cnamespace, config)
return __delete(uri)
def get_workspace_config(namespace, workspace, cnamespace, config):
"""Get method configuration in workspace.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
cnamespace (str): Config namespace
config (str): Config name
Swagger:
https://api.firecloud.org/#!/Method_Configurations/getWorkspaceMethodConfig
"""
uri = "workspaces/{0}/{1}/method_configs/{2}/{3}".format(namespace,
workspace, cnamespace, config)
return __get(uri)
def overwrite_workspace_config(namespace, workspace, cnamespace, configname, body):
"""Add or overwrite method configuration in workspace.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
cnamespace (str): Configuration namespace
configname (str): Configuration name
body (json): new body (definition) of the method config
Swagger:
https://api.firecloud.org/#!/Method_Configurations/overwriteWorkspaceMethodConfig
"""
headers = _fiss_agent_header({"Content-type": "application/json"})
uri = "workspaces/{0}/{1}/method_configs/{2}/{3}".format(namespace,
workspace, cnamespace, configname)
return __put(uri, headers=headers, json=body)
def update_workspace_config(namespace, workspace, cnamespace, configname, body):
"""Update method configuration in workspace.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
cnamespace (str): Configuration namespace
configname (str): Configuration name
body (json): new body (definition) of the method config
Swagger:
https://api.firecloud.org/#!/Method_Configurations/updateWorkspaceMethodConfig
"""
uri = "workspaces/{0}/{1}/method_configs/{2}/{3}".format(namespace,
workspace, cnamespace, configname)
return __post(uri, json=body)
def validate_config(namespace, workspace, cnamespace, config):
"""Get syntax validation for a configuration.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
cnamespace (str): Configuration namespace
config (str): Configuration name
Swagger:
https://api.firecloud.org/#!/Method_Configurations/validate_method_configuration
"""
uri = "workspaces/{0}/{1}/method_configs/{2}/{3}/validate".format(namespace,
workspace, cnamespace, config)
return __get(uri)
def rename_workspace_config(namespace, workspace, cnamespace, config,
new_namespace, new_name):
"""Rename a method configuration in a workspace.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
mnamespace (str): Config namespace
config (str): Config name
new_namespace (str): Updated config namespace
new_name (str): Updated method name
Swagger:
https://api.firecloud.org/#!/Method_Configurations/renameWorkspaceMethodConfig
"""
body = {
"namespace" : new_namespace,
"name" : new_name,
# I have no idea why this is required by FC, but it is...
"workspaceName" : {
"namespace" : namespace,
"name" : workspace
}
}
uri = "workspaces/{0}/{1}/method_configs/{2}/{3}/rename".format(namespace,
workspace, cnamespace, config)
return __post(uri, json=body)
def copy_config_from_repo(namespace, workspace, from_cnamespace,
from_config, from_snapshot_id, to_cnamespace,
to_config):
"""Copy a method config from the methods repository to a workspace.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
from_cnamespace (str): Source configuration namespace
from_config (str): Source configuration name
from_snapshot_id (int): Source configuration snapshot_id
to_cnamespace (str): Target configuration namespace
to_config (str): Target configuration name
Swagger:
https://api.firecloud.org/#!/Method_Configurations/copyFromMethodRepo
DUPLICATE: https://api.firecloud.org/#!/Method_Repository/copyFromMethodRepo
"""
body = {
"configurationNamespace" : from_cnamespace,
"configurationName" : from_config,
"configurationSnapshotId" : from_snapshot_id,
"destinationNamespace" : to_cnamespace,
"destinationName" : to_config
}
uri = "workspaces/{0}/{1}/method_configs/copyFromMethodRepo".format(
namespace, workspace)
return __post(uri, json=body)
def copy_config_to_repo(namespace, workspace, from_cnamespace,
from_config, to_cnamespace, to_config):
"""Copy a method config from a workspace to the methods repository.
Args:
namespace (str): project to which workspace belongs
workspace (str): Workspace name
from_cnamespace (str): Source configuration namespace
from_config (str): Source configuration name
to_cnamespace (str): Target configuration namespace
to_config (str): Target configuration name
Swagger:
https://api.firecloud.org/#!/Method_Configurations/copyToMethodRepo
DUPLICATE: https://api.firecloud.org/#!/Method_Repository/copyToMethodRepo
"""
body = {
"configurationNamespace" : to_cnamespace,
"configurationName" : to_config,
"sourceNamespace" : from_cnamespace,
"sourceName" : from_config
}
uri = "workspaces/{0}/{1}/method_configs/copyToMethodRepo".format(
namespace, workspace)
return __post(uri, json=body)
###########################
### 1.3 Method Repository
###########################
def list_repository_methods(namespace=None, name=None, snapshotId=None):
"""List method(s) in the methods repository.
Args:
namespace (str): Method Repository namespace
name (str): method name
snapshotId (int): method snapshot ID
Swagger:
https://api.firecloud.org/#!/Method_Repository/listMethodRepositoryMethods
"""
params = {k:v for (k,v) in locals().items() if v is not None}
return __get("methods", params=params)
def list_repository_configs(namespace=None, name=None, snapshotId=None):
"""List configurations in the methods repository.
Args:
namespace (str): Method Repository namespace
name (str): config name
snapshotId (int): config snapshot ID
Swagger:
https://api.firecloud.org/#!/Method_Repository/listMethodRepositoryConfigurations
"""
params = {k:v for (k,v) in locals().items() if v is not None}
return __get("configurations", params=params)
def get_config_template(namespace, method, version):
"""Get the configuration template for a method.
The method should exist in the methods repository.
Args:
namespace (str): Method's namespace
method (str): method name
version (int): snapshot_id of the method
Swagger:
https://api.firecloud.org/#!/Method_Repository/createMethodTemplate
"""
body = {
"methodNamespace" : namespace,
"methodName" : method,
"methodVersion" : int(version)
}
return __post("template", json=body)
def get_inputs_outputs(namespace, method, snapshot_id):
"""Get a description of the inputs and outputs for a method.
The method should exist in the methods repository.
Args:
namespace (str): Methods namespace
method (str): method name
snapshot_id (int): snapshot_id of the method
Swagger:
https://api.firecloud.org/#!/Method_Repository/getMethodIO
"""
body = {
"methodNamespace" : namespace,
"methodName" : method,
"methodVersion" : snapshot_id
}
return __post("inputsOutputs", json=body)
def get_repository_config(namespace, config, snapshot_id):
"""Get a method configuration from the methods repository.
Args:
namespace (str): Methods namespace
config (str): config name
snapshot_id (int): snapshot_id of the method
Swagger:
https://api.firecloud.org/#!/Method_Repository/getMethodRepositoryConfiguration
"""
uri = "configurations/{0}/{1}/{2}".format(namespace, config, snapshot_id)
return __get(uri)
def get_repository_method(namespace, method, snapshot_id, wdl_only=False):
"""Get a method definition from the method repository.
Args:
namespace (str): Methods namespace
method (str): method name
version (int): snapshot_id of the method
wdl_only (bool): Exclude metadata
Swagger:
https://api.firecloud.org/#!/Method_Repository/get_api_methods_namespace_name_snapshotId
"""
uri = "methods/{0}/{1}/{2}?onlyPayload={3}".format(namespace, method,
snapshot_id,
str(wdl_only).lower())
return __get(uri)
def update_repository_method(namespace, method, synopsis, wdl, doc=None,
comment=""):
"""Create/Update workflow definition.
FireCloud will create a new snapshot_id for the given workflow.
Args:
namespace (str): Methods namespace
method (str): method name
synopsis (str): short (<80 char) description of method
wdl (file): Workflow Description Language file
doc (file): (Optional) Additional documentation
comment (str): (Optional) Comment specific to this snapshot
Swagger:
https://api.firecloud.org/#!/Method_Repository/post_api_methods
"""
with open(wdl, 'r') as wf:
wdl_payload = wf.read()
if doc is not None:
with open (doc, 'r') as df:
doc = df.read()
body = {
"namespace": namespace,
"name": method,
"entityType": "Workflow",
"payload": wdl_payload,
"documentation": doc,
"synopsis": synopsis,
"snapshotComment": comment
}
return __post("methods",
json={key: value for key, value in body.items() if value})
def delete_repository_method(namespace, name, snapshot_id):
"""Redacts a method and all of its associated configurations.
The method should exist in the methods repository.
Args:
namespace (str): Methods namespace
method (str): method name
snapshot_id (int): snapshot_id of the method
Swagger:
https://api.firecloud.org/#!/Method_Repository/delete_api_methods_namespace_name_snapshotId
"""
uri = "methods/{0}/{1}/{2}".format(namespace, name, snapshot_id)
return __delete(uri)
def delete_repository_config(namespace, name, snapshot_id):
"""Redacts a configuration and all of its associated configurations.
The configuration should exist in the methods repository.
Args:
namespace (str): configuration namespace
configuration (str): configuration name
snapshot_id (int): snapshot_id of the configuration
Swagger:
https://api.firecloud.org/#!/Method_Repository/delete_api_configurations_namespace_name_snapshotId
"""
uri = "configurations/{0}/{1}/{2}".format(namespace, name, snapshot_id)
return __delete(uri)
def get_repository_method_acl(namespace, method, snapshot_id):
"""Get permissions for a method.
The method should exist in the methods repository.
Args:
namespace (str): Methods namespace
method (str): method name
version (int): snapshot_id of the method
Swagger:
https://api.firecloud.org/#!/Method_Repository/getMethodACL
"""
uri = "methods/{0}/{1}/{2}/permissions".format(namespace,method,snapshot_id)
return __get(uri)
def update_repository_method_acl(namespace, method, snapshot_id, acl_updates):
"""Set method permissions.
The method should exist in the methods repository.
Args:
namespace (str): Methods namespace
method (str): method name
snapshot_id (int): snapshot_id of the method
acl_updates (list(dict)): List of access control updates
Swagger:
https://api.firecloud.org/#!/Method_Repository/setMethodACL
"""
uri = "methods/{0}/{1}/{2}/permissions".format(namespace,method,snapshot_id)
return __post(uri, json=acl_updates)
def get_repository_config_acl(namespace, config, snapshot_id):
"""Get configuration permissions.
The configuration should exist in the methods repository.
Args:
namespace (str): Configuration namespace
config (str): Configuration name
snapshot_id (int): snapshot_id of the method
Swagger:
https://api.firecloud.org/#!/Method_Repository/getConfigACL
"""
uri = "configurations/{0}/{1}/{2}/permissions".format(namespace,
config, snapshot_id)
return __get(uri)
def update_repository_config_acl(namespace, config, snapshot_id, acl_updates):
"""Set configuration permissions.
The configuration should exist in the methods repository.
Args:
namespace (str): Configuration namespace
config (str): Configuration name
snapshot_id (int): snapshot_id of the method
acl_updates (list(dict)): List of access control updates
Swagger:
https://api.firecloud.org/#!/Method_Repository/setConfigACL
"""
uri = "configurations/{0}/{1}/{2}/permissions".format(namespace,
config, snapshot_id)
return __post(uri, json=acl_updates)
def get_method_configurations(namespace, method_name):
"""Get method configurations.
Given the namespace/name of a method, returns all configurations in
the repository that reference that method.
Args:
namespace (str): Method namespace
method_name (str): Method name
Swagger:
https://api.firecloud.org/#!/Method_Repository/get_api_methods_namespace_name_configurations
"""
uri = "methods/{0}/{1}/configurations".format(namespace, method_name)
return __get(uri)
def get_api_methods_definitions():
"""List method definitions.
List method definitions - i.e. unique namespace/name pairs -
with counts of snapshots and associated configurations
Swagger:
https://api.firecloud.org/#!/Method_Repository/get_api_methods_definitions
"""
uri = "methods/definitions"
return __get(uri)
#################
### 1.4 Profile
#################
def list_billing_projects():
"""Get activation information for the logged-in user.
Swagger: