def _make_github_repos(
        gh, github_login, github_passwd, github_organization, rinfo, existing,
        access_protocol, dryrun):
    cred = UserPassword('github', 'https://github.com/login')

    # determine the entity under which to create the repos
    entity = _get_github_entity(
        gh,
        cred,
        github_login,
        github_passwd,
        github_organization)

    res = []
    for ds, reponame in rinfo:
        try:
            access_url, existed = _make_github_repo(
                gh,
                entity,
                reponame,
                existing,
                access_protocol,
                dryrun)
            res.append((ds, access_url, existed))
        except gh.BadCredentialsException as e:
            # things blew up, wipe out cred store, if anything is in it
            if cred.is_known:
                cred.delete()
            raise e
    return res
示例#2
0
def _make_github_repos(gh, github_login, github_passwd, github_organization,
                       rinfo, existing, access_protocol, dryrun):
    # make it per user if github_login was provided. People might want to use
    # different credentials etc
    cred_identity = "%s@github" % github_login if github_login else "github"
    cred = UserPassword(cred_identity, 'https://github.com/login')

    # determine the entity under which to create the repos
    entity = _get_github_entity(gh, cred, github_login, github_passwd,
                                github_organization)

    res = []
    for ds, reponame in rinfo:
        try:
            access_url, existed = _make_github_repo(gh, github_login, entity,
                                                    reponame, existing,
                                                    access_protocol, dryrun)
            res.append((ds, access_url, existed))
        except gh.BadCredentialsException as e:
            # things blew up, wipe out cred store, if anything is in it
            if cred.is_known:
                # to avoid surprises "who ate my creds?", warn the user
                lgr.warning(
                    "Authentication failed, deleting stored credential %s",
                    cred_identity)
                cred.delete()
            raise e
    return res
示例#3
0
def _make_github_repos(
        gh, github_user, github_passwd, github_organization, rinfo, existing,
        access_protocol, dryrun):
    cred = UserPassword('github', 'https://github.com/login')

    # determine the entity under which to create the repos
    entity = _get_github_entity(
        gh,
        cred,
        github_user,
        github_passwd,
        github_organization)

    res = []
    for ds, reponame in rinfo:
        try:
            access_url, existed = _make_github_repo(
                gh,
                entity,
                reponame,
                existing,
                access_protocol,
                dryrun)
            res.append((ds, access_url, existed))
        except gh.BadCredentialsException as e:
            # things blew up, wipe out cred store, if anything is in it
            if cred.is_known:
                cred.delete()
            raise e
    return res
示例#4
0
def _make_github_repos(
        gh, github_login, github_passwd, github_organization, rinfo, existing,
        access_protocol, dryrun):
    # make it per user if github_login was provided. People might want to use
    # different credentials etc
    cred_identity = "%s@github" % github_login if github_login else "github"
    cred = UserPassword(cred_identity, 'https://github.com/login')

    # determine the entity under which to create the repos
    entity = _get_github_entity(
        gh,
        cred,
        github_login,
        github_passwd,
        github_organization)

    res = []
    for ds, reponame in rinfo:
        try:
            access_url, existed = _make_github_repo(
                gh,
                github_login,
                entity,
                reponame,
                existing,
                access_protocol,
                dryrun)
            res.append((ds, access_url, existed))
        except gh.BadCredentialsException as e:
            # things blew up, wipe out cred store, if anything is in it
            if cred.is_known:
                # to avoid surprises "who ate my creds?", warn the user
                lgr.warning(
                    "Authentication failed, deleting stored credential %s",
                    cred_identity
                )
                cred.delete()
            raise e
    return res
