Esempio n. 1
0
def readurltoken(repo):
    """return conduit url, token and make sure they exist

    Currently read from [auth] config section. In the future, it might
    make sense to read from .arcconfig and .arcrc as well.
    """
    url = repo.ui.config(b'phabricator', b'url')
    if not url:
        raise error.Abort(_(b'config %s.%s is required')
                          % (b'phabricator', b'url'))

    res = httpconnectionmod.readauthforuri(repo.ui, url, util.url(url).user)
    token = None

    if res:
        group, auth = res

        repo.ui.debug(b"using auth.%s.* for authentication\n" % group)

        token = auth.get(b'phabtoken')

    if not token:
        token = readlegacytoken(repo, url)
        if not token:
            raise error.Abort(_(b'Can\'t find conduit token associated to %s')
                              % (url,))

    return url, token
Esempio n. 2
0
def readurltoken(repo):
    """return conduit url, token and make sure they exist

    Currently read from [auth] config section. In the future, it might
    make sense to read from .arcconfig and .arcrc as well.
    """
    url = repo.ui.config(b'phabricator', b'url')
    if not url:
        raise error.Abort(_(b'config %s.%s is required')
                          % (b'phabricator', b'url'))

    res = httpconnectionmod.readauthforuri(repo.ui, url, util.url(url).user)
    token = None

    if res:
        group, auth = res

        repo.ui.debug(b"using auth.%s.* for authentication\n" % group)

        token = auth.get(b'phabtoken')

    if not token:
        raise error.Abort(_(b'Can\'t find conduit token associated to %s')
                            % (url,))

    return url, token
Esempio n. 3
0
 def read_hgrc_authtoken(ui, authuri):
     from mercurial.httpconnection import readauthforuri
     from inspect import getargspec
     args, _, _, _ = getargspec(readauthforuri)
     res = readauthforuri(self.ui, authuri, "")
     if res:
         group, auth = res
         return auth
     else:
         return None
Esempio n. 4
0
def find_user_password(self, realm, authuri):
    user, passwd = self.passwddb.find_user_password(realm, authuri)
    if user and passwd:
        self._writedebug(user, passwd)
        return (user, passwd)

    prefix = ''
    res = httpconnection.readauthforuri(self.ui, authuri, user)
    if res:
        _, auth = res
        prefix = auth.get('prefix')
        user, passwd = auth.get('username'), auth.get('password')
    if not user or not passwd:
        if not prefix:
            prefix = realm.split(' ')[0].lower()
        params = 'service=%s prefix=%s' % (_service, prefix)
        if user:
            params = '%s user=%s' % (params, user)
        user, passwd = auth_getuserpasswd(self, auth_getkey, params)

    self.add_password(realm, authuri, user, passwd)
    self._writedebug(user, passwd)
    return (user, passwd)
def find_user_password(self, realm, authuri):
    user, passwd = self.passwddb.find_user_password(realm, authuri)
    if user and passwd:
        self._writedebug(user, passwd)
        return (user, passwd)

    prefix = ''
    res = httpconnection.readauthforuri(self.ui, authuri, user)
    if res:
        _, auth = res
        prefix = auth.get('prefix')
        user, passwd = auth.get('username'), auth.get('password')
    if not user or not passwd:
        if not prefix:
            prefix = realm.split(' ')[0].lower()
        params = 'service=%s prefix=%s' % (_service, prefix)
        if user:
            params = '%s user=%s' % (params, user)
        user, passwd = auth_getuserpasswd(self, auth_getkey, params)

    self.add_password(realm, authuri, user, passwd)
    self._writedebug(user, passwd)
    return (user, passwd)
