@@ -438,32 +438,72 @@ def meth_acl(args):
438
438
@fiss_cmd
439
439
def meth_set_acl (args ):
440
440
""" Assign an ACL role to a list of users for a workflow. """
441
- acl_updates = [{"user" : user , "role" : args .role } for user in args .users ]
441
+ acl_updates = [{"user" : user , "role" : args .role } \
442
+ for user in set (expand_fc_groups (args .users )) \
443
+ if user != fapi .whoami ()]
442
444
443
445
id = args .snapshot_id
444
446
if not id :
445
447
# get the latest snapshot_id for this method from the methods repo
446
- r = fapi .list_repository_methods ()
448
+ r = fapi .list_repository_methods (namespace = args .namespace ,
449
+ name = args .method )
447
450
fapi ._check_response_code (r , 200 )
448
- versions = [m for m in r .json ()
449
- if m ['name' ] == args .method and m ['namespace' ] == args .namespace ]
451
+ versions = r .json ()
450
452
if len (versions ) == 0 :
451
453
if fcconfig .verbosity :
452
- eprint ("method {0}/{1} not found" .format (args .namespace , args .method ))
454
+ eprint ("method {0}/{1} not found" .format (args .namespace ,
455
+ args .method ))
453
456
return 1
454
457
latest = sorted (versions , key = lambda m : m ['snapshotId' ])[- 1 ]
455
458
id = latest ['snapshotId' ]
456
459
457
- r = fapi .update_repository_method_acl (args .namespace , args .method , id , acl_updates )
460
+ r = fapi .update_repository_method_acl (args .namespace , args .method , id ,
461
+ acl_updates )
458
462
fapi ._check_response_code (r , 200 )
459
463
if fcconfig .verbosity :
460
- print ("Updated ACL for {0}/{1}:{2}" .format (args .namespace , args .method , id ))
464
+ print ("Updated ACL for {0}/{1}:{2}" .format (args .namespace , args .method ,
465
+ id ))
461
466
return 0
462
467
468
+ def expand_fc_groups (users ):
469
+ """ If user is a firecloud group, return all members of the group.
470
+ Caveat is that only group admins may do this.
471
+ """
472
+ groups = None
473
+ for user in users :
474
+ fcgroup = None
475
+ if '@' not in user :
476
+ fcgroup = user
477
+ elif user .lower ().endswith ('@firecloud.org' ):
478
+ if groups is None :
479
+ r = fapi .get_groups ()
480
+ fapi ._check_response_code (r , 200 )
481
+ groups = {group ['groupEmail' ].lower ():group ['groupName' ] \
482
+ for group in r .json () if group ['role' ] == 'Admin' }
483
+ if user .lower () not in groups :
484
+ if fcconfig .verbosity :
485
+ eprint ("You do not have access to the members of {}" .format (user ))
486
+ yield user
487
+ continue
488
+ else :
489
+ fcgroup = groups [user .lower ()]
490
+ else :
491
+ yield user
492
+ continue
493
+ r = fapi .get_group (fcgroup )
494
+ fapi ._check_response_code (r , 200 )
495
+ fcgroup_data = r .json ()
496
+ for admin in fcgroup_data ['adminsEmails' ]:
497
+ yield admin
498
+ for member in fcgroup_data ['membersEmails' ]:
499
+ yield member
500
+
463
501
@fiss_cmd
464
502
def meth_list (args ):
465
503
""" List workflows in the methods repository """
466
- r = fapi .list_repository_methods (name = args .name )
504
+ r = fapi .list_repository_methods (namespace = args .namespace ,
505
+ name = args .method ,
506
+ snapshotId = args .snapshot_id )
467
507
fapi ._check_response_code (r , 200 )
468
508
469
509
# Parse the JSON for the workspace + namespace
@@ -481,6 +521,8 @@ def meth_list(args):
481
521
@fiss_cmd
482
522
def meth_exists (args ):
483
523
'''Determine whether a given workflow is present in methods repo'''
524
+ args .namespace = None
525
+ args .snapshot_id = None
484
526
return len (meth_list (args )) != 0
485
527
486
528
@fiss_cmd
@@ -519,7 +561,7 @@ def config_stop(args):
519
561
520
562
@fiss_cmd
521
563
def config_list (args ):
522
- """ List configurations in the methods repository or a workspace. """
564
+ """ List configuration(s) in the methods repository or a workspace. """
523
565
verbose = fcconfig .verbosity
524
566
if args .workspace :
525
567
if verbose :
@@ -532,7 +574,9 @@ def config_list(args):
532
574
else :
533
575
if verbose :
534
576
print ("Retrieving method configs from method repository" )
535
- r = fapi .list_repository_configs ()
577
+ r = fapi .list_repository_configs (namespace = args .namespace ,
578
+ name = args .config ,
579
+ snapshotId = args .snapshot_id )
536
580
fapi ._check_response_code (r , 200 )
537
581
538
582
# Parse the JSON for the workspace + namespace
@@ -563,6 +607,36 @@ def config_acl(args):
563
607
acls = sorted (r .json (), key = lambda k : k ['user' ])
564
608
return map (lambda acl : '{0}\t {1}' .format (acl ['user' ], acl ['role' ]), acls )
565
609
610
+ @fiss_cmd
611
+ def config_set_acl (args ):
612
+ """ Assign an ACL role to a list of users for a config. """
613
+ acl_updates = [{"user" : user , "role" : args .role } \
614
+ for user in set (expand_fc_groups (args .users )) \
615
+ if user != fapi .whoami ()]
616
+
617
+ id = args .snapshot_id
618
+ if not id :
619
+ # get the latest snapshot_id for this method from the methods repo
620
+ r = fapi .list_repository_configs (namespace = args .namespace ,
621
+ name = args .config )
622
+ fapi ._check_response_code (r , 200 )
623
+ versions = r .json ()
624
+ if len (versions ) == 0 :
625
+ if fcconfig .verbosity :
626
+ eprint ("Configuration {0}/{1} not found" .format (args .namespace ,
627
+ args .config ))
628
+ return 1
629
+ latest = sorted (versions , key = lambda c : c ['snapshotId' ])[- 1 ]
630
+ id = latest ['snapshotId' ]
631
+
632
+ r = fapi .update_repository_config_acl (args .namespace , args .config , id ,
633
+ acl_updates )
634
+ fapi ._check_response_code (r , 200 )
635
+ if fcconfig .verbosity :
636
+ print ("Updated ACL for {0}/{1}:{2}" .format (args .namespace , args .config ,
637
+ id ))
638
+ return 0
639
+
566
640
@fiss_cmd
567
641
def config_get (args ):
568
642
""" Retrieve a method config from a workspace, send stdout """
@@ -2093,22 +2167,31 @@ def main(argv=None):
2093
2167
# List available methods
2094
2168
subp = subparsers .add_parser ('meth_list' ,
2095
2169
description = 'List available workflows' )
2096
- subp .add_argument ('-n' , '--name' , default = None ,required = False ,
2170
+ subp .add_argument ('-m' , '--method' , default = None ,
2171
+ help = 'name of single workflow to search for (optional)' )
2172
+ subp .add_argument ('-n' , '--namespace' , default = None ,
2097
2173
help = 'name of single workflow to search for (optional)' )
2174
+ subp .add_argument ('-i' , '--snapshot-id' , default = None ,
2175
+ help = "Snapshot ID (version) of method/config" )
2098
2176
subp .set_defaults (func = meth_list )
2099
2177
2100
2178
subp = subparsers .add_parser ('meth_exists' ,
2101
2179
description = 'Determine if named workflow exists in method repository' )
2102
- subp .add_argument ('name ' , help = 'name of method to search for In repository' )
2180
+ subp .add_argument ('method ' , help = 'name of method to search for in repository' )
2103
2181
subp .set_defaults (func = meth_exists )
2104
2182
2105
2183
# Configuration: list
2106
2184
subp = subparsers .add_parser (
2107
2185
'config_list' , description = 'List available configurations' )
2108
- subp .add_argument ('-w' , '--workspace' , help = 'Workspace name' ,
2109
- default = fcconfig .workspace , required = False )
2186
+ subp .add_argument ('-w' , '--workspace' , help = 'Workspace name' )
2110
2187
subp .add_argument ('-p' , '--project' , default = fcconfig .project ,
2111
- help = proj_help , required = proj_required )
2188
+ help = proj_help )
2189
+ subp .add_argument ('-c' , '--config' , default = None ,
2190
+ help = 'name of single workflow to search for (optional)' )
2191
+ subp .add_argument ('-n' , '--namespace' , default = None ,
2192
+ help = 'name of single workflow to search for (optional)' )
2193
+ subp .add_argument ('-i' , '--snapshot-id' , default = None ,
2194
+ help = "Snapshot ID (version) of config (optional)" )
2112
2195
subp .set_defaults (func = config_list )
2113
2196
2114
2197
# Configuration: delete
@@ -2200,16 +2283,12 @@ def main(argv=None):
2200
2283
# pushed into a separate function and/or auto-generated
2201
2284
2202
2285
# Set ACL
2203
- # cacl_parser = subparsers.add_parser('config_set_acl',
2204
- # description='Set roles for config')
2205
- # cacl_parser.add_argument('namespace', help='Method namespace')
2206
- # cacl_parser.add_argument('name', help='Config name')
2207
- # cacl_parser.add_argument('snapshot_id', help='Snapshot ID')
2208
- # cacl_parser.add_argument('role', help='ACL role',
2209
- # choices=['OWNER', 'READER', 'WRITER', 'NO ACCESS'])
2210
- # cacl_parser.add_argument('users', metavar='user', help='Firecloud username',
2211
- # nargs='+')
2212
- # cacl_parser.set_defaults(func=meth_set_acl)
2286
+ subp = subparsers .add_parser ('config_set_acl' , description = 'Assign an ' +
2287
+ 'ACL role to a list of users for a config' ,
2288
+ parents = [conf_parent , acl_parent ])
2289
+ subp .add_argument ('-i' , '--snapshot-id' ,
2290
+ help = "Snapshot ID (version) of method/config" )
2291
+ subp .set_defaults (func = config_set_acl )
2213
2292
2214
2293
# Status
2215
2294
subp = subparsers .add_parser ('health' ,
0 commit comments