示例#5
0
def _enable_remote(ds, name, known_remotes, url, pushurl, fetch, description,
                   as_common_datasrc, publish_depends, publish_by_default,
                   annex_wanted, annex_required, annex_group,
                   annex_groupwanted, inherit, get_annex_info, **res_kwargs):
    result_props = dict(action='enable-sibling',
                        path=ds.path,
                        type='sibling',
                        name=name,
                        **res_kwargs)

    if not isinstance(ds.repo, AnnexRepo):
        yield dict(result_props,
                   status='impossible',
                   message='cannot enable sibling of non-annex dataset')
        return

    if name is None:
        yield dict(result_props,
                   status='error',
                   message='require `name` of sibling to enable')
        return

    # get info on special remote
    sp_remotes = {
        v['name']: dict(v, uuid=k)
        for k, v in ds.repo.get_special_remotes().items()
    }
    remote_info = sp_remotes.get(name, None)

    if remote_info is None:
        yield dict(result_props,
                   status='impossible',
                   message=("cannot enable sibling '%s', not known", name))
        return

    env = None
    cred = None
    if remote_info.get('type', None) == 'webdav':
        # a webdav special remote -> we need to supply a username and password
        if not ('WEBDAV_USERNAME' in os.environ
                and 'WEBDAV_PASSWORD' in os.environ):
            # nothing user-supplied
            # let's consult the credential store
            hostname = urlparse(remote_info.get('url', '')).netloc
            if not hostname:
                yield dict(
                    result_props,
                    status='impossible',
                    message=
                    "cannot determine remote host, credential lookup for webdav access is not possible, and not credentials were supplied"
                )
            cred = UserPassword('webdav:{}'.format(hostname))
            if not cred.is_known:
                try:
                    cred.enter_new(
                        instructions=
                        "Enter credentials for authentication with WEBDAV server at {}"
                        .format(hostname),
                        user=os.environ.get('WEBDAV_USERNAME', None),
                        password=os.environ.get('WEBDAV_PASSWORD', None))
                except KeyboardInterrupt:
                    # user hit Ctrl-C
                    yield dict(
                        result_props,
                        status='impossible',
                        message=
                        "credentials are required for sibling access, abort")
                    return
            creds = cred()
            # update the env with the two necessary variable
            # we need to pass a complete env because of #1776
            env = dict(os.environ,
                       WEBDAV_USERNAME=creds['user'],
                       WEBDAV_PASSWORD=creds['password'])

    try:
        ds.repo.enable_remote(name, env=env)
        result_props['status'] = 'ok'
    except AccessDeniedError as e:
        # credentials are wrong, wipe them out
        if cred and cred.is_known:
            cred.delete()
        result_props['status'] = 'error'
        result_props['message'] = e.message
    except AccessFailedError as e:
        # some kind of connection issue
        result_props['status'] = 'error'
        result_props['message'] = e.message
    except Exception as e:
        # something unexpected
        raise e

    yield result_props
示例#6
0
文件: siblings.py 项目: hanke/datalad
def _enable_remote(
        ds, name, known_remotes, url, pushurl, fetch, description,
        as_common_datasrc, publish_depends, publish_by_default,
        annex_wanted, annex_required, annex_group, annex_groupwanted,
        inherit, get_annex_info,
        **res_kwargs):
    result_props = dict(
        action='enable-sibling',
        path=ds.path,
        type='sibling',
        name=name,
        **res_kwargs)

    if not isinstance(ds.repo, AnnexRepo):
        yield dict(
            result_props,
            status='impossible',
            message='cannot enable sibling of non-annex dataset')
        return

    if name is None:
        yield dict(
            result_props,
            status='error',
            message='require `name` of sibling to enable')
        return

    # get info on special remote
    sp_remotes = {v['name']: dict(v, uuid=k) for k, v in ds.repo.get_special_remotes().items()}
    remote_info = sp_remotes.get(name, None)

    if remote_info is None:
        yield dict(
            result_props,
            status='impossible',
            message=("cannot enable sibling '%s', not known", name))
        return

    env = None
    cred = None
    if remote_info.get('type', None) == 'webdav':
        # a webdav special remote -> we need to supply a username and password
        if not ('WEBDAV_USERNAME' in os.environ and 'WEBDAV_PASSWORD' in os.environ):
            # nothing user-supplied
            # let's consult the credential store
            hostname = urlparse(remote_info.get('url', '')).netloc
            if not hostname:
                yield dict(
                    result_props,
                    status='impossible',
                    message="cannot determine remote host, credential lookup for webdav access is not possible, and not credentials were supplied")
            cred = UserPassword('webdav:{}'.format(hostname))
            if not cred.is_known:
                try:
                    cred.enter_new(
                        instructions="Enter credentials for authentication with WEBDAV server at {}".format(hostname),
                        user=os.environ.get('WEBDAV_USERNAME', None),
                        password=os.environ.get('WEBDAV_PASSWORD', None))
                except KeyboardInterrupt:
                    # user hit Ctrl-C
                    yield dict(
                        result_props,
                        status='impossible',
                        message="credentials are required for sibling access, abort")
                    return
            creds = cred()
            # update the env with the two necessary variable
            # we need to pass a complete env because of #1776
            env = dict(
                os.environ,
                WEBDAV_USERNAME=creds['user'],
                WEBDAV_PASSWORD=creds['password'])

    try:
        ds.repo.enable_remote(name, env=env)
        result_props['status'] = 'ok'
    except AccessDeniedError as e:
        # credentials are wrong, wipe them out
        if cred and cred.is_known:
            cred.delete()
        result_props['status'] = 'error'
        result_props['message'] = str(e)
    except AccessFailedError as e:
        # some kind of connection issue
        result_props['status'] = 'error'
        result_props['message'] = str(e)
    except Exception as e:
        # something unexpected
        raise e

    yield result_props