Esempio n. 6
0
def find_user_password(self, realm, authuri):
    user, passwd = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
        self, realm, authuri)
    if user and passwd:
        self._writedebug(user, passwd)
        return (user, passwd)

    prefix = ''
    res = httpconnection.readauthforuri(self.ui, authuri, user)
    if res:
        _, auth = res
        prefix = auth.get('prefix')
        user, passwd = auth.get('username'), auth.get('password')
    if not user or not passwd:
        if not prefix:
            prefix = '*'
        params = 'service=%s prefix=%s' % (_service, prefix)
        if user:
            params = '%s user=%s' % (params, user)
        user, passwd = auth_getuserpasswd(self, auth_getkey, params)

    self.add_password(realm, authuri, user, passwd)
    self._writedebug(user, passwd)
    return (user, passwd)
def find_user_password(self, realm, authuri):
    user, passwd = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
        self, realm, authuri)
    if user and passwd:
        self._writedebug(user, passwd)
        return (user, passwd)

    prefix = ''
    res = httpconnection.readauthforuri(self.ui, authuri, user)
    if res:
        _, auth = res
        prefix = auth.get('prefix')
        user, passwd = auth.get('username'), auth.get('password')
    if not user or not passwd:
        if not prefix:
            prefix = '*'
        params = 'service=%s prefix=%s' % (_service, prefix)
        if user:
            params = '%s user=%s' % (params, user)
        user, passwd = auth_getuserpasswd(self, auth_getkey, params)

    self.add_password(realm, authuri, user, passwd)
    self._writedebug(user, passwd)
    return (user, passwd)
Esempio n. 8
0
def showbuildstatus(context, mapping):
    """:build_status: String. Status of build.
    """
    repo = context.resource(mapping, b'repo')
    ui = repo.ui
    debug = ui.debugflag
    ctx = context.resource(mapping, b'ctx')
    store = jenkinsstore(repo.svfs, repo[b'tip'].rev())
    storecache = store.load(ui)
    if debug:
        if len(storecache) <= 1:
            ui.debug(b'jenkins cache is empty\n')
        else:
            ui.debug(b'jenkins cache: {}\n'.format(storecache))

    url = ui.config(b'jenkins', b'url')
    if not url:
        raise error.Abort('jenkins.url configuration option is not defined')
    res = httpconnectionmod.readauthforuri(repo.ui, url, util.url(url).user)
    if res:
        group, auth = res
        ui.debug(b"using auth.%s.* for authentication\n" % group)
        username = auth.get('username')
        password = auth.get('password')
        if not username or not password:
            raise error.Abort(
                "cannot fine 'username' and/or 'password' values for %s" % url)
    else:
        ui.debug(b"no 'auth' configuration for %s\n" % url)
        username, password = None, None
    username = ui.config(b'jenkins', b'username')
    password = ui.config(b'jenkins', b'password')
    server = Jenkins(url.decode('utf-8'), username=username, password=password)

    if 'jobs' not in storecache:
        jobnames = ui.config(b'jenkins', b'job').decode('utf-8')
        jobs = [n.strip() for n in jobnames.split(',')]
        storecache['jobs'] = {name: {} for name in jobs}
    elif debug:
        ui.debug(b'using cached jobs\n')

    def gen_jobs_buildinfo():
        for job, jobcache in storecache['jobs'].items():
            if not jobcache:
                jobcache.update(buildinfo_for_job(server, job))
            elif debug:
                ui.debug(b'using cached build info for job %s\n' % job)
            build_info = jobcache.get(ctx.hex().decode('utf-8'))
            if not build_info:
                yield '{}: NOT BUILT\n'.format(job)
                continue
            if build_info['building']:
                status = 'BUILDING'
            else:
                status = build_info['status']
            build_url = build_info['url']
            yield '{}: {} - {}\n'.format(job, status, build_url)

    jobs_buildinfo = [v.encode('utf-8') for v in gen_jobs_buildinfo()]
    store.save()

    if not jobs_buildinfo:
        jobs_buildinfo.append(b'NOT BUILT')

    return templatekw.compatlist(context, mapping, b'build_status',
                                 jobs_buildinfo)