Ejemplo n.º 1
0
def main(argsv):
    parser = argparse.ArgumentParser(
        description='Add one or more methods to Broad Methods Repository')
    parser.add_argument('-n',
                        '--namespace',
                        dest='namespace',
                        action='store',
                        required=True,
                        help='Methods namespace')
    parser.add_argument('-p',
                        '--public',
                        dest='public',
                        action='store_true',
                        help='Make methods publicly readable')
    parser.add_argument(dest='wdl', help='Path to WDL file.', nargs='+')
    args = parser.parse_args(argsv)
    namespace = args.namespace
    public = args.public
    for wdl in args.wdl:
        method_name = os.path.basename(wdl)
        suffix = method_name.lower().rfind('.wdl')
        if suffix != -1:
            method_name = method_name[0:suffix]
        method_acl = []
        try:
            existing_method = alto.get_method(namespace, method_name)
            method_acl = fapi.get_repository_method_acl(
                namespace=existing_method['namespace'],
                method=existing_method['name'],
                snapshot_id=existing_method['snapshotId']).json()
        except ValueError:
            pass
        if public:
            existing_public_user = False
            for i in range(len(method_acl)):
                if method_acl[i]['user'] == 'public':
                    existing_public_user = True
                    method_acl[i] = dict(user="******", role="READER")
                    break
            if not existing_public_user:
                method_acl.append(dict(user="******", role="READER"))
        result = fapi.update_repository_method(namespace=namespace,
                                               method=method_name,
                                               wdl=wdl,
                                               synopsis='')
        if result.status_code == 201:
            result = result.json()
            if len(method_acl) > 0:
                fapi.update_repository_method_acl(
                    namespace=result['namespace'],
                    method=result['name'],
                    snapshot_id=result['snapshotId'],
                    acl_updates=method_acl)
            print(
                'import "https://api.firecloud.org/ga4gh/v1/tools/{}:{}/versions/{}/plain-WDL/descriptor"'
                .format(result['namespace'], result['name'],
                        result['snapshotId']))
        else:
            print('Unable to add {}'.format(method_name))
            print(result.json())
def main(argv):
    parser = argparse.ArgumentParser(description='Add one or more methods to Broad Methods Repository.')
    parser.add_argument('-n', '--namespace', dest='namespace', action='store', required=True, help='Methods namespace')
    parser.add_argument('-p', '--public', dest='public', action='store_true', help='Make methods publicly readable')
    parser.add_argument(dest='wdl', help='Path to WDL file.', nargs='+')
    args = parser.parse_args(argv)

    namespace = args.namespace
    public = args.public

    n_success = 0
    for wdl in args.wdl:
        method_name = os.path.basename(wdl)
        suffix = method_name.lower().rfind('.wdl')
        if suffix != -1:
            method_name = method_name[0:suffix]

        method_acl = []
        try:
            existing_method = get_firecloud_workflow(namespace, method_name)
            method_acl = fapi.get_repository_method_acl(namespace=existing_method['namespace'], method=existing_method['name'], snapshot_id=existing_method['snapshotId']).json()
        except ValueError:
            pass

        if public:
            existing_public_user = False
            for i in range(len(method_acl)):
                if method_acl[i]['user'] == 'public':
                    existing_public_user = True
                    method_acl[i] = dict(user='******', role='READER')
                    break
            if not existing_public_user:
                method_acl.append(dict(user='******', role='READER'))

        result = fapi.update_repository_method(namespace=namespace, method=method_name, wdl=wdl, synopsis='')
        if result.status_code == 201:
            result = result.json()
            if len(method_acl) > 0:
                fapi.update_repository_method_acl(namespace=result['namespace'], method=result['name'], snapshot_id=result['snapshotId'], acl_updates=method_acl)
            print(f'Workflow {method_name} is imported! See https://api.firecloud.org/ga4gh/v1/tools/{result["namespace"]}:{result["name"]}/versions/{result["snapshotId"]}/plain-WDL/descriptor')
            n_success += 1
        else:
            print(f'Unable to add workflow {method_name} - {result.json()}')

    print(f'Successfully added {n_success} workflows.')
Ejemplo n.º 3
0
    def set_acl(self, role, users):
        """Set permissions for this method.

        Args:
            role (str): Access level
                one of {one of "OWNER", "READER", "WRITER", "NO ACCESS"}
            users (list(str)): List of users to give role to
        """
        acl_updates = [{"user": user, "role": role} for user in users]
        r = fapi.update_repository_method_acl(
            self.namespace, self.name, self.snapshot_id,
            acl_updates, self.api_url
        )
        fapi._check_response_code(r, 200)
Ejemplo n.º 4
0
z = fapi.update_repository_method(namespace=SEL_NAMESPACE, method=TERRA_METHOD_NAME, synopsis='run sims and compute component stats',
                                  wdl=os.path.abspath(f'./Dockstore.wdl'))
#print('UPDATE IS', z, z.json())
new_method = z.json()
print('NEW_METHOD IS', new_method)

#z = fapi.list_repository_methods(namespace=SEL_NAMESPACE, name=TERRA_METHOD_NAME).json()
#print('METHODS LIST AFT', z)

snapshot_id = new_method['snapshotId']

z = fapi.get_repository_method_acl(namespace=SEL_NAMESPACE, method=TERRA_METHOD_NAME, snapshot_id=snapshot_id)
print('ACL:', z, z.json())

z = fapi.update_repository_method_acl(namespace=SEL_NAMESPACE, method=TERRA_METHOD_NAME, snapshot_id=snapshot_id,
                                      acl_updates=[{'role': 'OWNER', 'user': '******'},
                                                   {'role': 'OWNER', 'user': '******'}])
print('ACL UPDATE:', z, z.json())
z = fapi.get_repository_method_acl(namespace=SEL_NAMESPACE, method=TERRA_METHOD_NAME, snapshot_id=snapshot_id)
print('ACL AFTER UPDATE:', z, z.json())

z = fapi.get_config_template(namespace=SEL_NAMESPACE, method=TERRA_METHOD_NAME, version=snapshot_id)
#print('CONFIG TEMPLATE AFT IS', z, z.json())
config_template = z.json()

#z = fapi.list_workspace_configs(namespace=SEL_NAMESPACE, workspace=SEL_WORKSPACE, allRepos=True).json()
#print('LIST_WORKSPACE_CONFIGS allRepos', z)
TERRA_CONFIG_NAME += f'_cfg_{snapshot_id}' 
# z = fapi.get_workspace_config(workspace=SEL_WORKSPACE, namespace=SEL_NAMESPACE,
#                               config=TERRA_CONFIG_NAME, cnamespace=SEL_NAMESPACE)